Automatic dusk-to-dawn light
Lights switch on by themselves at dusk and off again in the morning.
Shop by category
Shop all componentsBring it all together: lighting, climate, security and a rotating status display running as one integrated system. Four independent jobs share one board, so nothing may block. Every task keeps its own "last run" timestamp and checks millis() to decide whether its turn has come, the sensors are read every two seconds, the display rotates every three, and the security check runs constantly. A single delay(2000) anywhere in here would freeze the alarm for two seconds. This is cooperative scheduling, and it is the step between a project that does one thing and a system that does several.
Switch only low-voltage demo loads such as the LED here. Never wire mains to these relay modules in a classroom project.
Every part for this build comes in the Geekobot Explorer Kit box, a Geekobot exclusive, together with the parts for all 61 projects, from a first blinking LED to a smart fan and a reaction game. The wiring below is the kit's own wiring.
Tick anything you already have and the total updates.
The brain of every Explorer Kit project
Male-to-female and female-to-female leads for the modules
LEDs from the kit's red, green, yellow and blue packs (one is the lamp the relay switches)
220 ohm resistors: one in series with every LED segment
10k resistor: the fixed half of the light-sensing divider
16x2 LCD with I2C backpack: four wires, two lines of text
DHT11 temperature and humidity sensor
LDR: its resistance falls as the light gets brighter
1-channel 5V relay module (active LOW); the kit has two
IR obstacle sensor: OUT goes LOW when something is in front
Nano I/O shield from the kit: every pin has its own S, V, G header, so modules plug in with jumpers
Follow the colours: red is power, dark grey is ground, blue is a signal.
explorer_kit_61_mini_smart_home.inoVerify & upload in Electrolark#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <DHT.h>
#define DHTPIN 4
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27, 16, 2);
int ldrPin = A0;
int irPin = 2;
int lightRelay = 7;
int fanRelay = 8;
int buzzer = 9;
int alarmLed = 6;
int armButton = 5;
float temp = 0;
float hum = 0;
int lightLevel = 0;
bool lightOn = false;
bool fanOn = false;
bool armed = false;
bool intruder = false;
int darkBelow = 350;
float fanAbove = 30.0;
unsigned long lastSensorRead = 0;
unsigned long lastScreenChange = 0;
int screen = 0;
void readSensors()
{
float t = dht.readTemperature();
float h = dht.readHumidity();
if (!isnan(t)) temp = t;
if (!isnan(h)) hum = h;
lightLevel = analogRead(ldrPin);
}
void runLighting()
{
lightOn = (lightLevel < darkBelow);
digitalWrite(lightRelay, lightOn ? LOW : HIGH);
}
void runClimate()
{
fanOn = (temp > fanAbove);
digitalWrite(fanRelay, fanOn ? LOW : HIGH);
}
void runSecurity()
{
if (digitalRead(armButton) == LOW)
{
armed = !armed;
if (!armed)
{
intruder = false;
}
delay(300);
}
if (armed && digitalRead(irPin) == LOW)
{
intruder = true;
}
if (intruder)
{
digitalWrite(alarmLed, (millis() / 250) % 2);
digitalWrite(buzzer, (millis() / 250) % 2);
}
else
{
digitalWrite(alarmLed, LOW);
digitalWrite(buzzer, LOW);
}
}
void updateDisplay()
{
lcd.clear();
if (screen == 0)
{
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(temp, 1);
lcd.write(223);
lcd.print("C");
lcd.setCursor(0, 1);
lcd.print("Humidity: ");
lcd.print(hum, 0);
lcd.print("%");
}
else if (screen == 1)
{
lcd.setCursor(0, 0);
lcd.print("Light: ");
lcd.print(lightOn ? "ON" : "OFF");
lcd.setCursor(0, 1);
lcd.print("Fan: ");
lcd.print(fanOn ? "ON" : "OFF");
}
else
{
lcd.setCursor(0, 0);
lcd.print("Security: ");
lcd.print(armed ? "ARMED" : "OFF");
lcd.setCursor(0, 1);
lcd.print(intruder ? "!! INTRUDER !!" : "All clear");
}
}
void setup()
{
pinMode(irPin, INPUT);
pinMode(armButton, INPUT_PULLUP);
pinMode(lightRelay, OUTPUT);
pinMode(fanRelay, OUTPUT);
pinMode(buzzer, OUTPUT);
pinMode(alarmLed, OUTPUT);
digitalWrite(lightRelay, HIGH);
digitalWrite(fanRelay, HIGH);
dht.begin();
Serial.begin(9600);
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Mini Smart Home");
lcd.setCursor(0, 1);
lcd.print("Starting up...");
delay(2500);
readSensors();
updateDisplay();
}
void loop()
{
// Security runs every pass - it must never be delayed
runSecurity();
if (millis() - lastSensorRead > 2000)
{
lastSensorRead = millis();
readSensors();
runLighting();
runClimate();
Serial.print("T=");
Serial.print(temp, 1);
Serial.print(" H=");
Serial.print(hum, 0);
Serial.print(" L=");
Serial.println(lightLevel);
}
if (millis() - lastScreenChange > 3000)
{
lastScreenChange = millis();
screen = (screen + 1) % 3;
updateDisplay();
}
}
Use the kit's mini-USB cable, install the CH340 driver on Windows if no port appears, pick Tools > Board > Arduino Nano and try Tools > Processor > ATmega328P (Old Bootloader) if the upload times out.
Turn it round: the long leg (anode) goes to the pin side through the 220 ohm resistor, the short leg to GND.
The sketch uses INPUT_PULLUP, so one leg goes to the pin and the other to GND. Use two legs on opposite sides of the button.
The active buzzer has a + leg: it goes to the pin, the other to GND. Peel off the sticker on top if it has one.
Four independent jobs share one board, so nothing may block. Every task keeps its own "last run" timestamp and checks millis() to decide whether its turn has come, the sensors are read every two seconds, the display rotates every three, and the security check runs constantly. A single delay(2000) anywhere in here would freeze the alarm for two seconds. This is cooperative scheduling, and it is the step between a project that does one thing and a system that does several.
The LCD cycles through climate, appliances and security every 3 seconds. Cover the LDR and the light relay clicks in automatically. Warm the DHT11 past 30°C and the fan relay engages.
Yes. It is project 61 of 61 in the Geekobot Explorer Kit, in level 10 (Smart home). Every part on the list comes in the kit box, and you can also buy the parts one by one from the list above.
No. Every Explorer Kit project is wired on the Nano I/O shield and the breadboard with jumper wires.
15 parts: Generic Nano CH340 Development Board (Soldered), USB Cable, Solderless Breadboard, Dupont Jumper Wires (40 pcs), Through-Hole LED Pack (Pack of 10), Carbon Film Resistor 1/4W 5% (Pack of 10), Carbon Film Resistor 1/4W 5% (Pack of 10), Tactile Push Button Switch, PCB Mounted Active Buzzer Module, LCD1602 16x2 Character LCD Display, plus 5 more. On this page you can tick the parts you already have and add only the rest to your cart.
It is a advanced project and takes about 2 hours. The build on this page has 11 steps.
No. This page has the complete, tested code (explorer_kit_61_mini_smart_home.ino).
About ₹849 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Multi-system integration and scheduling; Cooperative task scheduling with millis(); Giving a safety task priority over everything else; Rotating one display between several data sources.
Switch only low-voltage demo loads such as the LED here. Never wire mains to these relay modules in a classroom project.
Lights switch on by themselves at dusk and off again in the morning.
A precise thermostat that keeps tropical fish at a steady 25–26 °C.
Starts the pump when the tank runs low and stops it when it is full.
Tap a hidden pad to switch a lamp on or off, even through a wooden desk.
Lessons are free to read. Maker (₹499/month) and Pro add quizzes, worked problems and certificates, paid with your Geekobot account. See plans
Learning project. Check every circuit and the datasheet of each part before you power it up.