使用 LDR 测量光线
连接分压器以读取亮度
使用 LDR 测量光线 是 CoddyKit 上的免费 Arduino & IoT Academy 课时。 这是第 2 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Arduino & IoT Academy 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Arduino & IoT Academy 课程共包含 4 节课。
本课时的部分内容尚未翻译,以英文显示。
What an LDR Is
An LDR is a light-dependent resistor. Its resistance drops in bright light and climbs high in the dark.
Resistance Tracks Light
Cover an LDR and its resistance soars; shine a lamp on it and resistance falls. That change is what you measure.
It Cannot Be Read Alone
The Arduino reads voltage, not resistance. So an LDR by itself gives no voltage the board can sense directly.
Pair It With a Resistor
Combine the LDR with a fixed resistor to form a voltage divider. Together they turn light into a readable voltage.
Pick a 10k Partner
A 10k ohm resistor is a solid default partner for most LDRs. It keeps your readings spread across a useful range.
Tap the Middle Point
Connect the junction between the LDR and the resistor to an analog pin like A0. That midpoint voltage is your signal.
Read the Brightness
Call analogRead on the divider pin to get a 0 to 1023 number that rises and falls with the light.
int light = analogRead(A0);Wiring Sets Direction
Which side the LDR sits on decides whether bright gives a high or low number. Test it and note your result.
Watch It Live
Print the value so you can wave your hand over the sensor and see the number react with Serial.println.
Serial.println(analogRead(A0));Smooth Out Flicker
Lights flicker faster than your eye sees. Averaging a few readings gives a steadier brightness value.
A Cheap, Useful Sensor
The LDR is a cheap way to add light awareness. It powers night lights, plant monitors, and auto-dimming displays.
Quick Check
Why cant an LDR connect to an analog pin on its own?
Recap: Reading Light
You built an LDR voltage divider with a 10k resistor, tapped the midpoint to A0, and read brightness with analogRead.
常见问题解答
「使用 LDR 测量光线」课时是免费的吗?
是的 — 「使用 LDR 测量光线」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Arduino & IoT Academy 课程的其余内容,请升级到 CoddyKit PRO。 Arduino & IoT Academy 课程共包含 4 节课。
「使用 LDR 测量光线」这节课中我会学到什么?
连接分压器以读取亮度 你通过在浏览器中直接运行的动手代码来练习 Arduino & IoT Academy,全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 Arduino & IoT Academy 需要有经验吗?
无需任何先前经验。CoddyKit 上的 Arduino & IoT Academy 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 2 节课,共 4 节。
「使用 LDR 测量光线」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 Arduino & IoT Academy 课中编写并运行代码吗?
能。每节 Arduino & IoT Academy 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。
此课程中的所有课时
- 读取 PIR 运动传感器
- 使用 LDR 测量光线
- 设置光线阈值
- 自动夜灯