0
0
Arduinoprogramming~30 mins

Bluetooth with HC-05/HC-06 module in Arduino - Mini Project: Build & Apply

Choose your learning style9 modes available
Bluetooth with HC-05/HC-06 module
📖 Scenario: You want to control an LED on your Arduino board using a Bluetooth module like HC-05 or HC-06. This project will help you set up the Bluetooth communication and turn the LED on or off by sending simple commands from your phone or computer.
🎯 Goal: Build a simple Arduino program that reads data from the HC-05/HC-06 Bluetooth module and turns an LED on or off based on the received command.
📋 What You'll Learn
Create a variable for the LED pin number
Create a variable for the Bluetooth serial communication
Write code to read data from the Bluetooth module
Control the LED based on the received data
Print the LED status to the serial monitor
💡 Why This Matters
🌍 Real World
Bluetooth modules like HC-05 and HC-06 are commonly used to add wireless control to devices such as home automation systems, robots, and wearable gadgets.
💼 Career
Understanding Bluetooth communication and Arduino programming is useful for embedded systems developers, IoT engineers, and hobbyists working on wireless device projects.
Progress0 / 4 steps
1
Set up the LED pin
Create an integer variable called ledPin and set it to 13. Then, in the setup() function, set the ledPin as an output using pinMode.
Arduino
Need a hint?

Use pinMode(ledPin, OUTPUT); inside setup() to prepare the LED pin.

2
Initialize Bluetooth serial communication
Create a SoftwareSerial object called bluetooth using pins 10 for RX and 11 for TX. In the setup() function, start the bluetooth serial communication at 9600 baud rate. Also, start the default serial communication at 9600 baud rate.
Arduino
Need a hint?

Use bluetooth.begin(9600); and Serial.begin(9600); inside setup().

3
Read Bluetooth data and control LED
In the loop() function, check if bluetooth.available() is greater than zero. If yes, read the incoming byte using bluetooth.read() and store it in a variable called incomingByte. If incomingByte is the character '1', turn the LED on using digitalWrite(ledPin, HIGH). If incomingByte is the character '0', turn the LED off using digitalWrite(ledPin, LOW). Also, print "LED ON" or "LED OFF" to the serial monitor accordingly.
Arduino
Need a hint?

Use bluetooth.read() to get the data and digitalWrite to control the LED.

4
Test and display LED status
Print the message "Waiting for Bluetooth command..." once in the setup() function to the serial monitor. This will help you know the program is ready.
Arduino
Need a hint?

Use Serial.println("Waiting for Bluetooth command..."); inside setup().