Meet the parts
Everything here comes from the kit. Both projects share the same breadboard and output parts, so you wire most of it once.
| Part | Job | Used in |
|---|---|---|
| Arduino UNO (SMD, FT232 USB) | Runs the code | Both |
| USB cable, A to B | Uploads code and powers the Arduino | Both |
| 400-point breadboard | Holds the parts with no soldering | Both |
| Male-to-male jumper wires | Connect the Arduino to the breadboard | Both |
| RGB LED, 5 mm, 4 legs | Glowing night light, or the test result colour | Both |
| LED, 5 mm | Daylight indicator, or “battery connected” | Both |
| Buzzer B-10 | Chirps at nightfall, or beeps the result | Both |
| Resistor pack: four 220 Ω | Protect each LED colour and the LED | Both |
| LDR module | Tells light from dark | Project 1 |
| Resistor pack: two 10 kΩ | Halve the battery voltage for A0 | Project 2 |
| AAA 1.5 V battery | The battery being tested | Project 2 |
The AAA battery can’t power the ArduinoAn UNO needs 5 V from USB. In this kit the AAA cell is what Project 2 tests, so keep the USB cable plugged in for both projects.
Set up the software
- Install the Arduino IDENo extra libraries are needed for these projects.
- Connect the UNOPlug in the USB A-to-B cable. This board uses an FT232 USB chip. If no port appears, install the FTDI driver.
- Pick the board and portChoose Tools → Board → Arduino Uno, then the Port that appeared when you plugged it in.
Build the base circuit
Unplug the USB cable while wiring. This layout has room for both projects at once. Pick a group to see only its parts and wires.
Connection table
| Arduino pin | Goes to | Through |
|---|---|---|
| D9 | RGB red leg | 220 Ω |
| D10 | RGB green leg | 220 Ω |
| D6 | RGB blue leg | 220 Ω |
| GND rail | RGB common (longest) leg | wire |
| D7 | LED long leg (+) | 220 Ω |
| GND rail | LED short leg (−) | wire |
| D8 | Buzzer + leg | direct |
| D2 | LDR module DO | wire |
| 5V / GND rails | LDR module VCC / GND | wire |
| A0 | Middle of the two 10 kΩ resistors | wire |
| GND rail | Second 10 kΩ, and battery − | wire |
| 5V, GND | Bottom + and − rails, bridged to the top rails | wire |
Why blue is on D6, not D11The buzzer’s tone() borrows the timer that dims pins 3 and 11. Keeping the RGB LED on D9, D10 and D6 lets it glow smoothly while the buzzer beeps.
Test the base circuit
Upload this test, then open the Serial Monitor at 9600 baud. The RGB LED should show red, green, blue, then the LED lights and the buzzer beeps.
// BASE CIRCUIT TEST: RGB LED, LED and buzzer
const int RED = 9, GREEN = 10, BLUE = 6;
const int LED = 7, BUZZER = 8;
const bool COMMON_ANODE = false; // true if the RGB long leg goes to 5V
void rgb(int r, int g, int b) {
if (COMMON_ANODE) { r = 255 - r; g = 255 - g; b = 255 - b; }
analogWrite(RED, r);
analogWrite(GREEN, g);
analogWrite(BLUE, b);
}
void setup() {
pinMode(RED, OUTPUT); pinMode(GREEN, OUTPUT); pinMode(BLUE, OUTPUT);
pinMode(LED, OUTPUT); pinMode(BUZZER, OUTPUT);
Serial.begin(9600);
}
void loop() {
Serial.println("Red"); rgb(255, 0, 0); delay(800);
Serial.println("Green"); rgb(0, 255, 0); delay(800);
Serial.println("Blue"); rgb(0, 0, 255); delay(800);
rgb(0, 0, 0);
Serial.println("LED and beep");
digitalWrite(LED, HIGH);
tone(BUZZER, 1000, 200);
delay(800);
digitalWrite(LED, LOW);
delay(400);
}- No colours at all?Your RGB LED may be common anode. Move its long-leg wire from the GND rail to the + rail and set
COMMON_ANODE = truein every sketch. - Colours in the wrong order?Leg order varies between makers. Swap the wires on D9, D10 and D6 until “Red” shows red.
- LED stays dark?Turn it round: the long leg goes towards the resistor and D7.
Before you plug in
0 of 5 checked
Project 1: Smart night light
An LDR (light-dependent resistor) changes its resistance with light. The module compares it with the setting on its small screw and switches its DO pin, so the Arduino just reads HIGH or LOW.
DARK to LOW.- Add the LDR modulePlug it into row a, columns 24–27. Wire VCC to the + rail, GND to the − rail and DO to D2. AO isn’t needed.
- Upload the night light sketchKeep the USB cable plugged in.
- Set the sensitivityCover the sensor with your hand and turn the module’s screw until its DO LED goes off in shadow and on in light.
- Try itCover the sensor or switch off the room light. After a second the buzzer chirps and the RGB LED starts a slow rainbow. The plain LED shows it’s daytime.
// SMART NIGHT LIGHT: LDR module + RGB LED + LED + buzzer
const int LDR_DO = 2; // LDR module DO pin
const int RED = 9, GREEN = 10, BLUE = 6;
const int LED = 7, BUZZER = 8;
const bool COMMON_ANODE = false; // true if the RGB long leg goes to 5V
const int DARK = HIGH; // DO level when it is dark
const unsigned long SETTLE = 1000; // ms it must stay dark or light
const int BRIGHTNESS = 150; // night light brightness, 0-255
bool night = false;
unsigned long changedAt = 0;
int hue = 0;
void rgb(int r, int g, int b) {
r = map(r, 0, 255, 0, BRIGHTNESS);
g = map(g, 0, 255, 0, BRIGHTNESS);
b = map(b, 0, 255, 0, BRIGHTNESS);
if (COMMON_ANODE) { r = 255 - r; g = 255 - g; b = 255 - b; }
analogWrite(RED, r); analogWrite(GREEN, g); analogWrite(BLUE, b);
}
void showHue(int h) { // 0-359 around the colour wheel
int x = (h % 120) * 255 / 120;
if (h < 120) rgb(255 - x, x, 0);
else if (h < 240) rgb(0, 255 - x, x);
else rgb(x, 0, 255 - x);
}
void setup() {
pinMode(LDR_DO, INPUT);
pinMode(RED, OUTPUT); pinMode(GREEN, OUTPUT); pinMode(BLUE, OUTPUT);
pinMode(LED, OUTPUT); pinMode(BUZZER, OUTPUT);
rgb(0, 0, 0);
Serial.begin(9600);
Serial.println("Night light ready");
}
void loop() {
bool darkNow = (digitalRead(LDR_DO) == DARK);
if (darkNow != night) { // light level changed
if (changedAt == 0) changedAt = millis();
if (millis() - changedAt >= SETTLE) { // and stayed changed
night = darkNow;
changedAt = 0;
if (night) {
Serial.println("Dark: night light ON");
tone(BUZZER, 880, 120); delay(160);
tone(BUZZER, 660, 160);
} else {
Serial.println("Light: night light OFF");
}
}
} else {
changedAt = 0;
}
digitalWrite(LED, night ? LOW : HIGH); // LED on in daylight
if (night) {
hue = (hue + 1) % 360; // slow rainbow
showHue(hue);
} else {
rgb(0, 0, 0);
}
delay(20);
}| Setting | Default | What it changes |
|---|---|---|
DARK | HIGH | The DO level that means “dark” |
SETTLE | 1000 ms | How long it must stay dark or light before switching, so a passing shadow doesn’t trigger it |
BRIGHTNESS | 150 | Night light brightness, 0–255 |
Project 2: AAA battery tester
The Arduino’s A0 pin measures voltage from 0 to 5 V as a number from 0 to 1023. Two equal resistors split the battery voltage in half. This keeps the pin safe if the battery is connected the wrong way round, and the code doubles the reading back.
- Add the two 10 kΩ resistorsOne from g15 to g19, one from i15 to the bottom − rail. Wire A0 to f15.
- Connect the batteryPress a wire from j19 onto the battery’s + end, and a wire from the − rail onto its flat − end. Tape helps them stay put.
- Upload the battery tester sketchOpen the Serial Monitor to see the voltage.
- Read the resultThe LED lights to show a battery is connected, and the RGB LED and beeps give the result.
// AAA BATTERY TESTER: 1.5 V cells only
const int BATT = A0; // between the two 10k resistors
const int RED = 9, GREEN = 10, BLUE = 6;
const int LED = 7, BUZZER = 8;
const bool COMMON_ANODE = false; // true if the RGB long leg goes to 5V
const float VREF = 5.0; // the UNO's 5 V supply
const float GOOD = 1.40, WEAK = 1.20, NONE = 0.30; // volts
int lastState = -1; // 0 none, 1 replace, 2 weak, 3 good
void rgb(int r, int g, int b) {
if (COMMON_ANODE) { r = 255 - r; g = 255 - g; b = 255 - b; }
analogWrite(RED, r); analogWrite(GREEN, g); analogWrite(BLUE, b);
}
float readBattery() {
long sum = 0;
for (int i = 0; i < 20; i++) { // average 20 readings
sum += analogRead(BATT);
delay(5);
}
float pinVolts = (sum / 20.0) * VREF / 1023.0;
return pinVolts * 2.0; // two equal resistors halve the voltage
}
void beeps(int count, int freq) {
for (int i = 0; i < count; i++) {
tone(BUZZER, freq, 120);
delay(220);
}
}
void setup() {
pinMode(RED, OUTPUT); pinMode(GREEN, OUTPUT); pinMode(BLUE, OUTPUT);
pinMode(LED, OUTPUT); pinMode(BUZZER, OUTPUT);
Serial.begin(9600);
Serial.println("Battery tester ready");
}
void loop() {
float v = readBattery();
int state = (v < NONE) ? 0 : (v < WEAK) ? 1 : (v < GOOD) ? 2 : 3;
if (state == 0) rgb(0, 0, 0); // nothing connected
else if (state == 1) rgb(255, 0, 0); // red: replace
else if (state == 2) rgb(255, 120, 0); // yellow: weak
else rgb(0, 255, 0); // green: good
digitalWrite(LED, state > 0 ? HIGH : LOW); // a battery is connected
Serial.print("Battery: ");
Serial.print(v, 2);
Serial.print(" V ");
if (state == 0) Serial.println("No battery");
else if (state == 1) Serial.println("REPLACE");
else if (state == 2) Serial.println("WEAK");
else Serial.println("GOOD");
if (state != lastState && state > 0) { // beep once per new result
if (state == 3) beeps(1, 1500);
if (state == 2) beeps(2, 1000);
if (state == 1) beeps(3, 400);
}
lastState = state;
delay(300);
}Only test single 1.5 V cellsUse AA or AAA cells only. Never connect a 9 V battery, a lithium battery pack or a phone battery, and never join the battery to the 5V rail. Rechargeable NiMH cells are 1.2 V when full, so they show WEAK even when charged.
Troubleshooting
No port appears in the Arduino IDE
- Try another USB cable or port. Some cables only charge.
- Install the FTDI driver (link in step 1), then plug the board in again.
The RGB LED shows the wrong colours, or none
- No light at all: it may be common anode. Move the long leg to the + rail and set
COMMON_ANODE = true. - Wrong colours: swap the wires on D9, D10 and D6.
- One colour missing: check that leg’s resistor sits in the same column.
The buzzer is silent or only clicks
- Swap its legs: the + mark goes to D8.
- Both active and passive buzzers sound with
tone(); an active one just sounds rougher.
The night light never turns on
- Watch the module’s DO LED while covering the sensor, and adjust its screw until it switches.
- If the light comes on in daylight instead, change
DARKtoLOW.
The night light flickers at dusk
Increase SETTLE to 2000 or 3000 ms, or turn the screw a little so it switches in a darker room.
The tester always says “No battery”
- Press the wires firmly on the battery ends and check A0 goes to f15.
- Check the battery − wire reaches the − rail.
The voltage looks too high or too low
- Both resistors must be 10 kΩ (brown black orange).
- USB power isn’t exactly 5 V. If you know the real value, set
VREFto it.