Components and supplies
Jumper wires (generic)
HC-05 Bluetooth Module
Arduino UNO
rgb led
Apps and platforms
color led controller
Project description
Code
untitled
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
untitled
c_cpp
1#include <SoftwareSerial.h> 2SoftwareSerial BLU(0,1); 3#define redPin 4 6 5#define greenPin 3 6#define bluePin 5 7void setup() 8{ 9 //Serial 10 setup 11 Serial.begin(9600); 12 Serial.println("-= HC-05 Bluetooth RGB LED 13 =-"); 14 BLU.begin(9600); 15 BLU.println("-= HC-05 Bluetooth RGB LED =-"); 16 17 18 pinMode(4, OUTPUT); 19 pinMode(redPin, OUTPUT); 20 pinMode(greenPin, OUTPUT); 21 22 pinMode(bluePin, OUTPUT); 23 digitalWrite(4,HIGH); 24 setColor(255, 0, 0); 25 26 delay(500); 27 setColor(0, 255, 0); 28 delay(500); 29 setColor(0, 0, 255); 30 31 delay(500); 32 setColor(255, 255, 255); 33} 34void loop() 35{ 36 while 37 (BLU.available() > 0) 38 { 39 int redInt = BLU.parseInt(); 40 int greenInt 41 = BLU.parseInt(); 42 int blueInt = BLU.parseInt(); 43 redInt = constrain(redInt, 44 0, 255); 45 greenInt = constrain(greenInt, 0, 255); 46 blueInt = constrain(blueInt, 47 0, 255); 48 if (BLU.available() > 0) 49 { 50 setColor(redInt, greenInt, 51 blueInt); 52 Serial.print("Red: "); 53 Serial.print(redInt); 54 Serial.print(" 55 Green: "); 56 Serial.print(greenInt); 57 Serial.print(" Blue: "); 58 59 Serial.print(blueInt); 60 Serial.println(); 61 BLU.flush(); 62 63 } 64 } 65} 66void setColor(int red, int green, int blue) 67{ 68 analogWrite(redPin, 69 red); 70 analogWrite(greenPin, green); 71 analogWrite(bluePin, blue); 72} 73
Comments
Only logged in users can leave comments