engineerkid
Published © GPL3+

Bluetooth Controlled RGB Light

In this project we will make a RGB light controller with Arduino & HC-05 Bluetooth Module.

BeginnerFull instructions provided3 hours1,692
Bluetooth Controlled RGB Light

Things used in this project

Hardware components

Arduino Uno
×1
RGB Led Strip
×1
HC-05 Bluetooth Module
×1
IRLZ44N N-channel Mofets
×3
220 ohm and 10k ohm resistor
×3
UTSOURCE Electronic Parts
UTSOURCE Electronic Parts
×1

Story

Read more

Schematics

Circuit Diagram

Android Application

Code

Previous state will not be saved

C/C++
#include <SoftwareSerial.h>
int bluetoothTx = 5;
int bluetoothRx = 6;
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);

void setup()
{
 pinMode(11,OUTPUT); // Blue pin of RGB LED
 pinMode(10,OUTPUT); // Green pin of RGB LED
 pinMode(9,OUTPUT); // Red pin of RGB LED
 //Setup usb serial connection to computer
  Serial.begin(9600);
 //Setup Bluetooth serial connection to android
  bluetooth.begin(9600);
}

void loop()
{
  //Read from bluetooth and write to usb serial
  if(bluetooth.available()>= 2 )
  {
    unsigned int color1 = bluetooth.read();
    unsigned int color2 = bluetooth.read();
    unsigned int color = (color2 *256) + color1;
    Serial.println(color);
   
    if (color >= 1000 && color <1255)
    {
    int blue = color;
    blue = map(blue, 1000,1255,0,255);
    int blue1 = 255-blue;
    analogWrite(11,blue1);
    //Serial.print(blue1);
    }
   
    if (color >=2000 && color <2255)
    {
      int green = color;
      green = map(green,2000,2255,0,255);
      int green1 = 255 - green;
      analogWrite(10,green1);
     // Serial.print(green1);
    }
   
    if (color >=3000 && color < 3255)
    {
      int red = color;
      red = map(red, 3000, 3255,0,255);
      int red1 = 255 - red;
      analogWrite(9,red1);
      //Serial.print(red1);
    }
 }
}

Previous state will be saved

C/C++
#include <SoftwareSerial.h>
#include <EEPROM.h>
int bluetoothTx = 5;
int bluetoothRx = 6;
int addrR = 0;
int addrG = 1;
int addrB = 2;
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);

void setup()
{
 pinMode(11,OUTPUT); // Blue pin of RGB LED
 pinMode(10,OUTPUT); // Green pin of RGB LED
 pinMode(9,OUTPUT); // Red pin of RGB LED
 //Setup usb serial connection to computer
  Serial.begin(9600);
 //Setup Bluetooth serial connection to android
  bluetooth.begin(9600);

  int red1 = EEPROM.read(addrR);
  int green1 = EEPROM.read(addrG);
  int blue1 = EEPROM.read(addrB);
  analogWrite(9,red1);
  analogWrite(10,green1);
  analogWrite(11,blue1);
}

void loop()
{
  //Read from bluetooth and write to usb serial
  if(bluetooth.available()>= 2 )
  {
    unsigned int color1 = bluetooth.read();
    unsigned int color2 = bluetooth.read();
    unsigned int color = (color2 *256) + color1;
    Serial.println(color);
   
    if (color >= 1000 && color <1255)
    {
    int blue = color;
    blue = map(blue, 1000,1255,0,255);
    int blue1 = 255-blue;
    analogWrite(11,blue1);
    //Serial.print(blue1);
    delay(10);
    EEPROM.write(addrB, blue1);
    }
   
    if (color >=2000 && color <2255)
    {
      int green = color;
      green = map(green,2000,2255,0,255);
      int green1 = 255 - green;
      analogWrite(10,green1);
     // Serial.print(green1);
      delay(10);
     EEPROM.write(addrG, green1);
    }
   
    if (color >=3000 && color < 3255)
    {
      int red = color;
      red = map(red, 3000, 3255,0,255);
      int red1 = 255 - red;
      analogWrite(9,red1);
      //Serial.print(red1);
      delay(10);
      EEPROM.write(addrR, red1);
    }
 }
}

Credits

engineerkid

engineerkid

13 projects • 0 followers
How To Protect Yourself From Coronavirus click above link☝☝☝

Comments