• If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!


digital input

Page history last edited by Kristin Lucas 15 years, 7 months ago
Program a Push Button
** updated to include correction in diagram 

This program will allow you to turn an LED on and off with a push button. Follow this patch to connect a push button to your Arduino board. Then put an the long lead of an LED in pin 13 of your digital in/out, and the short lead in Ground.


Download the diagram.
 * Button 
 * by DojoDave <http://www.0j0.org> 
 * Turns on and off a light emitting diode(LED) connected to digital   
 * pin 13, when pressing a pushbutton attached to pin 2.  
int ledPin = 13;                // choose the pin for the LED 
int inputPin = 2;               // choose the input pin (for a pushbutton) 
int val = 0;                    // variable for reading the pin status
void setup() { 
  pinMode(ledPin, OUTPUT);      // declare LED as output 
  pinMode(inputPin, INPUT);     // declare pushbutton as input 
void loop(){ 
  val = digitalRead(inputPin);  // read input value 
  if (val == HIGH) {            // check if the input is HIGH 
    digitalWrite(ledPin, LOW);  // turn LED OFF 
  } else { 
    digitalWrite(ledPin, HIGH); // turn LED ON 




Comments (0)

You don't have permission to comment on this page.