# LED_Puzzle

181

1

This puzzle was created for a school project called If This Then That, I.T.T.T. when abbreviated. In this indestructible I will be guiding you though the steps I made to get to where I am now, which is a functioning puzzle made with Arduino.

For this puzzle I used 16 LED of various colors, and 6 buttons.

### Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

## Step 1: What Is This LED_Puzzle?

The puzzle consists of 16 led lights as previously mentioned. The leds are categorized into 4 rows of 4 different colors. The first color is red, then comes orange, green and lastly blue. The whole idea is that the blue leds are only turned on when the row corresponding to the button is lit. Each blue led corresponds to one row except the one, which is used to indicate the puzzle as completed. This led will only turn on when all other bleu led are lit.

To complete the puzzle you have to press the buttons to turn on the different leds in the rows. One button turns some leds on and others of within its corresponding row. You can change which within the code to make it more or less difficult as you see fit. Though I warn you, it's quite a puzzle to make it solvable.

Now to the next step, getting the materials and connecting everything to the Arduino.

## Step 2: Materials and the Setup

What you need is either quite a big breadboard or something you can solder all the resistors and leds onto.

Materials:

-16 leds (1 red, 3 orange, 5 green, 7 blue) or whatever color scheme you want.

-6 push buttons.

-22 resistors (it would be for the best if you calculate which you need for the best performance).

-an Arduino with more than 22 digital inputs.

-lots of wires (around 50 should be enough).

-a breadboard (or two if you don't want to solder the leds)

The fristzing above should give you a clear view of the setup I used.

## Step 3: The Code

The code is mostly hard-coded. I am not that good at coding yet. For the buttons you could use a debounce instead of the boolean I used for better usability. Now the buttons may not react immediately or react in a different way then anticipated.

The code (I have no idea how to implement it in a better way).

const int buttonRow1 = 2;
const int buttonRow2 = 3; const int buttonRow3 = 4; const int buttonRow4 = 6; const int buttonRow5 = 7; const int buttonRow6 = 9; const int LED_red = 51; const int LED_orange1 = 44; const int LED_orange2 = 46; const int LED_orange3 = 48; const int LED_green1 = 31; const int LED_green2 = 33; const int LED_green3 = 35; const int LED_green4 = 39; const int LED_green5 = 41; const int LED_blue1 = 27; const int LED_blue2 = 25; const int LED_blue3 = 23; const int LED_blue4 = 22; const int LED_blue5 = 34; const int LED_blue6 = 36; const int LED_blue7 = 38; bool ButtonState = false;

void setup(){ pinMode(buttonRow1,INPUT); pinMode(buttonRow2,INPUT); pinMode(buttonRow3,INPUT); pinMode(buttonRow4,INPUT); pinMode(buttonRow5,INPUT); pinMode(buttonRow6,INPUT); pinMode(LED_red,OUTPUT); pinMode(LED_orange1,OUTPUT); pinMode(LED_orange2,OUTPUT); pinMode(LED_orange3,OUTPUT); pinMode(LED_green1,OUTPUT); pinMode(LED_green2,OUTPUT); pinMode(LED_green3,OUTPUT); pinMode(LED_green4,OUTPUT); pinMode(LED_green5,OUTPUT); pinMode(LED_blue1,OUTPUT); pinMode(LED_blue2,OUTPUT); pinMode(LED_blue3,OUTPUT); pinMode(LED_blue4,OUTPUT); pinMode(LED_blue5,OUTPUT); pinMode(LED_blue6,OUTPUT); pinMode(LED_blue7,OUTPUT); }

void loop(){ //Code for buttonRow1, LED_red, LED_green1 and LED_orange1 if (digitalRead(buttonRow1) == HIGH && ButtonState == false) { ButtonState = true; if (digitalRead(LED_red) == HIGH || digitalRead(LED_orange1) == HIGH || digitalRead(LED_green1) == HIGH ) { digitalWrite (LED_red,LOW); digitalWrite (LED_orange1,LOW); digitalWrite (LED_green1,LOW); } else if (digitalRead(LED_red) == LOW || digitalRead(LED_orange1) == LOW || digitalRead(LED_green1) == LOW ) { digitalWrite (LED_red,HIGH); digitalWrite (LED_orange1,HIGH); digitalWrite (LED_green1,HIGH); } } if (digitalRead(buttonRow1) == LOW){ ButtonState = false; } //Code for lighting blue1 if (digitalRead(LED_red) == HIGH && digitalRead(LED_orange1) == HIGH && digitalRead(LED_green1) == HIGH){ digitalWrite(LED_blue1,HIGH); } else{ digitalWrite(LED_blue1,LOW); } //Code for buttonRow2, LED_green2, LED_orange2 and LED_orange3 if (digitalRead(buttonRow2)==HIGH && ButtonState == false) { ButtonState = true; if (digitalRead(LED_green2) == LOW || digitalRead(LED_orange2) == LOW || digitalRead(LED_orange3) == HIGH ) { digitalWrite (LED_green2,HIGH); digitalWrite (LED_orange2,HIGH); digitalWrite (LED_orange3,LOW); } else if (digitalRead(LED_green2) == HIGH || digitalRead(LED_orange2) == HIGH || digitalRead(LED_orange3) == LOW ) { digitalWrite (LED_green2,LOW); digitalWrite (LED_orange2,LOW); digitalWrite (LED_orange3,HIGH); } } if (digitalRead(buttonRow2) == LOW){ ButtonState = false; } //Code for lighting blue2 if (digitalRead(LED_green2) == HIGH && digitalRead(LED_orange2) == HIGH && digitalRead(LED_orange3) == HIGH){ digitalWrite(LED_blue2,HIGH); } else{ digitalWrite(LED_blue2,LOW); } //Code for buttonRow3, LED_green5, LED_green4 and LED_green3 if (digitalRead(buttonRow3)==HIGH && ButtonState == false) { ButtonState = true; if (digitalRead(LED_green5) == LOW || digitalRead(LED_green4) == HIGH || digitalRead(LED_green3) == HIGH ) { digitalWrite (LED_green5,HIGH); digitalWrite (LED_green4,LOW); digitalWrite (LED_green3,LOW); } else if (digitalRead(LED_green5) == HIGH || digitalRead(LED_green4) == LOW || digitalRead(LED_green3) == LOW ) { digitalWrite (LED_green5,LOW); digitalWrite (LED_green4,HIGH); digitalWrite (LED_green3,HIGH); } } if (digitalRead(buttonRow3) == LOW){ ButtonState = false; } //Code for lighting blue3 if (digitalRead(LED_green5) == HIGH && digitalRead(LED_green4) == HIGH && digitalRead(LED_green3) == HIGH){ digitalWrite(LED_blue3,HIGH); } else{ digitalWrite(LED_blue3,LOW); } //Code for buttonRow4, LED_red, LED,orange3 and LED_green5 if (digitalRead(buttonRow4)==HIGH && ButtonState == false) { ButtonState = true; if (digitalRead(LED_red) == HIGH || digitalRead(LED_orange3) == LOW || digitalRead(LED_green5) == LOW ) { digitalWrite (LED_red,LOW); digitalWrite (LED_orange3,HIGH); digitalWrite (LED_green5,HIGH); } else if (digitalRead(LED_red) == LOW || digitalRead(LED_orange3) || HIGH && digitalRead(LED_green5) == HIGH ) { digitalWrite (LED_red,HIGH); digitalWrite (LED_orange3,LOW); digitalWrite (LED_green5,LOW); } } if (digitalRead(buttonRow4) == LOW){ ButtonState = false; } //Code for lighting blue7 if (digitalRead(LED_red) == HIGH && digitalRead(LED_orange3) == HIGH && digitalRead(LED_green5) == HIGH){ digitalWrite(LED_blue7,HIGH); } else{ digitalWrite(LED_blue7,LOW); } //Code for buttonRow5, LED_orange1, LED_orange2 and LED_green4 if (digitalRead(buttonRow5)==HIGH && ButtonState == false) { ButtonState = true; if (digitalRead(LED_green4) == LOW || digitalRead(LED_orange2) == HIGH || digitalRead(LED_orange1) == LOW ) { digitalWrite (LED_green4,HIGH); digitalWrite (LED_orange2,LOW); digitalWrite (LED_orange1,HIGH); } else if (digitalRead(LED_green4) == HIGH || digitalRead(LED_orange2) == LOW || digitalRead(LED_orange1) == HIGH ) { digitalWrite (LED_green4,LOW); digitalWrite (LED_orange2,HIGH); digitalWrite (LED_orange1,LOW); } } if (digitalRead(buttonRow5) == LOW){ ButtonState = false; } //Code for lighting blue6 if (digitalRead(LED_orange1) == HIGH && digitalRead(LED_orange2) == HIGH && digitalRead(LED_green4) == HIGH){ digitalWrite(LED_blue6,HIGH); } else{ digitalWrite(LED_blue6,LOW); } //Code for buttonRow6, LED_green1, LED_green2 and LED_green3 if (digitalRead(buttonRow6)==HIGH && ButtonState == false) { ButtonState = true; if (digitalRead(LED_green1) == HIGH || digitalRead(LED_green2) == LOW || digitalRead(LED_green3) == LOW ) { digitalWrite (LED_green1,LOW); digitalWrite (LED_green2,HIGH); digitalWrite (LED_green3,HIGH); } else if (digitalRead(LED_green1) == LOW || digitalRead(LED_green2) == HIGH || digitalRead(LED_green3) == HIGH ) { digitalWrite (LED_green1,HIGH); digitalWrite (LED_green2,LOW); digitalWrite (LED_green3,LOW); } } if (digitalRead(buttonRow6) == LOW){ ButtonState = false; } //Code for lighting blue5 if (digitalRead(LED_green1) == HIGH && digitalRead(LED_green2) == HIGH && digitalRead(LED_green3) == HIGH){ digitalWrite(LED_blue5,HIGH); } else{ digitalWrite(LED_blue5,LOW); }

//Code for completing the puzzle if (digitalRead(LED_blue1) == HIGH && digitalRead(LED_blue2) == HIGH && digitalRead(LED_blue3) == HIGH && digitalRead(LED_blue5) == HIGH && digitalRead(LED_blue6) == HIGH && digitalRead(LED_blue7) == HIGH) { digitalWrite(LED_blue4,HIGH); } else{ digitalWrite(LED_blue4,LOW); } }

## Recommendations

• ### Internet of Things Class

22,715 Enrolled