Components and supplies
RGB LED
IR remote and receiver
Arduino UNO
Project description
Code
Untitled file
arduino
1#include <IRremote.h> // include the IRremote library 2#define IR_RECEIVE_PIN 3 2 4 5long data = 0; 6 7int redPin = 9; //select the pin for the red LED 8int 9 bluePin = 10; // select the pin for the blue LED 10int greenPin = 11; // select 11 the pin for the green LED 12 13void setup() { 14 Serial.begin(9600); // begin 15 serial communication with a baud rate of 9600 16 17 IrReceiver.begin(IR_RECEIVE_PIN, 18 ENABLE_LED_FEEDBACK); 19 20 pinMode(redPin, OUTPUT); 21 pinMode(bluePin, OUTPUT); 22 23 pinMode(greenPin, OUTPUT); 24} 25 26void loop() { 27 if (IrReceiver.decode()) 28 { 29 30 if (IrReceiver.decodedIRData.decodedRawData != 0) { 31 data = 32 IrReceiver.decodedIRData.decodedRawData; 33 } 34 35 switch (data) { // 36 compare the value to the following cases 37 case 3910598400: 38 Serial.println("1, 39 Red"); 40 setLed(255, 0, 0); 41 break ; 42 case 3860463360: 43 44 Serial.println("2, Orange"); 45 setLed(255, 128, 0); 46 break 47 ; 48 case 4061003520: 49 Serial.println("3, Yellow"); 50 setLed(255, 51 255, 0); 52 break; 53 case 4077715200: 54 Serial.println("4, 55 Green"); 56 setLed(0, 255, 0); 57 break ; 58 case 3877175040: 59 60 Serial.println("5, Blue"); 61 setLed(0, 0, 255); 62 break 63 ; 64 case 2707357440: 65 Serial.println("6, Intigo"); 66 setLed(127, 67 0, 255); 68 break ; 69 case 4144561920: 70 Serial.println("7, 71 Violet"); 72 setLed(255, 0, 255); 73 break ; 74 } 75 IrReceiver.resume(); 76 77 } 78} 79 80void setLed(int r, int g, int b) 81{ 82 analogWrite(redPin, r); 83 analogWrite(greenPin, g); analogWrite(bluePin, b); 84} 85 86
Untitled file
arduino
1#include <IRremote.h> // include the IRremote library 2#define IR_RECEIVE_PIN 2 3 4long data = 0; 5 6int redPin = 9; //select the pin for the red LED 7int bluePin = 10; // select the pin for the blue LED 8int greenPin = 11; // select the pin for the green LED 9 10void setup() { 11 Serial.begin(9600); // begin serial communication with a baud rate of 9600 12 13 IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK); 14 15 pinMode(redPin, OUTPUT); 16 pinMode(bluePin, OUTPUT); 17 pinMode(greenPin, OUTPUT); 18} 19 20void loop() { 21 if (IrReceiver.decode()) { 22 23 if (IrReceiver.decodedIRData.decodedRawData != 0) { 24 data = IrReceiver.decodedIRData.decodedRawData; 25 } 26 27 switch (data) { // compare the value to the following cases 28 case 3910598400: 29 Serial.println("1, Red"); 30 setLed(255, 0, 0); 31 break ; 32 case 3860463360: 33 Serial.println("2, Orange"); 34 setLed(255, 128, 0); 35 break ; 36 case 4061003520: 37 Serial.println("3, Yellow"); 38 setLed(255, 255, 0); 39 break; 40 case 4077715200: 41 Serial.println("4, Green"); 42 setLed(0, 255, 0); 43 break ; 44 case 3877175040: 45 Serial.println("5, Blue"); 46 setLed(0, 0, 255); 47 break ; 48 case 2707357440: 49 Serial.println("6, Intigo"); 50 setLed(127, 0, 255); 51 break ; 52 case 4144561920: 53 Serial.println("7, Violet"); 54 setLed(255, 0, 255); 55 break ; 56 } 57 IrReceiver.resume(); 58 } 59} 60 61void setLed(int r, int g, int b) 62{ 63 analogWrite(redPin, r); analogWrite(greenPin, g); analogWrite(bluePin, b); 64} 65 66
Downloadable files
remote_controlled_rgb_led_7pDYxdN0IO.fzz
remote_controlled_rgb_led_7pDYxdN0IO.fzz
Comments
Only logged in users can leave comments
Creamms
0 Followers
•1 Projects
0
0