PUSH SWITCH
This project is use to turn on/off leds using Push Button with arduino.
FOR VIDEO : CLICK HERE
THINGS NEEDED
- Arduino UNO R3
- Push Button
- 10 K (For pull down for INPUT in Push Button)
- 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); }
Comments
Post a Comment