Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Voltaat Arduino Ultimate Kit
50 min
Share

Control the Arduino LED using Bluetooth

Bluetooth is a wireless technology that allows two devices to communicate with each other. It can be used to connect a variety of devices, including phones, computers, and headphones.

Project Video

Overview

In this tutorial we will use the HC-05 Bluetooth module to send data to the Arduino via your smartphone. This data will be used to control the Arduino’s built-in LED on and off.

Getting the Items

Arduino Uno R3 (Voltaat Version)
Get Item
HC-05 Bluetooth Module
Get Item
Jumper Wires - Male to Male (40 Pack)
Get Item

Steps

Wiring it Up

Connect the wires between the Bluetooth module and the Arduino, as shown in the image below.

Connections from the Bluetooth to the Arduino:

    • Bluetooth VCC pin → Arduino 5V pin

    • Bluetooth GND pin → Arduino GND pin

    • Bluetooth TX pin → Arduino pin 0 (RX)

    • Bluetooth RX pin → Arduino pin 1 (TX)

Coding


/*
 Voltaat learn (http://learn.voltaat.com)
 
 Link for full tutorial:

 Tutorial: Control the Arduino LED using Bluetooth

 This sketch allows you to control the Arduino's built-in LED using Bluetooth
 connection from your smartphone or computer.

 Connections:
 • Bluetooth VCC pin → Arduino 5V pin
 • Bluetooth GND pin → Arduino GND pin
 • Bluetooth TX pin → Arduino pin 0 (RX)
 • Bluetooth RX pin → Arduino pin 1 (TX)
*/

char inputData = ' '; // Initialize inputData to a space character

void setup() {
 Serial.begin(9600); // Initialize serial communication at 9600 bps
 pinMode(LED_BUILTIN, OUTPUT); // Set LED pin as output
}

void loop() {
 if (Serial.available() > 0) { // If there is data available
   inputData = Serial.read(); // Read the incoming data

   if (inputData == 'o' || inputData == 'O') { // If the received character is 'o' or 'O'
     digitalWrite(LED_BUILTIN, HIGH); // Turn on the LED
     Serial.println("Received, Arduino LED is turned ON"); // Print a message
   }
   else if (inputData == 'f' || inputData == 'F') { // If the received character is 'f' or 'F'
     digitalWrite(LED_BUILTIN, LOW); // Turn off the LED
     Serial.println("Received, Arduino LED is turned OFF"); // Print a message
   }
 }
}

Testing it Out

know when your plant needs watering

Now you must have correctly wired the Bluetooth to the Arduino as we explained in the wiring section, as well as uploaded the code to your Arduino board.

For the next step, you need to download an app that allows you to send data via Bluetooth to your Arduino through a terminal.

The app is available to download from Google Play store for free. You can download it from here!

Unfortunately, the HC-05 doesn’t work with the iPhone. For the iPhone, you need to use the BLE 4.0 Bluetooth module. It works exactly the same.

After installing the app on your smartphone, simply open it. The app will ask you to provide it with access to your phone’s Bluetooth, which you must do.

The app will ask you to choose the Bluetooth name, which will be HC-05 by default. If it asks you to enter a password, try 1234 or 0000 as the password.

know when your plant needs watering

The connection to the HC-05 Bluetooth module will take a while.

Now look at the HC-05’s built-in LED. If it is blinking fast, it means there is no connection, but if it is blinking every 5 seconds, it means the Bluetooth is connected successfully to your phone.

know when your plant needs watering

The app is very simple and has a user-friendly interface. It may be used in many applications. For this tutorial, we will just use the

terminal indicated by the arrow in the next image.

know when your plant needs watering

After opening the terminal, it will allow you to send commands to your Arduino over the Bluetooth connection. It is as simple as chatting with your friend. Let’s chat with your Arduino!

know when your plant needs watering

As you see in the previous image, when you send the character ‘o’ to your Arduino, the LED is turned on, but if you send the character ‘f’, the LED is turned off.

You can develop this code to have more functionality, like controlling an RGB strip or even a robot!

Now access the serial monitor on your Arduino IDE by clicking on the magnifying glass icon at the top right corner.

know when your plant needs watering

The serial monitor will also print the status of the LED according to the data it receives.

know when your plant needs watering

Resources

No items found.