Lesson 11: Build the circuit
From pins to parts
- Until now the board put the parts in for you. A real Arduino only has pins. You add the parts with wires on a breadboard.
- In this lesson you build the circuit yourself. The first column of dots is the Arduino's header: each dot is one pin (D13, D2, A0), 5V or GND.
- Pick a part, then tap the gap between two dots to put it there. Tap an LED to turn it round. Pick Remove and tap a part to take it away.
| Part | What it does |
|---|---|
| Wire | joins two dots |
| Resistor | limits the current (tap it to change its value) |
| LED | lights up when current flows from its long leg (the triangle) to its short leg (the bar) |
| Button | joins its two ends while you hold it down |
| LDR | its resistance falls when more light falls on it |
A complete loop
- Current needs a complete loop: from the pin, through the parts, back to GND.
- An LED always needs a resistor in the same loop. A pin gives 5 V and an LED needs only about 2 V. Without a resistor the current is too big and the LED burns out.
- With 220 Ω the current is about (5 − 2) ÷ 235 ≈ 0.013 A = 13 mA. That is bright and safe. A real Arduino pin breaks above 40 mA.
void setup() {
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH); // 5 V on D13: current flows round the loop
delay(500);
digitalWrite(13, LOW); // 0 V: no current, the LED is off
delay(500);
}
- The board shows the current next to each pin while the sketch runs.
Inputs need wires too
- A button between a pin and GND, with
pinMode(2, INPUT_PULLUP): the pin readsHIGHwhen you let go andLOWwhile you press. - An LDR and a fixed resistor make a potential divider. Join them between 5V and GND, and join the middle to A0. Then
analogRead(A0)changes with the light.
Difficulté 2/5 · 140 pièces + un petit bonus lors de la première réussite aujourd'hui
The sketch blinks pin 13. Build the circuit on the breadboard so that an LED blinks safely. Then press Check.
Cliquez sur Exécuter pour voir le résultat ici.
Difficulté 3/5 · 200 pièces + un petit bonus lors de la première réussite aujourd'hui
Wire an LED (with a resistor) to pin 13 and a button from pin 2 to GND. Then finish the sketch: the LED is on only while the button is pressed.
Cliquez sur Exécuter pour voir le résultat ici.
Difficulté 4/5 · 280 pièces + un petit bonus lors de la première réussite aujourd'hui
Build a night light. Make a divider: LDR from 5V to A0, and a 10 kΩ resistor from A0 to GND. Put an LED with a resistor on pin 9. Then write the sketch: the LED is on when analogRead(A0) is below 300 (dark).
Cliquez sur Exécuter pour voir le résultat ici.