Built-in project · no microcontroller

Hello, breadboard

A switch, a resistor and an LED: the first circuit, with the whole loop in view. There is no microcontroller in it: the simulator solves the 3 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.30. On Mokxi they're free.

The circuit runs here once the page has loaded.

What you'll learn

  • A circuit needs a complete loop
  • What a switch does to that loop
  • Why an LED needs a series resistor
  • LED polarity: anode and cathode
  • Difficulty: Beginner
  • Time: About 10 minutes
  • Parts: 5

How it works

There is no microcontroller and no code here. The simulator solves the circuit directly. The 5 V supply pushes current through the slide switch, then a 220 Ω resistor, then the LED, and back to ground.

Slide the switch so its pole joins the output pin and the loop is closed, so the LED lights. Slide it the other way and the loop is open, so no current flows and the LED is dark.

The resistor keeps the LED safe. An LED holds a nearly fixed voltage, around 1.7 V for a red one, so something else must limit the current. With 220 Ω on 5 V it is about 15 mA, which is bright but safe.

Parts list

5 parts, plus the jumper wires. They retail for about $5.30; on Mokxi they're free.

Kits that can build it

This starter kit has every part in the circuit. Each kit's page lists what else it can build.

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 pinConnects to
Slide switch pin 15 V
LED, red pin CGround
Resistor, 220 Ω pin 1Slide switch pin 2
LED, red pin AResistor, 220 Ω pin 2

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.

sketch.ino
// Hello, breadboard.
//
// There is no microcontroller here. Press Run and the simulator solves the
// circuit itself: the 5 V supply pushes current through the switch, the 220 ohm
// resistor and the LED, and back to ground.
//
// Click the slide switch while it runs. In position 1 the loop is closed and
// the LED lights; in position 3 the pole goes nowhere, the loop is open, and
// the LED is dark.
//
// The resistor is what keeps the LED alive. An LED is a diode: it holds close
// to its forward voltage (about 1.7 V for a red one here) and then takes
// whatever current you give it, so something has to set that current. 220 ohm
// on a 5 V rail gives about 15 mA, which is bright and safe. Change its value
// in the properties panel and watch the LED dim, and watch the drop fall with
// it: a diode's voltage follows its current, which is why 1.7 and not 2.0.

Troubleshooting

The usual mistakes with this circuit, and the fix for each.

  • The LED stays dark with the switch on This project
    Check that the LED's cathode (C) goes to ground and the anode (A) goes to the resistor. Also check the switch is in the position that closes the loop.
  • The LED is dimmer than expected This project
    A bigger resistor means less current. Try the 220 Ω value from the parts list.
  • The input reads random values in one position. Slide switch
    A switch only connects or disconnects. Add a pull-up or pull-down resistor, or use INPUT_PULLUP, so the pin has a defined level when the switch is open.
  • The load never turns on when the switch is flipped. Slide switch
    Use the center (common) leg and one outer leg. The unused outer leg goes nowhere. Check that the switch is in series with the load.
  • 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.
  • A pull-up or pull-down resistor is missing, so the input floats and reads random values. Resistor
    Tie the input to 5 V or ground through about 10k. Or use INPUT_PULLUP and wire the switch to ground.
  • 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.

Change it and keep it

Open it in the editor, change the circuit or the code, and keep your version in a free account.