0% found this document useful (0 votes)
20 views5 pages

Control LEDs via Bluetooth with Arduino

This document describes how to control LEDs via Bluetooth using an Arduino UNO board. The circuit connects an HC-06 Bluetooth module to the Arduino along with 4 LEDs and resistors. An Android app is used to send character commands (A, B, C, D) over Bluetooth to toggle the individual LEDs connected to pins 4-7 on the Arduino. The Arduino code defines the pin assignments and includes an loop to receive character data from Bluetooth and toggle the corresponding LED based on the character received.

Uploaded by

satyam jadhav
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views5 pages

Control LEDs via Bluetooth with Arduino

This document describes how to control LEDs via Bluetooth using an Arduino UNO board. The circuit connects an HC-06 Bluetooth module to the Arduino along with 4 LEDs and resistors. An Android app is used to send character commands (A, B, C, D) over Bluetooth to toggle the individual LEDs connected to pins 4-7 on the Arduino. The Arduino code defines the pin assignments and includes an loop to receive character data from Bluetooth and toggle the corresponding LED based on the character received.

Uploaded by

satyam jadhav
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

AIM: To Control LEDs via Bluetooth using Arduino UNO.

Apparatus:
1. Arduino UNO & programming cable
2. HC-06 Bluetooth module
3. 4 x LEDs
4. 4 x 220 ohms resistors
5. Breadboard
6. Connecting wires

Pinouts:

1. HC-06 Bluetooth Module


The HC-06 bluetooth module is a slave bluetooth module designed
for wireless serial communication. It is a slave module meaning that it can
receive serial data when serial data is sent out from a master bluetooth
device(device able to send serial data through the air: smart phones, PC).

2. Arduino UNO
Arduino Uno is a microcontroller board based on the ATmega328P. It
has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6
analog inputs, a 16 MHz ceramic resonator, a USB connection, a power jack,
an ICSP header and a reset button. It contains everything needed to support
the microcontroller; simply connect it to a computer with a USB cable or
power it with a AC-to-DC adapter or battery to get started.
Circuit:

Procedure:
a) Connect the circuit as shown.
We use the 5V power supply from Arduino
Connect the HC-06 to Arduino accordingly:

HC-06 ---> Arduino UNO


VCC ---> +5V
GND ---> GND
Tx ---> Rx (pin 0)
Rx ---> Tx (pin 1)

Connect the 1st LED anode to 220 ohm resistor and 220 ohm resistor to pin 4 of Arduino
UNO. LED cathode should be connected to ground.
Similarly, connect 2nd LED to pin 5 of Arduino UNO, 3rd LED to pin 6 and 4th LED to pin 7
of Arduino UNO.

b) Program the Arduino.


Functions used in the program
1. [Link](9600): Start serial communication with baud rate at 9600bps.
2. [Link](“Hello”): Displays a message Hello or anything typed between ”” over serial.
3. [Link](): Read the incoming data through serial.
4. digitalRead(pin_number): read the digital value of a pin, from digital I/Os on Arduino.
5. digitalWrite(pin_number, value): write the digital value (HIGH/LOW) to a pin, from digital
I/Os on Arduino

Program:
Upload the following program to Arduino

//Naming Arduino pins 4, 5, 6 & 7 to their respective LEDs


#define LED1 4
#define LED2 5
#define LED3 6
#define LED4 7

//Character variable to store the command received from Bluetooth


char cmdIn;

void setup()
{
[Link](9600); //Start communication with Bluetooth module

//Set LED pins as output


pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);

//Just a text to confirm that Bluetooth communication has established


[Link]("Hello");
//You should see this text 'Hello' on the mobile app
}

void loop()
{
//If the incoming data is available from Bluetooth,
//then store the data in the variable
if ([Link]()>0)
{
cmdIn = [Link]();
}

/*
*These if statements check that the received data is 'A', 'B', 'C' or 'D'.
*when any of the command is received, the respective if statement gets executed.
*Here, we toggle the respective LED. To do this, we first check if the LED
*is ON or OFF and perform the opposite action, and display the status of LED.
*Example: if LED is ON then turn the LED OFF.
*/

if (cmdIn == 'A') //'A' is received


{
if (digitalRead(LED1) == LOW) //check if LED is OFF
{
digitalWrite(LED1, HIGH); //Turn LED ON
[Link]("LED1 is ON"); //Display that LED is ON
}
else if (digitalRead(LED1) == HIGH) //Check if LED is ON
{
digitalWrite(LED1, LOW); //Turn LED OFF
[Link]("LED1 is OFF"); //Display that LED is OFF
}
}

if (cmdIn == 'B')
{
if (digitalRead(LED2) == LOW)
{
digitalWrite(LED2, HIGH);
[Link]("LED2 is ON");
}
else if (digitalRead(LED2) == HIGH)
{
digitalWrite(LED2, LOW);
[Link]("LED2 is OFF");
}
}

/*As you can see the code in below if statements is different than the above ones.
*Here, the same process is done as above, but in a different way
*digitalWrite(LED3, !digitalRead(LED3)) to understand this function, here is the format
*digitalWrite(_output_pin_, NOT of _output_pin_)
*The exclamation mark '!' refers to NOT function.
*Hence the function digitalWrite(LED3, !digitalRead(LED3)) means
*turn LED3 ON or OFF, based on the compliment of previous state of that LED3
*To display the message about status of LED, we join one string "LED3 is "
*with the string value of current state of LED3 i.e. (String(digitalRead(LED3))
*
*/

if (cmdIn == 'C')
{
digitalWrite(LED3, !digitalRead(LED3));
[Link]("LED3 is " + (String(digitalRead(LED3))));
}

if (cmdIn == 'D')
{
digitalWrite(LED4, !digitalRead(LED4));
[Link]("LED4 is " + (String(digitalRead(LED4))));
}

delay(1000); //wait for 1 second


}

Mobile App:
Download and install the following mobile application from Google play store or scan the
QR code below

Bluetooth Terminal HC-05 by mightyIT

When the app is installed, turn on the circuit and do the following
When the circuit is on, the LED on the Bluetooth module starts to blink.
1. Go to Bluetooth settings on your phone.
2. Scan for new devices.
3. Find HC-05 or HC-06 under available devices.
4. Enter pairing key as 1234 or 0000
5. Wait till your phone adds the device under paired devices.
6. Once this is done, open the installed app.
7. Look for HC-05 or HC-06 under paired devices.
8. Wait for the device to get connected.
9. Once connected, the LED on the Bluetooth Module is stable & ON.

 When the application is connected to Bluetooth module, Then press the reset button
on the Arduino board. You will receive a ‘‘Hello’’ message displayed on the black
terminal.
 Then type the commands A, B, C or D in the textbox which says ‘Enter ASCII
Command’ and click on ‘Send ASCII’ button just besides the textbox.
 You will see the respective LED connected to Arduino turning ON and a text will be
displayed on the app.
 Now type and send the same command you sent earlier, now you will see the LED
turn OFF and a text displayed
 Remember, command ‘A’ controls LED1, ‘B’ controls LED2, ‘C’ controls LED3 & ‘D’
controls LED4.
 Try sending other commands, also try sending multiple commands like ABC, BD,
ABCD, AC, etc.

Common questions

Powered by AI

The system integrates hardware components, such as the Arduino UNO, HC-06 Bluetooth module, LEDs, resistors, and a breadboard, with software programming in the Arduino IDE. Hardware configurations facilitate communication and power distribution, while software code defines logic for processing Bluetooth commands and toggling LEDs. This combination leverages Bluetooth communication to manage wireless input and software functions to control hardware states, achieving responsive and precise LED control efficiently .

To pair the HC-06 Bluetooth module with a smartphone, the user first needs to turn on the circuit, causing the module's LED to blink. Next, they should scan for new Bluetooth devices on their phone, select HC-06 from the list, and enter the pairing key (1234 or 0000). Once paired, the user opens the Bluetooth Terminal HC-05 app, selects HC-06 under paired devices, and waits for connection confirmation indicated by a stable, on LED on the module. Commands ('A', 'B', 'C', 'D') can then be entered in the app to control the respective LEDs .

If the Bluetooth module fails to connect, the user should ensure the module is powered and the LED is blinking, indicating readiness. Check Bluetooth settings on the smartphone for visibility and correct HC-06 selection. Verify the correct pairing key is entered. If issues persist, reset the Arduino and Bluetooth module or restart the smartphone. Also, ensure software alignment, such as correct baud rates and compiled code on the Arduino, is correct .

The Arduino UNO interacts with the HC-06 Bluetooth module by utilizing its serial communication capabilities. The HC-06 module receives serial data wirelessly from a master Bluetooth device, such as a smartphone or PC. It is connected to the Arduino's Tx and Rx pins, allowing it to communicate the received commands to the Arduino. The Arduino is programmed to interpret these commands ('A', 'B', 'C', 'D') and toggle the corresponding LEDs on or off based on these inputs .

Using #define in Arduino setup allows for clear and efficient code by assigning meaningful names to pin numbers, which improves readability and reduces errors. Defining LEDs with #define makes the code easier to debug and modify, since changes to pin assignments need to be made only once in the definition rather than throughout the code .

The 'Serial.begin(9600)' function initializes serial communication between the Arduino and the HC-06 Bluetooth module at a baud rate of 9600 bps. This setup allows the Arduino to exchange data reliably with the Bluetooth module, receiving wireless commands and sending status messages back to the user through a connected device .

The 'Serial.println' function outputs data to the serial monitor or paired device, providing textual feedback to the user. In the Arduino code, it is used to display messages such as "Hello" to confirm Bluetooth connection and to report LED statuses (e.g., "LED1 is ON"). This feedback mechanism keeps users informed of successful communication and the current states of the LEDs, thus enhancing interaction and troubleshooting capabilities .

The '!' (NOT) operator is used to toggle the state of LED3 and LED4 efficiently. The logic behind this is to invert the current state of the LED. Instead of checking whether the LED is on or off and then applying the opposite state, the NOT operator simplifies this by directly setting the digital output to the opposite of its current state. The code `digitalWrite(LED3, !digitalRead(LED3))` checks the current state of LED3 using `digitalRead()` and writes the opposite state using `digitalWrite()`, thus efficiently handling the toggling operation .

The 220-ohm resistors are significant in the setup as they limit the current passing through the LEDs, preventing them from drawing more current than they can handle, which could potentially damage the LEDs. They ensure that the LEDs operate within their safe current range when powered by the Arduino's 5V supply .

The mobile application enhances the system's functionality by providing a user-friendly interface for wireless control. It allows for easy command entry to toggle LEDs on or off through ASCII commands. The app also displays real-time feedback on the command effects, confirming the status of each LED. This setup simplifies user interaction and extends control capabilities remotely without requiring a manual switch interface .

You might also like