Automatic dusk-to-dawn light
Lights switch on by themselves at dusk and off again in the morning.
Shop by category
Shop all componentsA button is the simplest digital input. One side goes to 5V, the other to pin D2, and a 10k resistor from D2 to GND (a pull-down) holds the pin at LOW when nobody presses. Pressing connects 5V and the pin reads HIGH. The sketch reads the pin with digitalRead() and copies the state to an LED on D3.
Every part for this build comes in the Geekobot Spark Kit box, a Geekobot exclusive, together with the parts for all 24 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 Spark Kit project
220 ohm and 10k resistor pack: 220 ohm for the LED, 10k as the pull-down
Sensor Shield v5.0 from the kit: every pin has its own G, V, S header, so modules plug in with female jumpers
Follow the colours: red is power, dark grey is ground, blue is a signal.
spark_kit_04_push_button_led.inoVerify & upload in Electrolark// Spark Kit 04: push button LED
int led = 3;
int button = 2;
void setup() {
pinMode(led, OUTPUT);
pinMode(button, INPUT); // 10k pull-down on the breadboard
}
void loop() {
int state = digitalRead(button);
if (state == HIGH) {
digitalWrite(led, HIGH);
} else {
digitalWrite(led, LOW);
}
}
Use the kit's USB cable (some phone cables carry power only), install the CH340 driver on Windows if the port does not appear, and pick Tools > Board > Arduino Uno.
The pull-down is missing or loose, so D2 floats. Check the 10k from D2 to GND.
The button is turned 90 degrees, so its legs are always connected. Rotate it across the centre gap.
It gently pulls the pin to 0 V when the button is open, so the input never floats and reads random noise.
Yes, with pinMode(button, INPUT_PULLUP) and the button to GND instead of 5V. The reading is then LOW when pressed; projects 19 and 24 use that.
Yes. It is one of the 24 projects in the Geekobot Spark Kit, and every part on the list comes in the kit box. You can also buy the parts one by one from the list above.
No. Every Spark Kit project is wired on the breadboard or the Sensor Shield with jumper wires.
8 parts: Uno R3 CH340G ATmega328p Compatible Development Board, Arduino USB-A to USB-B Data Cable for UNO/MEGA, Through-Hole LED Pack (Pack of 10), Tactile Push Button Switch, 2 × Carbon Film Resistor 1/4W 5% (Pack of 10), Solderless Breadboard, Dupont Jumper Wires (40 pcs) and Arduino Sensor Shield V5 Expansion Board. 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 30 minutes. The build on this page has 6 steps.
No. This page has the complete, tested code (spark_kit_04_push_button_led.ino).
About ₹443 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Reading a digital input; Why an input needs a pull-down resistor; if / else decisions.
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.