Back to Arduino Step By Step Course

Lesson 98: Arduino 10 LED Push button Projects, Potentiometer LED Voltmeter and Traffic Light

If you don't like to see ads while video is being played you can purchase this course for $200 from Udemy or purchase YouTube premium Here

Lesson 98: Arduino 10 LED Push button Projects, Potentiometer LED Voltmeter and Traffic Light

Please select other codes for this lecture from the links below.

Part 1: Introduction

In this lesson we learn how to use LED and Push button in this 10 LED projects. Wiring diagram is shown, code is fully explained and demonstrated with multiple change of settings for each project. We read potentiometer's voltage and display voltage by turning each LED on to represent voltages. A Simple traffic light project.
This code is part of video lecture. This project 8 code. This code allows you to control 5 LEDS using push button switch. With every push the next LED will turn ON and the previous will turn OFF.


 
/*
 * Arduino Step by Step Course by Robojax
 * Lesson 98  https://robojax.com/course1/?vid=lecture98
 * Project 8 of 10
 * 
 * Walking Light with Push buttons
 * This code allows you to control 5 LEDS using push button switch. With every push the next LED will turn ON 
 * and the previous will turn OFF.
 * 
 * Watch full details and demonstraiton: https://youtu.be/OSwleCBlkuI
 * 
 * Start a full Arduino Step By Step course:  https://youtu.be/-6qSrDUA5a8
 * 
 ****** 10 Projects explained in this video
 * 1-LED ON OFF 
 * 2-LED ON/OFF with push button
 * 3-LED ON/OFF toggle with push button
 * 4-Fading light of LED
 * 5-Fading light of LED using push button
 * 6-See Saw with LED
 * 7-Walking Light
 * 8-Walking light with push button
 * 9-LED voltage level meter
 * 10- Arduino Traffic Light
 * 
 * 
 * What pars we need:
 * -Of course Arduino board (UNO , Nano, Mega or any)
 * -Push button switch 
 * -LED eitehr 5mm or 3mm
 * -200ohm to 1000 ohrm resistor for LED
 * -Some dupont wires to connec 
 * -If don't want to solder, then use breadboard
This video is part of Arduino Step by Step Course which starts here: https://youtu.be/-6qSrDUA5a8

  * written by Ahmad Shamshiri on Jan 30, 2022
 * in Ajax, Ontario, Canada
 * www.Robojax.com

If you found this tutorial helpful, please support me so I can continue creating 
content like this. Make a donation using PayPal by credit card https://bit.ly/donate-robojax
  
 * This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.* 
 * This code has been download from Robojax.com
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.

 * 
 */
const int pushButtonPin = 2;//define a pin number for push button
const int LED1 = 3;
const int LED2 = 4;
const int LED3 = 5;
const int LED4 = 6;
const int LED5 = 7;

int LED_ON = LED1;




boolean pushButtonState = false;
//the code inside setup() runs once.

void setup() {
  Serial.begin(9600);
  Serial.println("Walking LED with Push button");
  pinMode(pushButtonPin, INPUT_PULLUP);//define a pin for push button switch
   
  pinMode(LED1, OUTPUT);//set LED1 pin as output
  pinMode(LED2, OUTPUT);//set LED2 pin as output
  pinMode(LED3, OUTPUT);//set LED3 pin as output
  pinMode(LED4, OUTPUT);//set LED4 pin as output
  pinMode(LED5, OUTPUT);//set LED4 pin as output  
}//setup end

void loop() {

   // Serial.print(" LED: ");
    //Serial.println(LED_ON);  
  int switchPushed= digitalRead(pushButtonPin);//read state of push button

  if (switchPushed == LOW)
  {
    pushButtonState = 1 - pushButtonState;   
    Serial.print("State: ");
    Serial.print(pushButtonState);
    Serial.print(" LED: ");
    Serial.println(LED_ON);
    delay(200);
    
      if(LED_ON == LED1)
      {
        LED_ON = LED2;
        digitalWrite(LED1, HIGH);    
        digitalWrite(LED2, LOW);
        digitalWrite(LED3, LOW);    
        digitalWrite(LED4, LOW);  
        digitalWrite(LED5, LOW);          
      }else if(LED_ON == LED2)
      {
        LED_ON = LED3;  
        digitalWrite(LED1, LOW);    
        digitalWrite(LED2, HIGH);
        digitalWrite(LED3, LOW);    
        digitalWrite(LED4, LOW); 
        digitalWrite(LED5, LOW);             
      }else if(LED_ON == LED3)
      {
        LED_ON = LED4;
        digitalWrite(LED1, LOW);    
        digitalWrite(LED2, LOW);
        digitalWrite(LED3, HIGH);    
        digitalWrite(LED4, LOW); 
        digitalWrite(LED5, LOW);     
      }else if(LED_ON == LED4)
      {
        LED_ON = LED5;
        digitalWrite(LED1, LOW);    
        digitalWrite(LED2, LOW);
        digitalWrite(LED3, LOW);    
        digitalWrite(LED4, HIGH); 
        digitalWrite(LED5, LOW);     
      }else
      {
        LED_ON = LED1;
        digitalWrite(LED1, LOW);    
        digitalWrite(LED2, LOW);
        digitalWrite(LED3, LOW);    
        digitalWrite(LED4, LOW); 
        digitalWrite(LED5, HIGH);     
      }
  }
  // Watch full details and demonstraiton: https://youtu.be/7xTHaFdCyaI
 }//loop end
 
   

The least I expect from you is to thumb up the video and subscribe to my channel. I appriciate that. .I have spent months making these lectures and writing code. You don't lose anything by subscribging to my channel. Your subscription is stamp of approval to my videos and more people can find them and in it turn it helps me. Thank you

If you found this tutorial helpful, please support me so I can continue creating content like this. support me via PayPal

**** AFFILIATE PROGRAM **** We are a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for us to earn fees by linking to Amazon.com and affiliated sites.