Skip to main content

PUSH SWITCH (ARDUINO)

 PUSH SWITCH

This project is use to turn on/off leds using Push Button with arduino.
FOR VIDEO : CLICK HERE

THINGS NEEDED

  1. Arduino UNO R3
  2. Push Button
  3. 10 K (For pull down for INPUT in Push Button)
  4. 1K (For Leds)

CIRCUIT DIAGRAM

WIRING

PUSH BUTTON TO ARDUINO

  • Connect one pin of Push Button to GND using 10K resistor & Another pin of push button to VCC.
  • Similarly, Connect all push buttons.
  • Now, Connect Pin 2, 3, 4 & 5 of arduino to all push button where the 10K resistor connect to push button pins simultaneously.

LEDS TO ARDUINO

  • Connect Led1 to pin 11 of arduino.
  • Connect Led2 to pin 10 of arduino.
  • Connect Led3 to pin  9  of arduino.
  • Connect Led4 to pin  8  of arduino.

CODE

//4 Push switch
//scientist BENIELS LAB 

const int pushButton[] ={2,3,4,5};// define push button inputs
const int ledpin[]={11,10,9,8};// output pins where 4 led will be connected
String ledNames[] ={"led1", "led2","led3","led4"};// Just put name for 4 leds
int pushed[] ={0,0,0,0};// status of each buttons
int ledStatus[] ={LOW,LOW,LOW,LOW};// initial status of led


void setup() {
  
  Serial.begin(9600);// starting the serial monitor 
  for(int i=0; i<4; i++)
  {
    pinMode(pushButton[i], INPUT_PULLUP); 
    pinMode(ledpin[i], OUTPUT);   
    digitalWrite(ledpin[i], LOW);// initial relay status to be OFF
  }


}

void loop() {


  for(int i=0; i<4; i++)
  {
     int  val = digitalRead(pushButton[i]);   
    if(val == HIGH && ledStatus[i] == LOW){
  
      pushed[i] = 1-pushed[i];
      delay(100);
    }   

  ledStatus[i] = val;

      if(pushed[i] == HIGH){
        Serial.print(ledNames[i]);
        Serial.println(" ON");
        digitalWrite(ledpin[i], LOW); 
       
      }else{
        Serial.print(ledNames[i]);
        Serial.println(" OFF");
        digitalWrite(ledpin[i], HIGH);
   
      }  
 
  } 
    Serial.println("=="); 
  delay(100);

}

SUBSCRIBE TO "scientist BENIEL'S LAB" IN YOUTUBE FOR MORE ELECTRONIC'S & ROBOTIC'S PROJECTS.
THANK YOU


Comments

Popular posts from this blog

Arduno Clock

  Arduino Clock This is a clock using RTC Tiny with Arduino. Using this we can see time & date.  FOR VIDEO :

MQ-5 GAS LEAK DETECTOR

  MQ-5 GAS LEAK DETECTOR  This project is used to detect the gas leak and alert us that the gas is leaking. You can use it for your science projects. FOR VIDEO :

Blutooth Switch (Arduino)

 BLUTOOTH SWITCH (ARDUINO) Hi, Using this we can control leds using Smart Phone via Blutooth. We can also control home appliances using Relay with it. For Video :  CLICK HERE  .