Getting Arduino Stoplight to work with Sparkfun IR remote

We have set up a four-color Arduinio stoplight (red, yellow, green, and white). They are all on different pins on the breadboard (2, 3, 4, 5). We were trying to incorporate the code we decided to use ('cause everyone has code on this) with that on the Sparkfun site for their IR Remote to work with our stoplight setup. In their demo, they use a RGB LED light. We do not want to do that. We want to use our stoplight setup.

After hours and hours and days and days of trying to code this correctly, it is a disaster. All we want to do is get the IR remote from Sparkfun to turn on the white light (only) on our stoplight relay while the lights are in relay. So, the lights will be going…but when we press the remote, the white lights comes on (even if other lights are on at the same time). That’s it! The white light can come on when we push either buttons A, B or C on the remote (doesn’t matter).

We have already set up everything else. The light relay works fine. We have the IR light receiver on the breadboard set up and wired. IT’S THE CODE THAT’S DRIVING US CRAZY for beginners. >:(

This is the code we chose to use because it was friendly:

// variables
int RED = 2;
int YELLOW = 3;
int GREEN = 4;
int WHITE = 5;

int DELAY_RED = 10000;
int DELAY_YELLOW = 5000;
int DELAY_GREEN = 10000;
int DELAY_WHITE = 5000;
void setup() {
// put your setup code here, to run once:
pinMode(RED, OUTPUT);

void loop() {
// put your main code here, to run repeatedly:




void red_light()
digitalWrite(RED, HIGH);
digitalWrite(YELLOW, LOW);
digitalWrite(GREEN, LOW);
digitalWrite(WHITE, LOW);

void yellow_light()
digitalWrite(RED, LOW);
digitalWrite(YELLOW, HIGH);
digitalWrite(GREEN, LOW);
digitalWrite(WHITE, LOW);

void green_light()
digitalWrite(RED, LOW);
digitalWrite(YELLOW, LOW);
digitalWrite(GREEN, HIGH);
digitalWrite(WHITE, LOW);

void white_light()
digitalWrite(GREEN, LOW);
digitalWrite(YELLOW, LOW);
digitalWrite(RED, LOW);
digitalWrite(WHITE, HIGH);

Then, there is the Sparkfun code for the IR remote (not so friendly for us):

/* RGB Remote Control
by: Jim Lindblom
SparkFun Electronics
date: October 1, 2013

This sketch uses Ken Shirriff’s awesome IRremote library:

RGB Remote Control uses a combination of SparkFun’s
IR Remote ( and an
IR receiver diode (IR Receiver Diode - TSOP38238 - SEN-10266 - SparkFun Electronics) to
control an RGB LED.

The IR Remote’s power button turns the LED on or off. The A, B,
and C buttons select a channel (red, green, or blue). The up
and down arrows increment or decrement the LED brightness on that channel.
The left and right arrows turn a channel to min or max, and
circle set it to the middle.

Hardware setup:

  • The output of an IR Receiver Diode (38 kHz demodulating
    version) should be connected to the Arduino’s pin 11.
  • The IR Receiver diode should also be powered off the
    Arduino’s 5V and GND rails.
  • A common cathode RGB LED is connected to Arduino’s pins
    5, 9, and 6 (red, green, and blue pins).

#include <IRremote.h> // Include the IRremote library

/* Setup constants for SparkFun’s IR Remote: /
#define NUM_BUTTONS 9 // The remote has 9 buttons
Define the IR remote button codes. We’re only using the
least signinficant two bytes of these codes. Each one
should actually have 0x10EF in front of it. Find these codes
by running the IRrecvDump example sketch included with
the IRremote library.*/
const uint16_t BUTTON_POWER = 0xD827; // i.e. 0x10EFD827
const uint16_t BUTTON_A = 0xF807;
const uint16_t BUTTON_B = 0x7887;
const uint16_t BUTTON_C = 0x58A7;
const uint16_t BUTTON_UP = 0xA05F;
const uint16_t BUTTON_DOWN = 0x00FF;
const uint16_t BUTTON_LEFT = 0x10EF;
const uint16_t BUTTON_RIGHT = 0x807F;
const uint16_t BUTTON_CIRCLE = 0x20DF;

/* Connect the output of the IR receiver diode to pin 11. /
int RECV_PIN = 11;
Initialize the irrecv part of the IRremote library */
IRrecv irrecv(RECV_PIN);
decode_results results; // This will store our IR received codes
uint16_t lastCode = 0; // This keeps track of the last code RX’d

/* Setup RGB LED pins: */
enum ledOrder // Make an enum to add some clarity in the code
RED, // 0
GREEN, // 1
BLUE // 2
const int rgbPins[3] = {5, 9, 6}; // Red, green, blue pins respectively
byte rgbValues[3] = {55, 23, 200}; // This keeps track of channel brightness
byte activeChannel = RED; // Start with RED as the active channel
boolean ledEnable = 1; // Start with the LED on.

void setup()
Serial.begin(9600); // Use serial to debug.
irrecv.enableIRIn(); // Start the receiver

/* Set up the RGB LED pins: /
for (int i=0; i<3; i++)
analogWrite(rgbPins_, rgbValues*);
// loop() constantly checks for any received IR codes. At the*
// end it updates the RGB LED.
void loop()
* if (irrecv.decode(&results))
/ read the RX’d IR into a 16-bit variable: /_

uint16_t resultCode = (results.value & 0xFFFF);
_ / The remote will continue to spit out 0xFFFFFFFF if a_

* button is held down. If we get 0xFFFFFFF, let’s just*
_ assume the previously pressed button is being held down /
if (resultCode == 0xFFFF)
resultCode = lastCode;
* lastCode = resultCode;
// This switch statement checks the received IR code against*
* // all of the known codes. Each button press produces a*
* // serial output, and has an effect on the LED output.
switch (resultCode)
_ Serial.println(“Power”);
if (ledEnable) ledEnable = 0;
else ledEnable = 1; // Flip ledEnable*
* break;_
case BUTTON_A:
_ Serial.println(“A”);
activeChannel = RED;
case BUTTON_B:
_ Serial.println(“B”);
activeChannel = GREEN;
case BUTTON_C:
_ Serial.println(“C”);
activeChannel = BLUE;
_ Serial.println(“Up”);
rgbValues[activeChannel]++; // Increment brightness*
* break;_
_ Serial.println(“Down”);
rgbValues[activeChannel]–; // Decrement brightness*
* break;_
_ Serial.println(“Left”);
rgbValues[activeChannel] = 0; // Min brightness (off)
_ Serial.println(“Right”);
rgbValues[activeChannel] = 255; // Max brightness*
* break;_
_ Serial.println(“Circle”);
rgbValues[activeChannel] = 127; // Medium brightness*
* break;
Serial.print(“Unrecognized code received: 0x”);
Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value*
* }
// Every time through the loop, update the RGB LEDs:
if (ledEnable)
for (int i=0; i<3; i++)
analogWrite(rgbPins, rgbValues);

* {
for (int i=0; i<3; i++)
analogWrite(rgbPins, 0);

Any help would be appreciated. What we’ve tried before has produced nothing but error messages. We have also downloaded the Arduino library._