In this project, I will show you how to generate an LED pattern with push-button using an Arduino. This project is an advancement of simple Led to multiple LEDs with Arduino and a push-button which switches them at a very fast rate. Whenever you press a push-button it generates a unique pattern that is represented with the help of LEDs. This is a very interesting project Follow the steps below to make it.
Hardware Components
Following are the necessary hardware components:
Working Explanation
S.NO | Components | Value | Qty |
1. | Arduino | Uno R3 | 1 |
2. | USB Cable A/B | – | 1 |
3. | Push Button | – | 1 |
4. | Resistors | 10k,470 ohm | 1,7 |
5. | LED | 5mm | 7 |
6. | Breadboard | – | 1 |
7. | Connecting Wires | – | 1 |
As mentioned earlier as well that this project of an LED pattern is an advancement of simple LEDs to multiple LEDs. After making a simple Led project of turning it on and turning it off with the help of Arduino you can make several other projects and learn new coding with it. In Led pattern project we are using 7 LEDs connected to digital pins of Arduino and a push-button is used to generate a unique pattern on LEDs. Every time a push-button is pressed, it switches the lighting pattern from previous values to the new outputs which are the main idea of the project. This project LED pattern is a great step of practicing your programming skills and learning some new projects.
Connection
- STEP # 1 ( Make Push Button Connections )
- Pin1 to 5V of Arduino.
- Resistor 10k B/w Pin2 of Push Btn & GND of Arduino
- Pin2 is also connected to D6 of Arduino
- STEP # 2 ( Make LED Connections )
- Connect All -VE of LED To GND to Arduino
- STEP # 3 ( Make Resistors Connections )
- All Resistor’s to +VE of LED and then D7,D8,D9,D10,D11,D12,D13 of Arduino
- STEP # 4 ( Upload Code )
Application
- This project can be used as an indication of something like errors
- With the help of this project, you can your secret lock pattern
Circuit Diagram
Code
int L1 = 13; int L2 = 12; int L3 = 11; int L4 = 10; int L5 = 9; int L6 = 8; int L7 = 7; //7 LED pin int buttonPin = 6; //the number of the pushbutton pin int de=50; // delay time int p=0; // variable for pattem int buttonState = 0; // variable for reading the pushbutton status void setup() { pinMode(L1, OUTPUT); pinMode(L2, OUTPUT); pinMode(L3, OUTPUT); pinMode(L4, OUTPUT); pinMode(L5, OUTPUT); pinMode(L6, OUTPUT); pinMode(L7, OUTPUT); pinMode(buttonPin, INPUT); } void loop() { buttonState = digitalRead(buttonPin); if (buttonState == HIGH) { p++; delay(2000); } if(p==1) { digitalWrite(L1,1); digitalWrite(L2,0); digitalWrite(L3,0); digitalWrite(L4,0); digitalWrite(L5,0); digitalWrite(L6,0); digitalWrite(L7,0); //1 delay(de); digitalWrite(L1,0); digitalWrite(L2,1); digitalWrite(L3,0); digitalWrite(L4,0); digitalWrite(L5,0); digitalWrite(L6,0); digitalWrite(L7,0); //2 delay(de); digitalWrite(L1,0); digitalWrite(L2,0); digitalWrite(L3,1); digitalWrite(L4,0); digitalWrite(L5,0); digitalWrite(L6,0); digitalWrite(L7,0); //3 delay(de); digitalWrite(L1,0); digitalWrite(L2,0); digitalWrite(L3,0); digitalWrite(L4,1); digitalWrite(L5,0); digitalWrite(L6,0); digitalWrite(L7,0); //4 delay(de); digitalWrite(L1,0); digitalWrite(L2,0); digitalWrite(L3,0); digitalWrite(L4,0); digitalWrite(L5,1); digitalWrite(L6,0); digitalWrite(L7,0); //5 delay(de); digitalWrite(L1,0); digitalWrite(L2,0); digitalWrite(L3,0); digitalWrite(L4,0); digitalWrite(L5,0); digitalWrite(L6,1); digitalWrite(L7,0); //6 delay(de); digitalWrite(L1,0); digitalWrite(L2,0); digitalWrite(L3,0); digitalWrite(L4,0); digitalWrite(L5,0); digitalWrite(L6,0); digitalWrite(L7,1); //7 delay(de); } if(p==2) { digitalWrite(L1,0); digitalWrite(L2,0); digitalWrite(L3,0); digitalWrite(L4,0); digitalWrite(L5,0); digitalWrite(L6,0); digitalWrite(L7,1); //7 delay(de); digitalWrite(L1,0); digitalWrite(L2,0); digitalWrite(L3,0); digitalWrite(L4,0); digitalWrite(L5,0); digitalWrite(L6,1); digitalWrite(L7,0); //6 delay(de); digitalWrite(L1,0); digitalWrite(L2,0); digitalWrite(L3,0); digitalWrite(L4,0); digitalWrite(L5,1); digitalWrite(L6,0); digitalWrite(L7,0); //5 delay(de); digitalWrite(L1,0); digitalWrite(L2,0); digitalWrite(L3,0); digitalWrite(L4,1); digitalWrite(L5,0); digitalWrite(L6,0); digitalWrite(L7,0); //4 delay(de); digitalWrite(L1,0); digitalWrite(L2,0); digitalWrite(L3,1); digitalWrite(L4,0); digitalWrite(L5,0); digitalWrite(L6,0); digitalWrite(L7,0); //3 delay(de); digitalWrite(L1,0); digitalWrite(L2,1); digitalWrite(L3,0); digitalWrite(L4,0); digitalWrite(L5,0); digitalWrite(L6,0); digitalWrite(L7,0); //2 delay(de); digitalWrite(L1,1); digitalWrite(L2,0); digitalWrite(L3,0); digitalWrite(L4,0); digitalWrite(L5,0); digitalWrite(L6,0); digitalWrite(L7,0); //1 delay(de); } if(p==3) { digitalWrite(L1,1); digitalWrite(L2,0); digitalWrite(L3,0); digitalWrite(L4,0); digitalWrite(L5,0); digitalWrite(L6,0); digitalWrite(L7,0); //1 delay(de); digitalWrite(L1,0); digitalWrite(L2,1); digitalWrite(L3,0); digitalWrite(L4,0); digitalWrite(L5,0); digitalWrite(L6,0); digitalWrite(L7,0); //2 delay(de); digitalWrite(L1,0); digitalWrite(L2,0); digitalWrite(L3,1); digitalWrite(L4,0); digitalWrite(L5,0); digitalWrite(L6,0); digitalWrite(L7,0); //3 delay(de); digitalWrite(L1,0); digitalWrite(L2,0); digitalWrite(L3,0); digitalWrite(L4,1); digitalWrite(L5,0); digitalWrite(L6,0); digitalWrite(L7,0); //4 delay(de); digitalWrite(L1,0); digitalWrite(L2,0); digitalWrite(L3,0); digitalWrite(L4,0); digitalWrite(L5,1); digitalWrite(L6,0); digitalWrite(L7,0); //5 delay(de); digitalWrite(L1,0); digitalWrite(L2,0); digitalWrite(L3,0); digitalWrite(L4,0); digitalWrite(L5,0); digitalWrite(L6,1); digitalWrite(L7,0); //6 delay(de); digitalWrite(L1,0); digitalWrite(L2,0); digitalWrite(L3,0); digitalWrite(L4,0); digitalWrite(L5,0); digitalWrite(L6,0); digitalWrite(L7,1); //7 delay(de); digitalWrite(L1,0); digitalWrite(L2,0); digitalWrite(L3,0); digitalWrite(L4,0); digitalWrite(L5,0); digitalWrite(L6,1); digitalWrite(L7,0); //6 delay(de); digitalWrite(L1,0); digitalWrite(L2,0); digitalWrite(L3,0); digitalWrite(L4,0); digitalWrite(L5,1); digitalWrite(L6,0); digitalWrite(L7,0); //5 delay(de); digitalWrite(L1,0); digitalWrite(L2,0); digitalWrite(L3,0); digitalWrite(L4,1); digitalWrite(L5,0); digitalWrite(L6,0); digitalWrite(L7,0); //4 delay(de); digitalWrite(L1,0); digitalWrite(L2,0); digitalWrite(L3,1); digitalWrite(L4,0); digitalWrite(L5,0); digitalWrite(L6,0); digitalWrite(L7,0); //3 delay(de); digitalWrite(L1,0); digitalWrite(L2,1); digitalWrite(L3,0); digitalWrite(L4,0); digitalWrite(L5,0); digitalWrite(L6,0); digitalWrite(L7,0); //2 delay(de); } if(p==4) { digitalWrite(L1,1); digitalWrite(L2,0); digitalWrite(L3,0); digitalWrite(L4,0); digitalWrite(L5,0); digitalWrite(L6,0); digitalWrite(L7,1); //1,7 delay(de); digitalWrite(L1,0); digitalWrite(L2,1); digitalWrite(L3,0); digitalWrite(L4,0); digitalWrite(L5,0); digitalWrite(L6,1); digitalWrite(L7,0); //2,6 delay(de); digitalWrite(L1,0); digitalWrite(L2,0); digitalWrite(L3,1); digitalWrite(L4,0); digitalWrite(L5,1); digitalWrite(L6,0); digitalWrite(L7,0); //3,5 delay(de); digitalWrite(L1,0); digitalWrite(L2,0); digitalWrite(L3,0); digitalWrite(L4,1); digitalWrite(L5,0); digitalWrite(L6,0); digitalWrite(L7,0); //4 delay(de); } if(p==5) { digitalWrite(L1,0); digitalWrite(L2,0); digitalWrite(L3,0); digitalWrite(L4,1); digitalWrite(L5,0); digitalWrite(L6,0); digitalWrite(L7,0); //4 delay(de); digitalWrite(L1,0); digitalWrite(L2,0); digitalWrite(L3,1); digitalWrite(L4,0); digitalWrite(L5,1); digitalWrite(L6,0); digitalWrite(L7,0); //3,5 delay(de); digitalWrite(L1,0); digitalWrite(L2,1); digitalWrite(L3,0); digitalWrite(L4,0); digitalWrite(L5,0); digitalWrite(L6,1); digitalWrite(L7,0); //2,6 delay(de); digitalWrite(L1,1); digitalWrite(L2,0); digitalWrite(L3,0); digitalWrite(L4,0); digitalWrite(L5,0); digitalWrite(L6,0); digitalWrite(L7,1); //1,7 delay(de); } if(p==6) { digitalWrite(L1,1); delay(de); digitalWrite(L2,1); delay(de); digitalWrite(L3,1); delay(de); digitalWrite(L4,1); delay(de); digitalWrite(L5,1); delay(de); digitalWrite(L6,1); delay(de); digitalWrite(L7,1); //1,7 delay(de); digitalWrite(L7,0); //1,7 delay(de); digitalWrite(L6,0); delay(de); digitalWrite(L5,0); delay(de); digitalWrite(L4,0); delay(de); digitalWrite(L3,0); delay(de); digitalWrite(L2,0); delay(de); digitalWrite(L1,0); delay(de); } if(p==7) { digitalWrite(L1,0); digitalWrite(L2,0); digitalWrite(L3,0); digitalWrite(L4,0); digitalWrite(L5,0); digitalWrite(L6,0); digitalWrite(L7,0); //1,7 p=0; } }