Day 2: The Button Chronicles

The Button Chronicles – Day 2

Lesson Image


To learn the basics of using a button in a circuit and successfully connect a button to the HERO R3 and use it to control an LED.


  • HERO board
  • Button
  • LED
  • Breadboard or circuit board
  • Jumper wires


Step 1: Connect the button to the HERO board.

Insert one end of a jumper wire into the button pin on the HERO board and the other end into the button.

Step 2: Connect the LED to the HERO board.

Insert one end of a jumper wire into the LED pin on the HERO board

and the other end into the LED.

Step 3: Write the code.

Step 4: Upload and test the code.

Upload the code to the HERO board and press the button to see if the LED turns on and off.

Pushbutton and LED

const int buttonPin = 2;  // the number of the pushbutton pin
const int ledPin = 13;    // the number of the LED pin

int buttonState = 0;      // variable for reading the pushbutton status

void setup() {
  pinMode(ledPin, OUTPUT);      // initialize the LED pin as an output
  pinMode(buttonPin, INPUT);    // initialize the pushbutton pin as an input

void loop() {
  buttonState = digitalRead(buttonPin);  // read the state of the pushbutton value

  if (buttonState == HIGH) {             // check if the pushbutton is pressed
    digitalWrite(ledPin, HIGH);  // turn LED on
  } else {
    digitalWrite(ledPin, LOW);   // turn LED off


Discuss the following points:

  • The importance of using a button in a circuit
  • The role of the code in controlling the LED
  • Any observations or questions you have


Recap and Summary.

Astrid: We did it, Gear! I feel so accomplished. We made the LED blink and now control it with a button.

Gear: You did a fantastic job, Astrid. Today, you learned how to use a button to control an LED. This skill is essential as you continue your journey into the world of electronics and coding.

Hook into the Next Day:

Astrid and Gear say…

Gear: Astrid, we’re making great progress. Tomorrow, we’ll learn how to work with multiple LEDs. This will allow us to create more complex and exciting projects.

Astrid: I can’t wait, Gear! Let’s keep this adventure going!

Post a comment

Leave a Comment

Your email address will not be published. Required fields are marked *