reverendfuzzy
Published © GPL3+

Simple ON/OFF Pushbutton

Click on, click off, the project! A simple push on, push off button, that turns an LED on and off with one pushbutton.

BeginnerShowcase (no instructions)1 hour4,745
Simple ON/OFF Pushbutton

Things used in this project

Hardware components

5 mm LED: Red
5 mm LED: Red
Generics are fine
×1
Tactile Switch, Top Actuated
Tactile Switch, Top Actuated
Generics are fine
×1
Resistor 10k ohm
Resistor 10k ohm
1/4 or 1/2 watt, Generics are fine
×1
Resistor 100 ohm
Resistor 100 ohm
1/4 or 1/2 watt, Generics are fine
×1
Breadboard (generic)
Breadboard (generic)
1/4 or 1/2 watt, Generics are fine
×1
Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
Genuine Arduino Uno R3 is recommended. No clones!
×1
Jumper wires (generic)
Jumper wires (generic)
Generics are fine
×1

Software apps and online services

Arduino IDE
Arduino IDE
Can be used on any OS that supports it, but some flavor of Linus is recommended.

Hand tools and fabrication machines

Plier, Needle Nose
Plier, Needle Nose
Helps for plugging component leads into the breadboard. If you're already proficient at this, forget about the pliers.

Story

Read more

Schematics

Breadboard wiring

This is how it is assembled on the breadboard

Schematic

This is the schematic, for the slightly more advanced crowd.

Code

Click on / click off pushbutton - the code

Arduino
Copy/Paste directly into a blank Arduino sketch.
#include <stdio.h>
#include <stdlib.h>

const int button = 8;            // GPIO 8 for the button
const int led =7;                // GPIO 7 for the LED
int ledflag=0;                   // LED status flag

void setup() {
  pinMode(button,INPUT);         // define button as an input 
  pinMode(led,OUTPUT);           // define LED as an output
  digitalWrite(led,LOW);         // turn output off just in case
}

void loop() {
  if (digitalRead(button)==HIGH){ // if button is pressed
    if (ledflag==0) {             // and the status flag is LOW
      ledflag=1;                  // make status flag HIGH
      digitalWrite(led,HIGH);     // and turn on the LED
      }                           // 
    else {                        // otherwise...
      ledflag=0;                  // make status flag LOW
      digitalWrite(led,LOW);      // and turn off the LED
    }
  delay(1000);                    // wait a sec for the 
  }                               // hardware to stabilize
}                                 // begin again 

Credits

reverendfuzzy

reverendfuzzy

1 project • 1 follower
Reverend Fuzzy is an ordained Minister, and has a skills in Electrical Engineering, Chaplaincy, computer repair, and video production.

Comments