For this week's assignment, the idea is to build a simple smart circuit that contains at least TWO action components that you can control wirelessly. I was inspired by the smart houses, so i decided to make a device that could be able to open and close the house door using mobile phone and also turn On and Off a lamp using mobile phone.
We used Tinker CAD which is a free web app for electronics, coding and 3D design. On Tinker CAD we can create simulations of circuits in which we there is a dashboard that contains all the components needed to create any circuit, we can just drag and drop the component that we want to use, so we can design and test our ideas virtually, which helps us to experiment the circuit before physically doing it. https://www.tinkercad.com/
The Arduino Integrated Development Environment - or Arduino Software (IDE) - contains a text editor for writing code, a message area, a text console, a toolbar with buttons for common functions and a series of menus. It connects to the Arduino hardware to upload programs and communicate with them
ArduinoBlue is an easy to use iOS/Android application that allows the smart phone to communicate and control Arduino with Bluetooth module HC-05 and receives the command from the user.
Arduino UNO is a low-cost, flexible, and easy-to-use programmable open-source microcontroller board that can be integrated into a variety of electronic projects. It consists of various pins, which makes it more compatible and can be used to connect different electronic components.
A breadboard is a plastic board with tiny holes. These holes make it easily to insert electronic components to prototype, create electric circuits.
The USB port serves two purposes: First, it is the cable connection to a computer which allows you to program the board. The USB cord will also provide power for the Arduino if you're not using the power port
Servo motors are great devices that can turn to a specified position. Usually, they have a servo arm that can turn 180 degrees.
5Volts adaptor used as a power supply that adapts electricity of house wall voltage ( 220 volts AC) to low-voltage DC suitable for powering electronics
The terminals are labeled positive and negative, where the positive terminal connected to the center pin of the adaptor.
Relays are used to protect the electrical system from too high of a voltage or current, allowing the safe operation of any equipment it connects to.
Halogen 12V lamp used to emit Light. It converts electrical energy directly into light
The HC-05 Bluetooth module designed for transparent wireless serial communication. Once it is paired to a master Bluetooth device such as PC, smart phones and tablet, its operation becomes transparent to the user.
A resistor is a two-terminal electrical component that provides electrical resistance, used to lower the flow of current, divide voltages
Jumper wires are used to connect components together and it has different types like Male-Male, Male-Female, and Female-Female.
The LCD (Liquid Crystal Display) is a type of display that uses the liquid crystals for its operation.
Connect VCC (5V) pin and GND pin of Arduino to the breadboard.
Connect the VCC and GND pins of the Bluetooth Module to the power and GND of Arduino in the breadboard.
Connect the TXD pin of the Bluetooth module to the RX 0 pin in Arduino, and the RXD pin to a resistance connected to the TX 1 pin connected to a resistance to the GND of the breadboard.
Connect the GND and VCC pins on Servo motor to the power and GND of Arduino in the breadboard, and the 3rd terminal to pin(11) in Arduino board.
Finally connecting the LCD I2C Module: VCC and GND pins to the power and GND of Arduino in the breadboard, the SCL to (A5) and SDA to (A4) in Arduino board.
Pseudocode
There are 3-options happens when the doorbell ring:
Open the door for the guest to enter.
Close the door again.
You are busy now and you don't want to open the door.
So i decided to make these 3-conditions if i give Arduino data(1) to open the door and write "Welcome" on the LCD, if the given data is (0) close the door and write "Closing the door" on the LCD, and if the given data is (2) the servo motor will not make any action but the LCD will display " Sorry, I'm busy"
Steps on writing the code:
Add the library of Liquid crystal i2c and the library of servo motor.
Make a character with name of incomingData and give it initial value '0'
Set the LCD to be Off at the beginning and the servo motor at o degrees.
In Void loop start with while serial. available ==0 in order to stop in this line while no numbers are send in the serial port.
Set the incomingData to be equal to the serial read to store them.
If the incoming Data =='0' set servo motor to 0 degrees, light up the LCD and write "closing the door" then darken the LCD, else if incomingData =='1' set servo motor to 100 degrees, light up the LCD and write "Welcome" then darken the LCD, else if incomingData ==2 light up the LCD and write "Sorry, I'm busy" then darken the LCD.
#include <LiquidCrystal_I2C.h>
#include <Servo.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
Servo lock;
char incomingData = '0';
void setup() {
Serial.begin(9600);
lcd.init();
lcd.noBacklight();
lock.attach(11);
lock.write(0);
}
void loop() {
while (Serial.available() == 0)
;
incomingData = Serial.read();
Serial.print(incomingData);
if (incomingData == '0') {
lock.write(0);
lcd.backlight();
Serial.println("Closing Door");
lcd.setCursor(2, 1);
lcd.print("Closing Door");
delay(1500);
lcd.clear();
lcd.noBacklight();
} else if (incomingData == '1') {
lock.write(100);
Serial.println("Welcome");
lcd.backlight();
lcd.setCursor(4, 1);
lcd.print("Welcome");
delay(1500);
lcd.clear();
lcd.noBacklight();
lock.write(100);
} else if (incomingData == '2') {
lcd.backlight();
lcd.setCursor(1, 1);
lcd.print("Sorry, Im busy");
delay(1500);
lcd.clear();
lcd.noBacklight();
}
}
Download Arduino Blue Control App on mobile phone.
Pair the Hc-05 Bluetooth Module to he mobile phone.
Open Arduino Blue Control App, and connect the Bluetooth module to the mobile.
Now we can control the circuit using the mobile phone, by sending the same incomingData as written in the code.
#include <LiquidCrystal_I2C.h>
#include <Servo.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
Servo lock;
#define relay 8
char incomingData = '0';
void setup() {
Serial.begin(9600);
lcd.init();
lcd.noBacklight();
lock.attach(11);
lock.write(0);
pinMode(relay, OUTPUT);
digitalWrite(relay, LOW);
}
void loop() {
while (Serial.available() == 0)
;
incomingData = Serial.read();
Serial.print(incomingData);
if (incomingData == '0') {
lock.write(0);
lcd.backlight();
Serial.println("Closing Door");
lcd.setCursor(2, 1);
lcd.print("Closing Door");
delay(1500);
lcd.clear();
lcd.noBacklight();
} else if (incomingData == '1') {
lock.write(100);
Serial.println("Welcome");
lcd.backlight();
lcd.setCursor(4, 1);
lcd.print("Welcome");
delay(1500);
lcd.clear();
lcd.noBacklight();
lock.write(100);
} else if (incomingData == '2') {
lcd.backlight();
lcd.setCursor(1, 1);
Serial.println("Sorry, Im busy");
lcd.print("Sorry, Im busy");
delay(1500);
lcd.clear();
lcd.noBacklight();
} else if (incomingData == '3') {
digitalWrite(relay, HIGH);
Serial.println("Turn on Lamp");
} else if (incomingData == '4') {
digitalWrite(relay, LOW);
Serial.println("Turn off Lamp");
}
}
1) I struggled with building the circuit virtually on TinkerCad as I didn't fine the Bluetooth module, also the relay in TinkerCad is totally different from the real relay used in the physical circuit.
2) I asked for instructor help on Slack and they helped me to download Fritzing app and i found the Bluetooth Module there, but the problem was that LCD I2C Module is not exist there and also the relay looks different so i struggled again how to build it virtually.
Using Halogen Lamp and relay may be implemented in my final project the Montessori busy box.
Making a circuit with 3-servo motors and 3-voltage regulator, assembling them into a robotic arm and controlling them using the mobile phone was really an amazing outcome.