In this tutorial, you will learn about Arduino RGB LED control with Bluetooth.
Here common cathode RGB LED and Bluetooth HC-05 used for interface. The android slider using to control for RGB values from 0 to 255 through An Android application.
Circuit diagram
Components Required
Arduino Nano - 1 no
Bluetooth module HC-05 - 1no
RGB cc- 1 no
Resistor 300E - 1no
Bluetooth HC-05 Module
HC-05 is a Bluetooth module which is designed for wireless communication. This module can be used in a master or slave configuration. Bluetooth serial modules allow all serial enabled devices to communicate with each other using Bluetooth.
It has 6 pins,
Key/EN- NC
VCC to Connect 5 V power
GND to power Ground
TXD to Arduino Nano Rx (D0)
RXD to Arduino Nano Tx (D1)
State- NC
HC-05 module Information
HC-05 has red LED which indicates connection status, whether the Bluetooth is connected or not. Before connecting to HC-05 module this red LED blinks continuously in a periodic manner. When it gets connected to any other Bluetooth device, its blinking slows down to two seconds.
This module works on 3.3 V. We can connect 5V supply voltage as well since the module has on board 5 to 3.3 V regulator.
As HC-05 Bluetooth module has 3.3 V level for RX/TX and microcontroller can detect 3.3 V level, so, no need to shift transmit level of HC-05 module. But we need to shift the transmit voltage level from microcontroller to RX of HC-05 module.
HC-05 Default Settings
Default Bluetooth Name: “HC-05”
Default Password: 1234 or 0000
Download Datasheet
RGB LED
A RGB LED is commonly used component in electronics, generally, as it is used for indication purpose. You can use RGB LED in various projects like portable flashlight, LED indicator, etc. An RGB LED can also be used for work according to condition like for condition 1st Red will glow, for condition 2nd green will glow and for condition 3rd blue will glow.
Pin Configuration
Pin No. Pin Name Description
1 R This terminal used for glowing LED in Red color
2 Gnd Common Cathode terminal (Ground)
3 G This terminal used for glowing LED in Green color
4 B This terminal used for glowing LED in Blue color
Download Datasheet
Installing the Arduino Library
No need any special libraries.
Arduino Code
#include <SoftwareSerial.h>
SoftwareSerial Bluetooth(10,11); // Rx,Tx pin to BT tx, rx pin
char LED_CharRGB; // reads each character
int RedPin = 5; // Red RGB pin -> D5
int GreenPin = 6; // Green RGB pin -> D6
int BluePin = 3; // Bluetoothe RGB pin -> D3
int RedValue = 255; // Red RGB pin -> D5
int GreenValue = 255; // Green RGB pin -> D6
int BlueValue = 255; // Bluetoothe RGB pin -> D3
String RedtempValue;
String GreentempValue;
String BluetempValue;
char CurrentColor;
void setup() {
pinMode(RedPin,OUTPUT);
pinMode(BluePin,OUTPUT);
pinMode(GreenPin, OUTPUT);
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
Bluetooth.begin(9600);
}
void loop() {
//while is reading the message
while(Bluetooth.available() > 0){
{
LED_CharRGB = Bluetooth.read(); // Reads a character
if(LED_CharRGB=='R'){
CurrentColor = 'R';
RedtempValue = "";
}
else if(LED_CharRGB=='G'){
CurrentColor = 'G';
GreentempValue = "";
}
else if(LED_CharRGB=='B'){
CurrentColor = 'B';
BluetempValue = "";
}
if(CurrentColor == 'R' && LED_CharRGB!='R'){
RedtempValue += LED_CharRGB;
}
else if(CurrentColor == 'G' && LED_CharRGB!='G'){
GreentempValue += LED_CharRGB;
}
else if(CurrentColor == 'B' && LED_CharRGB!='B'){
BluetempValue += LED_CharRGB;
}
}
Bluetooth.flush();
}
analogWrite(RedPin, RedtempValue.toInt());
analogWrite(GreenPin, GreentempValue.toInt());
analogWrite(BluePin, BluetempValue.toInt());
}
ANDROID APPLICATION
The Android app developers generally use JAVA language, but this Android app can also build without knowing the Java language. This app inventor is specially designed for Block programmers those who don’t know the JAVA language.
MIT main page
MIT Block
Demo
Comments