My idea of this week's assignment is a remote control of a smart home. You can easily control the lights and the ventilation of your home via an app on your mobile phone.
I connect the Bluetooth moduel with the arduino and download Arduino Bluetooth Control on my phone to send serial data to the Arduino Bluetooth module when a button is pressed on the app.
If I press 1 the buzzer will work ,If I press 2 the red color will turn on from the RGB led ,If I press 3 the green color will turn on from the RGB led ,If I press 4 the blue color will turn on from the RGB led ,
Electric components which I used to build my circuit
HC-5 Bluetooth module
to receives the data and sends it to the Arduino through the TX pin of the Bluetooth module
RGB led
Resistor
to limit current flow for the GBR LED
Arduino uno
Wires
to connect components together
Breadboard
to connect all the jumper wires and other components
Crocodile wires to join the component with Arduino/breadboard.
Buzzer for genarating sound
Softwares
Arduino IDE for flashing the code onto the Arduino board.
Arduino Bluetooth Control
to send serial data to the Arduino Bluetooth module when a button is pressed on the app
I used the tinkercad as a simulation program that used for simulating the electric circuits.
The Main components of my circuit one Input which is HC-5 Bluetooth Module ,and two output which are (RGB led and buzzer)
HC-5 Bluetooth Module (Input )
RGB LED (output)
Three 220 ohm resistor
Arduino Uno R3
Breadboard
Buzzer (output)
Procedures:
Connect the RGBLED Cathode with the 220 ohm Resistor on the same row of the Breadboard and the anode Red with pin 3,anode Blue with pin 4 and anode White with pin 5.
Connect the HC-5 Bluetooth Module with the Arduino as following:
TX with RX of Arduino
RX with TX of Arduino
GND with GND
VCC with 5V
Connect one of the Buzzer's wire's to the GND of the Arduino and the other with Pin 13.
Use Arduino IDE to program the Bluetooth module. I identified char variables for the incoming data. In the void setup, identify the Pins of the LED and the Buzzer as outputs. In the void loop, add While loop for reading the incoming data. Then, if condition to control the LED and the Buzzer.
char incomingdata = 0;
void setup() {
Serial.begin(9600);\\star print the serial
pinMode(13, OUTPUT);\\for the buzzer output
pinMode(3, OUTPUT);\\pin(3 for red the RGB led output
pinMode(4, OUTPUT);\\pin(4 for blue the RGB led output
pinMode(5, OUTPUT); \\pin(5 for green the RGB led output
}
void loop() {
while (Serial.available() >= 0)
{
incomingdata = Serial.read();
if (incomingdata == '1')\\if we press 1 the buzzer will work and the RGB led will turn off
{
digitalWrite(13, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
} else if (incomingdata == '2') \\if we press 2 the buzzer will turn off and the RGB led red will turn on
{
digitalWrite(13, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
} else if (incomingdata == '3') \\if we press 3 the buzzer will not work and the RGB led green will turn on
{
digitalWrite(13, LOW);
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
} else if (incomingdata == '4')\\if we press 4 the buzzer will turn off and the RGB led blue will turn on
{ {
digitalWrite(13, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
}
}
}
First I defind the RGB led and the buzzer as follow:
The Red with pin 3,anode Blue with pin 4 and anode White with pin 5.
The buzzer will be the output with pin 13
Serial.begin(9600);\\star print the serial
pinMode(13, OUTPUT);\\for the buzzer output
pinMode(3, OUTPUT);\\pin(3 for red the RGB led output
pinMode(4, OUTPUT);\\pin(4 for blue the RGB led output
pinMode(5, OUTPUT); \\pin(5 for green the RGB led output
In the void loop ,if I press 1 from Arduino Bluetooth Control app on my mobil phone the buzzer will work and the RGB led will turn off, if we press 2 the buzzer will turn off and the RGB led red will turn on,\if we press 3 the buzzer will not work and the RGB led green will turn on,if we press 4 the buzzer will turn off and the RGB led blue will turn on.
if (incomingdata == '1')\\if we press 1 the buzzer will work and the RGB led will turn off
{
digitalWrite(13, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
} else if (incomingdata == '2') \\if we press 2 the buzzer will turn off and the RGB led red will turn on
{
digitalWrite(13, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
} else if (incomingdata == '3') \\if we press 3 the buzzer will not work and the RGB led green will turn on
{
digitalWrite(13, LOW);
digitalWrite(3, LOW);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
} else if (incomingdata == '4')\\if we press 4 the buzzer will turn off and the RGB led blue will turn on
{ {
digitalWrite(13, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
Upload the code to the Arduino , but first disconnect the TR & RX of the Bluetooth Module. Connect them again after uploading the code.
Open the Arduino Bluetooth Controller on your phone and connect it with the Bluetooth module.
Configure the buttons (Button A = 1 - Button B = 2).
Click on Button A to turn on the LED & Buzzer
Click on Button B to turn off the LED & Buzzer
The main problem that I faced that each time i try to upload the code to Arduino it fails, after I watched a lot of videos on YouTube and googled about this issue, I found that I have to unplug TR & RX of the Bluetooth Module and reconnect them again after uploading the code.
Maybe I will use the bluetooth module in my finall project
Never to get connect to a Bluetooth Module while your peer are connecting their Bluetooth Module next to you as all of the Bluetooth Modules appeared with the same names on the phones