Design an automatic night light.
This is not a copy-the-code exercise. We will take a simple customer brief and work through it like an engineering design task: requirements, inputs and outputs, system plan, circuit, breadboard build, pseudocode, Arduino code and a test plan.
The customer brief
Design a small automatic night light for a corridor. The lamp should stay off when the room is bright, turn on when it becomes dark, and become brighter as the light level falls. The user must be able to adjust the point at which the lamp starts operating.
Requirements
- Sense room brightness.
- Allow the user to adjust the switching threshold.
- Use a dimmable LED output.
- Show sensor and threshold values in Serial Monitor during testing.
- Use only Level 1 techniques.
1. Identify the inputs and output
The LDR tells us how bright the room is. The potentiometer gives the user an adjustable number. The Arduino compares those two values and controls LED brightness.
2. System plan diagram
3. Circuit diagram
4. Breadboard build plan
5V → LDR → A0 junction → 10 kΩ → GND
Outer pins to 5V and GND; centre pin to A1
Pin 9 → resistor → LED anode; cathode → GND
UNO 5V to + rail and UNO GND to – rail
5. Pseudocode
Set LED pin as output
Start Serial Monitor
REPEAT FOREVER
Read light sensor from A0
Read user threshold from A1
Print both values
IF light value is lower than threshold
Calculate a brightness value
Send brightness to PWM LED
ELSE
Turn LED off
END IF
Wait a short time
REPEAT
6. Arduino code
const int ldrPin = A0;
const int thresholdPin = A1;
const int ledPin = 9;
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
int lightLevel = analogRead(ldrPin);
int threshold = analogRead(thresholdPin);
int brightness = 0;
if (lightLevel < threshold) {
brightness = 255 - (lightLevel / 4);
if (brightness > 255) {
brightness = 255;
}
}
else {
brightness = 0;
}
analogWrite(ledPin, brightness);
Serial.print("Light: " );
Serial.print(lightLevel);
Serial.print(" Threshold: " );
Serial.print(threshold);
Serial.print(" LED: " );
Serial.println(brightness);
delay(100);
}This is intentionally direct Level 1 code. The learner can see each reading, decision and output without hiding the process inside arrays or more abstract program structures.
7. Test plan
| Test | Input / condition | Expected result | Actual result | Pass? |
|---|---|---|---|---|
| 1 | Bright room | LED remains off | ||
| 2 | Cover LDR gradually | LED turns on and becomes brighter | ||
| 3 | Turn threshold control clockwise | Switching point changes | ||
| 4 | Turn threshold control fully the other way | Switching point changes in opposite direction | ||
| 5 | Observe Serial Monitor | A0, A1 and LED values change sensibly | ||
| 6 | Disconnect LDR | Fault is visible in reading / behaviour and can be diagnosed |
8. Evaluation questions
- Did the system meet every requirement?
- Was the threshold adjustment range useful?
- Did the LED brightness change smoothly enough?
- What happened at the exact switching point?
- What would you improve if this were installed permanently?