Week 7: LED Puzzle (Arduino)

Challenge: Turn on the blue LED!

For this first Arduino exercise, I wired up three LEDs and three buttons in parallel. On my board, they are all mapped logically with the same color of button and LED next to each other. But when clicking, this mental mapping does not completely translate to the output. The red and yellow button work as we would expect them to and turn on the red and yellow LED respectively. The blue button, however, turns on both the red and yellow LEDs but not the blue one. How then can we turn on the blue LED?

Arduino setup.

Watch the video here.

int blueledPin = 2; 
int bluebuttonPin = 3; 
int yellowledPin = 4;
int yellowbuttonPin = 5;
int redledPin = 6;
int redbuttonPin = 7;

void setup() {
  //BLUE button + LED
  pinMode(blueledPin, OUTPUT); 
  pinMode(bluebuttonPin, INPUT);

  //YELLOW button + LED
  pinMode(yellowledPin, OUTPUT); 
  pinMode(yellowbuttonPin, INPUT);

  //RED button + LED
  pinMode(redledPin, OUTPUT); 
  pinMode(redbuttonPin, INPUT);

void loop() {
  //BLUE button triggers RED and YELLOW LED
  int bluebuttonState = digitalRead(bluebuttonPin);
  digitalWrite(redledPin, bluebuttonState);
  digitalWrite(yellowledPin, bluebuttonState);

  //YELLOW button triggers YELLOW LED
  int yellowbuttonState = digitalRead(yellowbuttonPin);
  digitalWrite(yellowledPin, yellowbuttonState);

  //RED button triggers RED LED
  int redbuttonState = digitalRead(redbuttonPin);
  digitalWrite(redledPin, redbuttonState);

  //if YELLOW and RED button pressed turn on BLUE LED
  if (redbuttonState == yellowbuttonState) {
    digitalWrite(blueledPin, redbuttonState);

Solution: Pressing the red and yellow button together will turn on the blue LED.

Leave a Reply