//Set up the state of the button as "0" and the button pin as 7 #define buttonPin 7 int state = 0; void setup() { //Set up the button pin as an input device pinMode(buttonPin, INPUT); //Begin Serial communication at 9600 baud Serial.begin(9600); } void loop() { //Read the state (pressed/not pressed) of the button state = digitalRead(buttonPin); //Check whether the Serial connection is available to send data if (Serial.available() > 0){ //Write the state of the button to the connection Serial.write(state); //Print the state to the Serial monitor for debugging Serial.println(state); } }