Wednesday 4 September 2019

How to control LED via Bluetooth and Arduino

I will cover how to set up Arduino, upload the code, test in serial mode, then test using Android app.

Things required:

1. Arduino Uno board
2. Jumper wires
3. HC-05
4. LED

1. Make the following connections:

Arduino                              HC-05
TX              ====>             TX
RX              ====>             RX
5V              ====>             VCC
GND           ====>             GND

LED short wire ====>       GND of Arduino
LED long wire ====>         pin 8 of Arduino

2. Temporarily remove the TX and RX from the HC-05.

3. Upload the following code:

void setup() {
 pinMode(8, OUTPUT); // put your setup code here, to run once:

void loop() {
  // put your main code here, to run repeatedly:
      char data=; // reading the data received from the bluetooth module
        case 'a': digitalWrite(8, HIGH);break; // when a is pressed on the app on your smart phone
        case 'b': digitalWrite(8, LOW);break; // when b is pressed on the app on your smart phone
        default : break;

4. Replace the TX and RX cables as above.

5. Open serial monitor in Arduino program.

6. Change Baud rate to 9600 and select 'no line ending'.

7. Enter a to turn LED on, enter b to turn LED off.

Using via Bluetooth app. I use Bluetooth Terminal

8. Swap the TX and RX cables around on the Arduino.

9. Pair up using Bluetooth app.

10. Enter a in app to turn LED on, enter b in app to turn LED off.

There is a video showing this in action here:

No comments:

Post a Comment