自動ナイトライト
暗くなって動きを検出したらLEDを点灯します。
「自動ナイトライト」はCoddyKit上の無料Arduino & IoT Academyレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはArduino & IoT Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Arduino & IoT Academyコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
The Project Goal
Now combine your skills into one device: an automatic night light that switches an LED on when it is dark and someone moves.
Two Inputs, One Output
You will read two inputs, the LDR for light and the PIR for motion, then drive one output: an LED.
Plan the Pins
Assign each part a pin: the LDR on an analog input, the PIR on a digital input, and the LED on a digital output.
Set Up the LED
In setup, mark the LED pin as an OUTPUT so the board can drive current to it on command.
pinMode(ledPin, OUTPUT);Read Both Sensors
Each loop, grab a fresh light value and the current motion state so your decision uses up-to-date data.
int light = analogRead(A0);
int motion = digitalRead(pirPin);Combine With AND
The light should turn on only when it is dark and motion is present. Use && to require both at once.
if (light < threshold && motion == HIGH)Turn the LED On
When both conditions hold, drive the LED pin HIGH to light it up for whoever just walked in.
digitalWrite(ledPin, HIGH);Turn the LED Off
Otherwise, set the pin LOW so the light goes dark again when motion stops or the room is bright.
digitalWrite(ledPin, LOW);Keep It Lit Briefly
People dislike a light that snaps off instantly. Add a short hold time so it stays on a while after the last motion.
Skip Daytime Triggers
The light check matters: requiring dark means daytime motion is ignored, saving power and avoiding pointless blinks.
Make It Real
Swap the LED for a relay and you can switch a real lamp. Same logic, bigger impact in your hallway.
Quick Check
What condition turns the night light on?
Recap: Your Night Light
You merged an LDR, a PIR, and an LED, using a threshold and && so the light glows only in the dark with motion.
よくある質問
「自動ナイトライト」レッスンは無料ですか?
はい。「自動ナイトライト」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Arduino & IoT Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Arduino & IoT Academyコースには全4レッスンが含まれています。
「自動ナイトライト」で何を学びますか?
暗くなって動きを検出したらLEDを点灯します。 ブラウザで直接実行するハンズオンコードでArduino & IoT Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Arduino & IoT Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのArduino & IoT Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。
「自動ナイトライト」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このArduino & IoT Academyレッスンでコードを書いて実行できますか?
はい。すべてのArduino & IoT Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。