TINKER PiEDESIGN IN INDIA

Button controls an LEDTinkerPieCircuit tutorial 9 of 24 · Beginner · 10 minutes

Read a push button with INPUT_PULLUP and light an LED only while it is pressed.

Open this circuit in TinkerPieCircuit (free, runs in your browser)

What you will learn

Parts

TinkerPie V1 board1 push button1 LED1 resistor, 220 Ω

Steps

  1. Build the LED

    Wire S1 → resistor → LED (+), and LED (−) → GND, just like the Blink tutorial.

  2. Add the button

    Click Push button. Wire one side to pin P10 and the other side to GND.

  3. Use the pull-up

    pinMode(P10, INPUT_PULLUP) keeps the pin at HIGH (3.3 V) until the button joins it to GND. A pressed button therefore reads LOW.

  4. Write the decision

    In loop(), if (digitalRead(P10) == LOW) turn the LED on, otherwise turn it off.

  5. Try it

    Press ▶ Start, then press and hold the red cap of the button with your mouse or finger.

The code

function setup() {
  pinMode(P10, INPUT_PULLUP);
  pinMode(S1, OUTPUT);
}

function loop() {
  if (digitalRead(P10) == LOW) {
    digitalWrite(S1, HIGH);
  } else {
    digitalWrite(S1, LOW);
  }
}

Copy this into the Code tab. It is Arduino-style JavaScript. The real board uses the same pin names (S1, P10…) in TinkerPie Studio.

How it works

The board has a small resistor inside that pulls the pin up to 3.3 V. Pressing the button connects the pin to GND (0 V), so the program sees LOW.

Challenge: Make the LED stay on for 2 seconds after the button is pressed (hint: use delay).

← Blink an LED · All 24 circuit tutorials · Dim an LED with a knob →