Detect switch on digitalread

  1. const int buttonPin = 3;
  2. int buttonState = 0;    
  3.  
  4. void setup() {
  5.   Serial.begin(9600);  
  6.   pinMode(buttonPin, INPUT);    
  7. }
  8.  
  9. void loop(){
  10.   buttonState = digitalRead(buttonPin);
  11.   Serial.println(buttonState);
  12. }