Lesson 11: Build the circuit
此页面需较新浏览器(支持 SharedArrayBuffer)。请升级 Chrome、Edge、Firefox 或 Safari 至最新版本。
English
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 |
English
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.
English
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.
难度 2/5 · 今日首次完成可获 140 金币及少量额外奖励
The sketch blinks pin 13. Build the circuit on the breadboard so that an LED blinks safely. Then press Check.
点击“运行”查看此处输出。
难度 3/5 · 今日首次完成可获 200 金币及少量额外奖励
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.
点击“运行”查看此处输出。
难度 4/5 · 今日首次完成可获 280 金币及少量额外奖励
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).
点击“运行”查看此处输出。