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

Arduino Bluetooth LED Control Guide

1) The document describes a circuit built with an Arduino UNO, HC-06 Bluetooth module, 4 LEDs, and resistors to control the LEDs via Bluetooth. 2) An Android app called "Bluetooth Terminal HC-05" is used to send character commands ('A','B','C','D') from a phone to the Arduino via Bluetooth which toggles the corresponding LED. 3) An Arduino program uses if-statements to check for each character command and toggle the respective LED from on to off by using digitalWrite to change its output pin state. Status messages are sent back over Bluetooth serial.

Uploaded by

Rohit Gholap
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)
480 views5 pages

Arduino Bluetooth LED Control Guide

1) The document describes a circuit built with an Arduino UNO, HC-06 Bluetooth module, 4 LEDs, and resistors to control the LEDs via Bluetooth. 2) An Android app called "Bluetooth Terminal HC-05" is used to send character commands ('A','B','C','D') from a phone to the Arduino via Bluetooth which toggles the corresponding LED. 3) An Arduino program uses if-statements to check for each character command and toggle the respective LED from on to off by using digitalWrite to change its output pin state. Status messages are sent back over Bluetooth serial.

Uploaded by

Rohit Gholap
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

To improve the responsiveness or functionality of the LED control system, one could consider reducing the delay times to increase the responsiveness between commands. Implementing more robust error-checking within the Bluetooth communication process could prevent erroneous command execution. Additionally, enhancing the user interface of the controlling app to support custom commands or a GUI with buttons for LED control would improve user interaction. Another potential modification could involve using interrupts in Arduino programming to handle command inputs, ensuring the system can respond immediately to commands without being influenced by ongoing processes or delays .

When the user inputs command 'A' into the Bluetooth Terminal app, it is transmitted via Bluetooth to the HC-06 module, which forwards the command to the Arduino. The Arduino, upon receiving 'A', checks the state of LED1 (digital pin 4). If the LED is currently off (LOW), it turns it on (HIGH) and sends a message indicating "LED1 is ON". If the LED is on (HIGH), it turns it off (LOW) and sends "LED1 is OFF" over the serial link. Thus, command 'A' toggles the state of LED1 between ON and OFF while providing feedback about its current state .

The digitalWrite function is used within the Arduino programming to modify the state of an LED from HIGH to LOW or LOW to HIGH in response to Bluetooth commands. When a command like 'A' or 'B' is received, the program checks the current state of the corresponding LED using digitalRead. If the LED is off (LOW), digitalWrite turns it on (HIGH) and vice versa. In cases like LEDs 3 and 4, digitalWrite uses a more concise logic with digitalWrite(pin, !digitalRead(pin)), which toggles the LED state by setting it to the opposite of its current state. This logic effectively uses the NOT operator to invert the LED's state .

The Serial.println function in the Arduino sketch plays a critical role in providing real-time feedback during Bluetooth communication. It outputs messages to the serial monitor (or paired device), allowing for interaction with the user. For instance, when a command is received that toggles an LED, Serial.println indicates the command status by providing feedback such as "LED1 is ON" or "LED1 is OFF". This function ensures the user is informed about the current status and actions performed by the Arduino, facilitating clearer interaction between the user and the hardware .

The delay function in the Arduino program introduces a pause or wait time in the execution of the sketch. In the context of the LED control project, a delay of 1000 milliseconds (or 1 second) is used at the end of the loop. This pause allows for the stabilization of the emitted command and visual feedback to be perceived clearly by the user. It temporarily halts further processing, ensuring that the toggled LED state remains visible long enough for human perception before the program continues to check for new input .

Serial.begin(9600) in the Arduino setup is used to initialize serial communication at a baud rate of 9600 bits per second. This establishes the communication speed between the Arduino and the Bluetooth module, enabling the transmission and reception of serial data. This configuration is essential for the Arduino to send and receive commands through the HC-06 Bluetooth module, facilitating control of the LEDs based on input commands .

The HC-06 Bluetooth module is a slave module designed for wireless serial communication, meaning it can only receive serial data sent from a master device, such as a smartphone or PC. In the LED control project, the HC-06 is connected to the Arduino UNO, receiving commands via Bluetooth to control the LEDs. The module connects its VCC to 5V and GND to ground on the Arduino UNO; the TX and RX pins are connected to RX (pin 0) and TX (pin 1) of the Arduino UNO, respectively .

To pair a smartphone with the HC-06 Bluetooth module, first, ensure the module is powered and its LED is blinking, indicating readiness to pair. On the smartphone, go to Bluetooth settings and scan for new devices. Locate the HC-05 or HC-06 in the list of available devices. Use the default pairing key, typically '1234' or '0000', and pair the module with the smartphone. Once paired, the device will appear under paired devices. Open the Bluetooth Terminal HC-05 app, connect to the HC-06 module from the list of paired devices, and ensure the LED on the HC-06 is stable to confirm a successful connection .

The Arduino UNO microcontroller board is crucial in the LED control project as it serves as the central unit for processing commands and controlling outputs. It receives data from the HC-06 Bluetooth module and interprets this data according to the programmed logic. By controlling the digital pins to which the LEDs are connected, the Arduino UNO can toggle the LEDs on or off based on input from the paired Bluetooth device. Its programmable nature enables users to define how it should respond to various commands, and its multiple I/O capabilities support the management of multiple LEDs .

In the Arduino program, defining LED pins simplifies managing each LED by associating them with specific digital pins on the Arduino. This implementation is done by using the #define directive to assign pin numbers to human-readable names, such as LED1, LED2, LED3, and LED4 being assigned to pins 4, 5, 6, and 7 respectively. This allows programmers to reference LEDs with meaningful names rather than pin numbers, improving readability and maintainability in the code .

You might also like