RGB led control using bluetooth module
RGB led controlling with the mobile application via bluetooth mode HC-05 and Arduino Uno.
Apps and platforms
1
Arduino IDE
Project description
Code
RGB Bluetooth control
c_cpp
1#include <SoftwareSerial.h> 2SoftwareSerial BLU(0,1); 3#define redPin 6 4#define greenPin 3 5#define bluePin 5 6void setup() 7{ 8 //Serial setup 9 Serial.begin(9600); 10 Serial.println("-= HC-05 Bluetooth RGB LED =-"); 11 BLU.begin(9600); 12 BLU.println("-= HC-05 Bluetooth RGB LED =-"); 13 14 pinMode(4, OUTPUT); 15 pinMode(redPin, OUTPUT); 16 pinMode(greenPin, OUTPUT); 17 pinMode(bluePin, OUTPUT); 18 digitalWrite(4,HIGH); 19 setColor(255, 0, 0); 20 delay(500); 21 setColor(0, 255, 0); 22 delay(500); 23 setColor(0, 0, 255); 24 delay(500); 25 setColor(255, 255, 255); 26} 27void loop() 28{ 29 while (BLU.available() > 0) 30 { 31 int redInt = BLU.parseInt(); 32 int greenInt = BLU.parseInt(); 33 int blueInt = BLU.parseInt(); 34 redInt = constrain(redInt, 0, 255); 35 greenInt = constrain(greenInt, 0, 255); 36 blueInt = constrain(blueInt, 0, 255); 37 if (BLU.available() > 0) 38 { 39 setColor(redInt, greenInt, blueInt); 40 Serial.print("Red: "); 41 Serial.print(redInt); 42 Serial.print(" Green: "); 43 Serial.print(greenInt); 44 Serial.print(" Blue: "); 45 Serial.print(blueInt); 46 Serial.println(); 47 BLU.flush(); 48 } 49 } 50} 51void setColor(int red, int green, int blue) 52{ 53 analogWrite(redPin, red); 54 analogWrite(greenPin, green); 55 analogWrite(bluePin, blue); 56} 57
RGB Bluetooth control
c_cpp
1#include <SoftwareSerial.h> 2SoftwareSerial BLU(0,1); 3#define redPin 6 4#define greenPin 3 5#define bluePin 5 6void setup() 7{ 8 //Serial setup 9 Serial.begin(9600); 10 Serial.println("-= HC-05 Bluetooth RGB LED =-"); 11 BLU.begin(9600); 12 BLU.println("-= HC-05 Bluetooth RGB LED =-"); 13 14 pinMode(4, OUTPUT); 15 pinMode(redPin, OUTPUT); 16 pinMode(greenPin, OUTPUT); 17 pinMode(bluePin, OUTPUT); 18 digitalWrite(4,HIGH); 19 setColor(255, 0, 0); 20 delay(500); 21 setColor(0, 255, 0); 22 delay(500); 23 setColor(0, 0, 255); 24 delay(500); 25 setColor(255, 255, 255); 26} 27void loop() 28{ 29 while (BLU.available() > 0) 30 { 31 int redInt = BLU.parseInt(); 32 int greenInt = BLU.parseInt(); 33 int blueInt = BLU.parseInt(); 34 redInt = constrain(redInt, 0, 255); 35 greenInt = constrain(greenInt, 0, 255); 36 blueInt = constrain(blueInt, 0, 255); 37 if (BLU.available() > 0) 38 { 39 setColor(redInt, greenInt, blueInt); 40 Serial.print("Red: "); 41 Serial.print(redInt); 42 Serial.print(" Green: "); 43 Serial.print(greenInt); 44 Serial.print(" Blue: "); 45 Serial.print(blueInt); 46 Serial.println(); 47 BLU.flush(); 48 } 49 } 50} 51void setColor(int red, int green, int blue) 52{ 53 analogWrite(redPin, red); 54 analogWrite(greenPin, green); 55 analogWrite(bluePin, blue); 56} 57
Downloadable files
RGB controlling via Bluetooth module
RGB controlling via Bluetooth module

Comments
Only logged in users can leave comments