In Arduino IDE: Tools → Board → Arduino AVR Boards → Arduino Mega or Mega 2560. If it offers to install “Arduino AVR Boards”, click Install.
4
在 Arduino IDE 里:Tools → Board → Arduino AVR Boards → Arduino Mega or Mega 2560。如果它提示要安装 “Arduino AVR Boards”,就点 Install(安装)。
5
Tools → Port → pick the port that appeared (something like COM3).
5
Tools → Port → 选刚刚出现的那个端口(类似 COM3)。
🛠️ No COM port showing up?
🛠️ 没有出现 COM 端口?
Most ELEGOO boards use a chip called CH340 that Windows needs a small driver for. Find the CH340 driver in your kit's download folder (or search “CH340 driver Windows”), install it, then unplug and replug the board and check Tools → Port again.大多数 ELEGOO 开发板用的是一颗叫 CH340 的芯片,Windows 需要一个小驱动才能认出它。在套件的下载文件夹里找到 CH340 驱动(或者搜索 “CH340 driver Windows”),装好它,然后拔下再插上开发板,再去看一下 Tools → Port。
1
Make the Light Blink
让小灯闪烁
★Your first program你的第一个程序
🎯 Upload your very first program and make the tiny built-in light blink — then make it blink your way.
🎯 上传你的第一个程序,让板载小灯闪起来 —— 然后再让它按你的方式闪。
Parts Needed
所需材料
🔌 Mega2560 + USB cable🔌 Mega2560 + USB 线✨ That's it!✨ 就这些!
Wiring
接线
No wiring needed — the Mega2560 has a small LED built in, already wired to pin 13.
不需要接线 —— Mega2560 自带一个小 LED,已经连到 引脚 13 上了。
The Code
程序代码
// Experiment 1 — Blink
// Pin 13 has a tiny LED soldered onto the board.
void setup() {
pinMode(LED_BUILTIN, OUTPUT); // get pin 13 ready to send power
}
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // LED ON (HIGH = 5 volts)
delay(1000); // wait 1000 ms = 1 second
digitalWrite(LED_BUILTIN, LOW); // LED OFF (LOW = 0 volts)
delay(1000); // wait 1 second
}
1
In Arduino IDE, delete anything in the editor and type (or paste) the code above.
1
在 Arduino IDE 里,删掉编辑器里原有的内容,把上面的代码打上去(或粘贴进去)。
2
Click the round → Upload button (top-left). Wait for “Done uploading.”
Watch the board — the little LED blinks on for 1 second, off for 1 second. 🎉
3
看着开发板 —— 小 LED 会亮 1 秒、灭 1 秒地闪起来。🎉
🔬 How it works
🔬 原理
setup() runs once when the board powers on. loop() runs over and over forever. digitalWrite turns a pin ON (HIGH) or OFF (LOW), and delay pauses in milliseconds (1000 = one second).setup() 在开发板通电时只运行一次。loop() 会一遍又一遍地永远重复。digitalWrite 把一个引脚打开(HIGH)或关闭(LOW),delay 则按毫秒暂停(1000 = 一秒)。
🧪 Try this
🧪 想一想
Change both 1000s to 200 and upload again — fast blink! Then make an SOS signal: 3 quick blinks, 3 slow blinks, 3 quick blinks.把两个 1000 都改成 200 再上传一次 —— 快速闪烁!然后做一个 SOS 信号:闪 3 下快的、3 下慢的、再 3 下快的。
2
A Button Switch
按钮开关
★★Input + Output输入 + 输出
🎯 Wire up a real LED and a push button. Press the button → light ON. Let go → light OFF.
🎯 接上一个真正的 LED 和一个按钮。按下按钮 → 灯亮。松手 → 灯灭。
Parts Needed
所需材料
🍞 Breadboard🍞 面包板💡 LED × 1💡 LED × 1🟫 220Ω resistor (red-red-brown)🟫 220Ω 电阻(红-红-棕)🔘 Push button🔘 按钮🔗 Jumper wires🔗 跳线
Wiring
接线
🍞 Show realistic breadboard layout (Fritzing-style)🍞 显示真实面包板接线图(Fritzing 风格)
Holes in the same column (within one half) are joined inside the board. The button bridges the center gap; both green jumpers go to the blue (−) GND rail.
LED: Pin 8 → 220Ω resistor → LED long leg (+); LED short leg (−) → GND. Button: one leg → Pin 2; the leg diagonally across → GND.LED:引脚 8 → 220Ω 电阻 → LED 长腿(+);LED 短腿(−) → GND。 按钮:一只脚 → 引脚 2;斜对角的那只脚 → GND。
The Code
程序代码
// Experiment 2 — Button switch
const int buttonPin = 2; // the push button
const int ledPin = 8; // the LED
void setup() {
pinMode(buttonPin, INPUT_PULLUP); // built-in resistor; pressed = LOW
pinMode(ledPin, OUTPUT);
}
void loop() {
if (digitalRead(buttonPin) == LOW) { // button is pressed
digitalWrite(ledPin, HIGH); // light ON
} else {
digitalWrite(ledPin, LOW); // light OFF
}
}
🔬 How it works
🔬 原理
digitalReadchecks a pin instead of powering it. INPUT_PULLUP uses a resistor inside the chip so the pin reads HIGH normally, and LOW when you press the button (which connects it to GND). The if / else makes a decision every loop.digitalRead 是去读取一个引脚,而不是给它供电。INPUT_PULLUP 用了芯片内部的一个电阻,所以引脚平时读出来是 HIGH,按下按钮(把它连到 GND)时就变成 LOW。if / else 会在每一轮循环里做一次判断。
🧪 Try this
🧪 想一想
Turn it into a toggle: press once to turn on, press again to turn off. (Hint: you'll need a variable that remembers if the light is on, and you only flip it the moment the button is first pressed.)把它改成一个开关切换:按一下打开,再按一下关掉。(提示:你需要一个变量来记住灯现在是不是亮的,而且只在按钮“刚被按下的那一刻”去翻转它。)
3
Breathing Light
呼吸灯
★★★PWM & loopsPWM 与循环
🎯 Make the LED smoothly fade brighter and dimmer, like it's slowly breathing.
🎯 让 LED 平滑地由亮变暗、由暗变亮,就像它在慢慢呼吸一样。
Parts Needed
所需材料
🍞 Breadboard🍞 面包板💡 LED × 1💡 LED × 1🟫 220Ω resistor🟫 220Ω 电阻🔗 Jumper wires🔗 跳线
Wiring
接线
🍞 Show realistic breadboard layout (Fritzing-style)🍞 显示真实面包板接线图(Fritzing 风格)
Same single LED branch as Experiment 2 — just move the orange wire to Pin 9 (~) so it can fade. The green jumper goes to the blue (−) GND rail.
Same as before, but the LED's resistor now connects to Pin 9 (a pin with a ~ next to it). LED short leg (−) → GND.和之前一样,只是 LED 的电阻现在接到 引脚 9(旁边带 ~ 符号的那种引脚)。LED 短腿(−)→ GND。
The Code
程序代码
// Experiment 3 — Breathing light (PWM)
const int ledPin = 9; // pin 9 has a "~" (can fade)
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
// fade up: 0 (off) to 255 (full brightness)
for (int b = 0; b <= 255; b++) {
analogWrite(ledPin, b);
delay(6);
}
// fade down: 255 back to 0
for (int b = 255; b >= 0; b--) {
analogWrite(ledPin, b);
delay(6);
}
}
🔬 How it works
🔬 原理
analogWrite uses a trick called PWM: it flicks the pin on and off super fast, so the LED looks dimmer or brighter — any value from 0 to 255. A for loop counts for you, so you don't write 256 separate lines.analogWrite 用了一个叫 PWM 的小窍门:它把引脚超快地开开关关,让 LED 看起来更暗或更亮 —— 取值可以是 0 到 255 之间任意一个数。for 循环会帮你数数,这样你就不用写 256 行了。
🧪 Try this
🧪 想一想
Make the delay(6) bigger for slow, sleepy breathing or smaller for fast. Bonus: add a second LED on another ~ pin that fades the opposite way.把 delay(6) 改大,呼吸就变得慢悠悠、懒洋洋;改小就变快。进阶挑战:在另一个 ~ 引脚上再加一个 LED,让它按相反的方向渐变。
4
Smart Night Light
聪明的夜灯
★★★★Sensors & Serial Monitor传感器与串口监视器
🎯 Use a light sensor so the LED brightens when the room gets dark and dims when it's bright — all by itself. Then watch the numbers live on screen.
🎯 用一个光敏电阻,让 LED 在房间变暗时自动变亮、变亮时自动变暗 —— 全靠它自己。然后在屏幕上实时看这些数字。
🍞 Show realistic breadboard layout (Fritzing-style)🍞 显示真实面包板接线图(Fritzing 风格)
Left = the light-sensor divider (5V → LDR → node → 10kΩ → GND), with A0 reading the node. Right = the same LED branch as before on Pin 9 (~). Green jumpers and the black wire all meet at the blue (−) GND rail.
Sensor: 5V → photoresistor → row we'll call “middle”; from “middle” → 10kΩ resistor → GND; and a wire from “middle” → A0. LED: Pin 9 → 220Ω → LED long leg (+); LED short leg (−) → GND.传感器:5V → 光敏电阻 → 我们叫它“中间”的那一行;从“中间” → 10kΩ 电阻 → GND;再从“中间”引一根线 → A0。 LED:引脚 9 → 220Ω → LED 长腿(+);LED 短腿(−)→ GND。
The Code
程序代码
// Experiment 4 — Smart night light
const int sensorPin = A0; // the light sensor
const int ledPin = 9; // LED on a "~" pin
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600); // open a line to the computer
}
void loop() {
int light = analogRead(sensorPin); // 0 = dark ... 1023 = bright
int brightness = map(light, 0, 1023, 255, 0); // darker -> brighter LED
analogWrite(ledPin, brightness);
Serial.println(light); // print the reading
delay(50);
}
1
Upload the code, then open Tools → Serial Monitor and set it to 9600 baud (bottom-right).
1
上传代码,然后打开 Tools → Serial Monitor(串口监视器),把它设成 9600 baud(波特率)(在右下角)。
2
Cover the sensor with your hand — the number drops and the LED gets brighter.
2
用手盖住传感器 —— 数字会变小,LED 会变得更亮。
3
Shine a phone light on it — the number rises and the LED dims.
3
用手机的灯照它 —— 数字会变大,LED 会变暗。
🔬 How it works
🔬 原理
analogRead turns the sensor's voltage into a number from 0 to 1023. map rescales one range to another (here, flipping it so dark = bright LED). Serial.println sends data back to the computer so you can see what the board senses.analogRead 把传感器的电压变成一个 0 到 1023 之间的数字。map 把一个范围重新缩放到另一个范围(这里是把它翻转过来,让“暗 = LED 亮”)。Serial.println 把数据传回电脑,这样你就能看到开发板感知到了什么。
🧪 Try this
🧪 想一想
Watch your room's numbers, pick a “dark” value, then add an if so the LED only switches on below that number — a real automatic night light that ignores small changes.观察一下你房间里的数字,挑一个代表“暗”的数值,然后加一个 if,让 LED 只在数字低于这个值时才点亮 —— 一盏真正的、能忽略小变化的自动夜灯。
⚠️ Lab Rules
⚠️ 安全须知
Always put a resistor in line with an LED — a bare LED on 5V can burn out.
Build and rewire with the USB unplugged; plug it in only when you're ready to test.
Never connect 5V straight to GND — that's a short circuit.
LED legs: the long leg is + (anode); the short leg / flat side is − (cathode).
Push pins and wires in gently, and keep drinks away from the breadboard.
一定要给 LED 串一个电阻 —— 裸接 5V 的 LED 会被烧坏。
搭电路、改接线时要拔掉 USB;只在准备测试时才插上。
千万不要把 5V 直接连到 GND —— 那是短路。
LED 的腿:长腿是 +(正极);短腿 / 有平边的那侧是 −(负极)。
插引脚和跳线时要轻一点,别把饮料放在面包板旁边。
🏆 My Progress
🏆 我的进度
#
Experiment
Level
Done?
#
实验
难度
完成?
0
Get Set Up
—
0
准备工作
—
1
Make the Light Blink
★
1
让小灯闪烁
★
2
A Button Switch
★★
2
按钮开关
★★
3
Breathing Light
★★★
3
呼吸灯
★★★
4
Smart Night Light
★★★★
4
聪明的夜灯
★★★★
Print this page and tick a box each time you finish. Keep tinkering! 🔧