hi.
welcome to my fist try to make an RGB led controlled by an IR remote.
so you are probably wondering why i would want this; so me and my dad bought an RGB Led led strip with controller for behind the television it broke and we did not wan't to buy a new one so i made this, it doesn't work for led strips on this moment then i would need to add some transistors and stuff and a RGB led strip to test it... so i started with this. it took me around 2 hours to code because i am not really good at coding, but i like it and it works for what i wanted to do.
the link for the library is at the bottom of the post
the photo is an attachment of the post because i did not know how to get it in the post
you wil probably need to change the IR receive codes because you are probably using a differed remote
i hope you like it and can use it.
#include <IRremote.h>
/*
PINS:
Red pin - Pin 8 on the arduino
Green pin - pin 9 on the arduino
Blue pin - pin 10 on the arduino
Receive pin from the IR receiver - pin 7 on the arduino
use the library from: https://github.com/z3t0/Arduino-IRremote
*/
const int RECV_PIN = 7;
IRrecv irrecv(RECV_PIN);
decode_results results;
unsigned long key_value = 0;
int Rpin = 8;
int Gpin = 9;
int Bpin = 10;
// Program variables
int redVal = 255; // Variables to store the values to send to the pins
int greenVal = 1; // Initial values are Red full, Green and Blue off
int blueVal = 1;
int P = 0; // Loop counter
int wait = 10; // 50ms (.05 second) delay; shorten for faster fades
void setup(){
Serial.begin(9600); // ...set up the serial ouput on 0004 style
irrecv.enableIRIn();
irrecv.blink13(true);
pinMode(Rpin, OUTPUT);
pinMode(Gpin, OUTPUT);
pinMode(Bpin, OUTPUT);
}
void loop(){
if (irrecv.decode(&results)){
if (results.value == 0XFFFFFFFF)
results.value = key_value;
Serial.println(results.value, HEX);
switch(results.value){
case 0xFF02FD:
Serial.println("ON");
setColor(0, 0, 0); // on/white
break;
case 0xFF827D:
Serial.println("OFF");
setColor(255, 255, 255); // off
break;
case 0xFF1AE5:
Serial.println("Dark red");
setColor(0, 255, 255); // Dark red
break;
case 0xFF2AD5:
Serial.println("light red");
setColor(20, 245, 245); // light red
break;
case 0xFF0AF5:
Serial.println("dark orange");
setColor(40, 235, 235); // dark orange
break;
case 0xFF38C7:
Serial.println("Orange");
setColor(0, 102, 255); // Orange
break;
case 0xFF18E7:
Serial.println("Yellow");
setColor(0, 0, 255); // Yellow
break;
case 0xFF9A65:
Serial.println("Less dark green");
setColor(255, 72, 234); // Less dark green
break;
case 0xFFAA55:
Serial.println("Green");
setColor(255, 0, 255); // Green
break;
case 0xFF8A75:
Serial.println("Dark green");
setColor(255, 153, 255); // Dark green
break;
case 0xFFB847:
Serial.println("Less light blue");
setColor(204, 51, 51); // Less light blue
break;
case 0xFF9867:
Serial.println("Darkest blue");
setColor(255, 255, 0); // Darkest blue
break;
case 0xFFA25D:
Serial.println("dark blue");
setColor(255, 204, 153); // dark blue
break;
case 0xFF926D:
Serial.println("less dark blue");
setColor(250, 250, 25); // less dark blue
break;
case 0xFFB24D:
Serial.println("Black");
setColor(250, 250, 250); // Black
break;
case 0xFF7887:
Serial.println("Brown");
setColor(102, 204, 255); // Brown
break;
case 0xFF58A7:
Serial.println("Pink1");
setColor(0, 255, 153); // Pink1
break;
case 0xFF22DD:
Serial.println("White");
setColor(0, 0, 0); // White
break;
case 0xFF12ED:
Serial.println("Pink2");
setColor(0, 255, 153); // Pink2
break;
case 0xFF32CD:
Serial.println("Pink3");
setColor(0, 255, 153); // Pink3
break;
case 0xFFF807:
Serial.println("light blue1");
setColor(102, 0, 51); // light blue1
break;
case 0xFF30CF:
Serial.println("Jump3");
int i;
for (i = 0; i < 5; i++)
{
Jump3(); // Jump3
}
break;
case 0xFF906F:
Serial.println("Flash");
int o;
for (o = 0; o < 5; o++)
{
Flash();
}
break;
case 0xFFB04F:
Serial.println("fade");
int u;
for (u = 0; u < 800; u++)
{
fade();
}
break;
}
key_value = results.value;
irrecv.resume();
}
}
void setColor(int red, int green, int blue)
{
analogWrite(Rpin, red);
analogWrite(Gpin, green);
analogWrite(Bpin, blue);
}
void Jump3()
{
setColor(0, 255, 255); // Dark red
delay(1000);
setColor(255, 72, 234); // Less dark green
delay(1000);
setColor(255, 204, 153); // dark blue
delay(1000);
}
void Flash()
{
setColor(random(0, 255), random(0, 255), random(0, 255)); //pick a random collor
delay(750);
setColor(0,0,0);
delay(500);
}
void fade()
{
P += 1; // Increment counter
if (P < 255) // First phase of fades
{
redVal -= 1; // Red down
greenVal += 1; // Green up
blueVal = 1; // Blue low
}
else if (P < 509) // Second phase of fades
{
redVal = 1; // Red low
greenVal -= 1; // Green down
blueVal += 1; // Blue up
}
else if (P < 763) // Third phase of fades
{
redVal += 1; // Red up
greenVal = 1; // Green low
blueVal -= 1; // Blue down
}
else // Re-set the counter, and start the fades again
{
P = 1;
}
analogWrite(Rpin, redVal); // Write current values to LED pins
analogWrite(Gpin, greenVal);
analogWrite(Bpin, blueVal);
delay(wait); // Pause for 'wait' milliseconds before resuming the loop
}
link for the library: GitHub - Arduino-IRremote/Arduino-IRremote: Infrared remote library for Arduino: send and receive infrared signals with multiple protocols