Blink and press
A pushbutton and a 2 Hz clock, no processor in sight. There is no microcontroller in it: the simulator solves the 6 parts as a circuit, so it runs the moment you press Run, and nothing needs compiling.
Teaching? Assign it to your class in one click.
Beginner About 10 minutes to build and run. Runs in your browser. Free, and no account needed.
The parts retail for about $5.40. On Mokxi they're free.
What you'll learn
- A complete loop from power to ground
- Why an LED needs a series resistor
- How a pushbutton opens and closes a path
- Using a clock part to blink without code
- LED polarity: anode toward power, cathode toward ground
- Difficulty: Beginner
- Time: About 10 minutes
- Parts: 8
How it works
This circuit has no microcontroller, so nothing runs code. Two LEDs sit on two separate paths, each with its own 220 ohm resistor to ground. The resistors keep the current low enough that the LEDs are safe.
The red LED is fed from the 5 V supply through the pushbutton. Press and hold the button and the path is complete, so the red LED lights. Let go and it turns off.
The green LED is fed by a Clock part instead of a supply. The clock output switches between high and low 2 times a second, so the green LED blinks on its own at 2 Hz.
Parts list
8 parts, plus the jumper wires. They retail for about $5.40; on Mokxi they're free.
- 1 × Full-size breadboard
- 1 × Power, 5 V
- 1 × PushbuttonIn Starter Kit, Christmas Lights Kit, Logic Lab Kit.
- 1 × LED, redIn Starter Kit, Halloween Prop Kit, Logic Lab Kit.
- 2 × Resistor, 220 ΩIn Starter Kit, Claw Machine Kit, Halloween Prop Kit.
- 1 × ClockIn Logic Lab Kit.
- 1 × LED, greenIn Starter Kit, Halloween Prop Kit, Logic Lab Kit.
Wiring table
Every connection, pin by pin, read from the circuit itself. Each row joins the pin on the left to the pin on the right, by a jumper wire or a breadboard strip.
| Part and pin | Connects to |
|---|---|
| Pushbutton pin 1a | 5 V |
| Resistor, 220 Ω (1) pin 2 | Ground |
| Resistor, 220 Ω (2) pin 2 | Ground |
| LED, red pin A | Pushbutton pin 2b |
| Resistor, 220 Ω (1) pin 1 | LED, red pin C |
| LED, green pin A | Clock pin OUT |
| Resistor, 220 Ω (2) pin 1 | LED, green pin C |
The notes that come with it
There is no microcontroller in this one, so nothing is compiled: the simulator solves the circuit itself. The file in the editor is the notes that come with it.
// Mokxi.
// This circuit has no board, so Run simulates the parts only.
// Add a board and pick a program in its Firmware panel: the editor then shows
// that program's source, and Run builds what you type here for that board.
void setup() {
pinMode(13, OUTPUT);
Serial.begin(115200);
}
void loop() {
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(500);
}
Code walkthrough
The key functions of the sketch, and what each one does.
setup sketch.ino
Runs once when the board starts. It gets the pins and libraries ready.
void setup() {
pinMode(13, OUTPUT);
Serial.begin(115200);
}loop sketch.ino
Runs over and over for as long as the board has power. This is where the project does its work.
void loop() {
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(500);
}Troubleshooting
The usual mistakes with this circuit, and the fix for each.
- The red LED never lights when you press the button This project
Check that the LED is the right way around, with the anode (A) on the button side and the cathode (C) toward the resistor. - The green LED stays dark or stays on This project
Make sure the Clock OUT pin goes to the green LED anode, and that the green cathode returns to ground through its resistor. - Both LEDs look very bright or one burns out This project
Each LED needs its own 220 ohm resistor on the ground side. Do not skip one. - The input reads random HIGH and LOW when the button is not pressed. Pushbutton
A floating pin picks up noise. Add a 10 k pull-down or pull-up resistor, or use INPUT_PULLUP and wire the button between the pin and GND. Then pressed reads LOW. - The button seems always pressed, or never changes. Pushbutton
A 4-leg tactile switch has legs joined in pairs. Place it across the breadboard center gap so the pairs sit on different rows. Wired along one side, the legs are already connected. - The LED does not light, or it lights once and then dies. LED
LEDs have polarity. The longer leg (anode) goes toward the positive side. Always add a series resistor, about 220 ohms to 1 k ohm on a 5 V pin. - A blue or white LED stays dark on 3.3 V. LED
Blue and white LEDs drop about 3 V, so 3.3 V leaves almost nothing for the resistor. Use a 5 V supply, or a smaller resistor and a red or green LED. - The LED is dim, burns out, or the pin reads wrong because the resistor value is off. Resistor
Read the color bands again. A 220 ohm to 330 ohm resistor suits a typical LED on 5 V. 10k is a common pull-up or pull-down value. Check with a multimeter if unsure.
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.