Automatic dusk-to-dawn light
Lights switch on by themselves at dusk and off again in the morning.
Shop by category
Shop all componentsA push-pull solenoid is an electromagnet with a moving plunger: power it and the plunger pulls in. Used as a latch bolt it unlocks a drawer, cabinet or tool box. A 4x4 membrane keypad takes the code, and a MOSFET module switches the 12 V solenoid, with a diode to catch the voltage spike when it turns off. Three wrong codes lock the keypad for a minute.
The solenoid gets hot if powered for long: never leave it energised.
Tick anything you already have and the total updates.
Follow the colours: red is power, dark grey is ground, blue is a signal.
12 V 2 A adapter powers the solenoid and the Nano (through VIN).
keypad_latch.inoVerify & upload in Electrolark#include <Keypad.h>
const char KEYS[4][4] = {{'1','2','3','A'},{'4','5','6','B'},{'7','8','9','C'},{'*','0','#','D'}};
byte rowPins[4] = {9, 8, 7, 6};
byte colPins[4] = {5, 4, 3, 2};
Keypad pad = Keypad(makeKeymap(KEYS), rowPins, colPins, 4, 4);
const String CODE = "2580";
const int LATCH = 10, BUZZER = 11;
String entry;
int wrong = 0;
void beep(int ms) { digitalWrite(BUZZER, HIGH); delay(ms); digitalWrite(BUZZER, LOW); }
void setup() { pinMode(LATCH, OUTPUT); pinMode(BUZZER, OUTPUT); }
void loop() {
char k = pad.getKey();
if (!k) return;
beep(30);
if (k == '*') { entry = ""; return; }
if (k != '#') { if (entry.length() < 8) entry += k; return; }
if (entry == CODE) {
wrong = 0;
digitalWrite(LATCH, HIGH); delay(3000); digitalWrite(LATCH, LOW); // short pulses keep the coil cool
} else {
beep(600);
if (++wrong >= 3) { delay(60000); wrong = 0; }
}
entry = "";
}
The keypad's pin order varies; swap the row and column pin lists.
It is not rated for continuous duty; keep the unlock pulse to a few seconds.
The flyback diode is missing or reversed.
It keeps casual hands out of a drawer; it does not take the place of a real lock.
The solenoid stays locked; add a hidden mechanical override.
Yes, swap the keypad for an RC522 reader and check card IDs.
9 parts: Generic Nano CH340 Development Board (Soldered), Membrane Matrix Keypad, DC 12V 10mm 20N Push-Pull Solenoid Electromagnet, MOSFET Switch Module, Relay Replacement (D4184 / LR7843), Diodes (Pack of 10), Buzzer Module 3.3–5V, DC Power Adapter (5.5x2.1mm), Solderless Breadboard and Dupont Jumper Wires (40 pcs). On this page you can tick the parts you already have and add only the rest to your cart.
It is a beginner project and takes about 2 hours. The build on this page has 6 steps.
No. This page has the complete, tested code (keypad_latch.ino).
About ₹1,442 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
How solenoids work and why they need a flyback diode; Reading a matrix keypad; Simple code checking with lock-out.
The solenoid gets hot if powered for long: never leave it energised.
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.