Guides · 10 min read

Arduino Chicken Coop Door: Automatic Opening with LDR or RTC

Build an Arduino chicken coop door that opens at dawn and closes at dusk: LDR or RTC control, gear motor, L298N, limit switches, jam protection, solar power.

An automatic chicken coop door is a motorised door that opens by itself at first light and closes after the hens have gone to roost. With Arduino you control it either with a light sensor (LDR) or with a real-time clock module (RTC); a geared DC motor moves the door, and two limit switches report when it is fully open and fully closed. No more getting up at dawn, and no more worrying about foxes and martens when you come home late.

In this guide you'll go through every step, from choosing the door mechanism and wiring to hysteresis on the light reading and jam protection. You'll also find a seasonal table of opening and closing times, two separate Arduino sketches and a step-by-step energy calculation for running it on solar power. The current and time values in the calculations are approximate; measure your own motor and board with a multimeter and redo the maths with the same steps.

L298N motor driver module
L298N motor driver: turns a 12 V gear motor in both directions from Arduino's small signals.

How does an automatic coop door work?

The logic is a simple state machine: the door is either closed, opening, open, closing, or in a fault state because something went wrong. Arduino checks the light or the clock at regular intervals, starts the motor when the condition is met and waits until the matching limit switch is pressed. If the time limit runs out before the switch is pressed, it assumes the door is stuck, stops the motor and moves to the safe side. If this pattern is new to you, the Arduino state machine article explains it step by step.

PartJobNote
Arduino Uno or NanoMakes the decisions, drives the motor and sensorsA Pro Mini draws less if it runs on solar
Geared DC motor (12 V)Lifts or slides the doorWorm-gear types hold the load even without power
L298N motor driverChanges the motor's direction and speedDrops about 2 V across itself
2 limit switchesReport fully open and fully closedUse the COM and NO terminals
LDR + 10 kΩ resistorMeasures daylightShould face the sky and be kept out of the rain
DS1307 or DS3231 RTCFor running from a time tableA DS3231 drifts less than a few minutes a year
Button and LEDManual open/close and status indicatorThe LED blinks to show a fault
12 V battery + panel + charge controllerPower for a garden without mainsStep-by-step calculation below

Door mechanism: vertical or horizontal slide?

The most common design is a light panel that slides up and down between two rails. A spool on the motor shaft winds a cord and lifts the panel; when closing, the motor unwinds the cord and the panel drops under its own weight. It's easy and cheap to build, but if the panel comes down on a hen it pins her with its weight. In a horizontal slide the panel is pushed sideways by a threaded rod or a gear rack; it's safer and less likely to stick in snow and ice, but the mechanics take a bit more effort. Whichever you choose, keep the panel as light as possible: 4–6 mm plywood or plastic sheet is enough and eases the load on the motor.

FeatureVertical slide (cord and spool)Horizontal slide (threaded rod or rack)
Build difficultyEasyMedium
Closing forceThe panel's weightThe motor's torque, must be limited
Risk of trapping a henYes, keep the panel lightLow, but torque and time limits are a must
Snow and iceFrozen rails may stop it coming downLess affected
Holding currentNone with a worm-gear motorThe threaded rod holds itself
Best forSmall coops, quick buildsLarge flocks, harsh winters

Wiring and pin table

ConnectionArduino UnoESP32Raspberry Pi Pico
L298N ENA (speed, PWM)D9GPIO 25GP15
L298N IN1 / IN2D7 / D8GPIO 26 / GPIO 27GP14 / GP13
Top limit switch (COM → GND, NO → pin)D2GPIO 32GP10
Bottom limit switch (COM → GND, NO → pin)D3GPIO 33GP11
Manual open/close button (other leg to GND)D4GPIO 14GP12
Midpoint of the LDR + 10 kΩ dividerA0GPIO 34 (ADC1)GP26 (ADC0)
RTC SDA / SCLA4 / A5GPIO 21 / GPIO 22GP4 / GP5
L298N 12V inputBattery positive (fused)Battery positive (fused)Battery positive (fused)
GNDBattery negative, L298N and board commonCommonCommon
Never power the motor from Arduino's 5V pin; connect 12 V to the L298N's 12V input through a 2–3 A fuse and join all the GNDs. If you use an ESP32 or a Pico, feed the LDR divider from 3.3 V; tying it to 5 V can damage the analog pin. The DS1307 needs at least 4.5 V, so use a DS3231 module with 3.3 V boards.

Wire the limit switches from their COM and NO (normally open) terminals and set the pins to INPUT_PULLUP: the pin reads HIGH while the switch is free and LOW when the door presses it. If a wire breaks, the pin stays HIGH and the code acts as if the switch was never pressed, which is why every movement in the code below has a time limit. With the LDR between 5 V and A0 and the 10 kΩ resistor between A0 and GND, the value rises in daylight and falls in darkness. You can play with the divider in the voltage divider calculator and find more on the LDR in the LDR light sensor article.

LDR or RTC? When should the door open?

Chickens live by the light: they want out at first light and go back to the coop on their own as dusk falls. An LDR follows this behaviour naturally; on a cloudy winter morning the door opens a little later, on a summer morning earlier. Its weak spot is that it can be fooled by car headlights, a garden lamp or a leaf landing on the sensor. An RTC runs at the time you wrote in the table whatever the weather; you'll need to update it every month, but it holds few surprises. In practice the best result is to combine them: follow the light for closing, but also add a time limit such as "close at 22:00 at the latest". The table below shows approximate sunrise and sunset times for Istanbul (UTC+3), calculated for the 15th of each month, and a closing time 30 minutes after sunset.

MonthSunrise (open)SunsetClose
January08:2518:0018:30
February08:0018:4019:10
March07:1519:1019:40
April06:2519:4520:15
May05:4520:1520:45
June05:3020:4021:10
July05:4520:3521:05
August06:1520:0520:35
September06:4519:1519:45
October07:1518:2518:55
November07:5017:4518:15
December08:2017:3518:05
The table is for Istanbul; further east the sun rises and sets earlier, further west later, by roughly 4 minutes per degree of longitude. If your country uses daylight saving time, add 1 hour in the summer months. Note the sunrise and sunset times for your own town once and update the table in the code.

Step-by-step build

  1. Build the panel and rails; make sure the panel slides up and down by hand without catching.
  2. Mount the motor above the panel, fit the spool on its shaft and tie the cord. Leave two turns of cord on the spool when the panel is fully open.
  3. Screw the top limit switch where the panel touches it when fully open and the bottom one at the fully closed position.
  4. Wire the L298N, the Arduino and the LDR as in the table; test the motor with a 12 V adapter before using the battery.
  5. Open the Serial Monitor and note the LDR values in daylight, at dusk and at night; set the thresholds from these values.
  6. If the motor turns the wrong way, swap its two wires on the L298N.
  7. Time one full opening and closing of the panel; set MOTOR_TIMEOUT_MS to about 1.5 times that.
  8. Put the electronics in a waterproof box, bring the cables in from below and leave the LDR outside facing the sky.

Arduino code: LDR, hysteresis and jam protection

C++ (Arduino IDE)
1// Otomatik kümes kapısı: LDR + redüktörlü DC motor + L298N + 2 limit switch
2// Automatic chicken coop door: LDR + gear motor + L298N + 2 limit switches
3const int ENA = 9;              // L298N hız (PWM) / L298N speed (PWM)
4const int IN1 = 7;              // yön 1 / direction 1
5const int IN2 = 8;              // yön 2 / direction 2
6const int LIMIT_TOP = 2;        // üst switch, basılınca LOW / top switch, LOW when pressed
7const int LIMIT_BOTTOM = 3;     // alt switch, basılınca LOW / bottom switch, LOW when pressed
8const int BUTTON = 4;           // elle aç-kapa / manual open-close
9const int STATUS_LED = 13;      // durum LED'i / status LED
10const int LDR_PIN = A0;         // LDR + 10 kΩ bölücü / LDR + 10 kΩ divider
11
12const int DARK_LEVEL = 180;     // bunun altı gece / below this is night
13const int LIGHT_LEVEL = 320;    // bunun üstü gündüz (histerezis) / above this is day (hysteresis)
14const unsigned long CONFIRM_MS = 10UL * 60UL * 1000UL;  // 10 dk kararlı ışık / 10 min of stable light
15const unsigned long MOTOR_TIMEOUT_MS = 25000UL;         // en uzun hareket süresi / longest allowed travel
16const int MOTOR_SPEED = 200;                            // 0-255
17const int MAX_CLOSE_RETRIES = 3;                        // sıkışmada deneme sayısı / retries on a jam
18
19enum State { CLOSED, OPENING, OPEN, CLOSING, FAULT };
20State state = CLOSED;
21unsigned long moveStart = 0;
22unsigned long conditionSince = 0;
23int closeRetries = 0;
24
25void motorUp()   { digitalWrite(IN1, HIGH); digitalWrite(IN2, LOW);  analogWrite(ENA, MOTOR_SPEED); }
26void motorDown() { digitalWrite(IN1, LOW);  digitalWrite(IN2, HIGH); analogWrite(ENA, MOTOR_SPEED); }
27void motorStop() { analogWrite(ENA, 0); digitalWrite(IN1, LOW); digitalWrite(IN2, LOW); }
28
29bool topPressed()    { return digitalRead(LIMIT_TOP) == LOW; }
30bool bottomPressed() { return digitalRead(LIMIT_BOTTOM) == LOW; }
31
32int readLight() {                         // 16 örneğin ortalaması / average of 16 samples
33  long sum = 0;
34  for (int i = 0; i < 16; i++) { sum += analogRead(LDR_PIN); delay(2); }
35  return sum / 16;
36}
37
38void startOpening() {
39  if (topPressed()) { state = OPEN; conditionSince = millis(); return; }
40  state = OPENING;
41  moveStart = millis();
42  motorUp();
43  Serial.println(F("Aciliyor / Opening"));
44}
45
46void startClosing() {
47  if (bottomPressed()) { state = CLOSED; conditionSince = millis(); return; }
48  state = CLOSING;
49  moveStart = millis();
50  motorDown();
51  Serial.println(F("Kapaniyor / Closing"));
52}
53
54bool buttonPressed() {                    // basit debounce / simple debounce
55  static bool last = HIGH;
56  static unsigned long changedAt = 0;
57  bool now = digitalRead(BUTTON);
58  if (now != last && millis() - changedAt > 50) {
59    changedAt = millis();
60    last = now;
61    return now == LOW;
62  }
63  return false;
64}
65
66void checkLight(unsigned long now) {
67  static unsigned long lastRead = 0;
68  if (now - lastRead < 1000) return;      // saniyede bir ölç / measure once per second
69  lastRead = now;
70  int light = readLight();
71  bool wantChange = (state == OPEN && light < DARK_LEVEL) || (state == CLOSED && light > LIGHT_LEVEL);
72  if (!wantChange) { conditionSince = now; return; }       // koşul bozuldu, sayaç baştan / condition broken, restart timer
73  if (now - conditionSince >= CONFIRM_MS) {
74    if (state == OPEN) startClosing(); else startOpening();
75  }
76}
77
78void setup() {
79  pinMode(ENA, OUTPUT);
80  pinMode(IN1, OUTPUT);
81  pinMode(IN2, OUTPUT);
82  pinMode(LIMIT_TOP, INPUT_PULLUP);
83  pinMode(LIMIT_BOTTOM, INPUT_PULLUP);
84  pinMode(BUTTON, INPUT_PULLUP);
85  pinMode(STATUS_LED, OUTPUT);
86  motorStop();
87  Serial.begin(9600);
88
89  // Açılışta kapının yerini bul / find the door position at power-up
90  if (topPressed()) state = OPEN;
91  else if (bottomPressed()) state = CLOSED;
92  else if (readLight() > (DARK_LEVEL + LIGHT_LEVEL) / 2) startOpening();
93  else startClosing();
94  conditionSince = millis();
95}
96
97void loop() {
98  unsigned long now = millis();
99
100  if (buttonPressed()) {
101    motorStop();
102    if (state == FAULT) closeRetries = 0;
103    if (state == OPEN || state == OPENING) startClosing();
104    else startOpening();
105  }
106
107  switch (state) {
108    case OPENING:
109      if (topPressed()) { motorStop(); state = OPEN; conditionSince = now; Serial.println(F("Acik / Open")); }
110      else if (now - moveStart > MOTOR_TIMEOUT_MS) { motorStop(); state = FAULT; Serial.println(F("HATA: acilmadi / FAULT: did not open")); }
111      break;
112    case CLOSING:
113      if (bottomPressed()) { motorStop(); state = CLOSED; closeRetries = 0; conditionSince = now; Serial.println(F("Kapali / Closed")); }
114      else if (now - moveStart > MOTOR_TIMEOUT_MS) {    // sıkışma: geri aç / jam: open again
115        motorStop();
116        delay(300);
117        closeRetries++;
118        if (closeRetries >= MAX_CLOSE_RETRIES) { state = FAULT; Serial.println(F("HATA: kapanmadi / FAULT: did not close")); }
119        else startOpening();                            // 10 dk sonra yeniden dener / retries after 10 min
120      }
121      break;
122    case OPEN:
123    case CLOSED:
124      checkLight(now);
125      break;
126    case FAULT:
127      break;
128  }
129
130  if (state == FAULT) digitalWrite(STATUS_LED, (now / 200) % 2);   // hızlı yanıp sönme / fast blink
131  else digitalWrite(STATUS_LED, state == OPEN);
132}
PartWhat it does
DARK_LEVEL / LIGHT_LEVELTwo separate thresholds (hysteresis): the door closes below 180 and opens above 320; in between it does nothing
CONFIRM_MSThe condition must hold for 10 minutes straight; headlights or a passing cloud won't move the door
readLight()Averages 16 readings to reduce noise
MOTOR_TIMEOUT_MSIf the switch isn't reached within 25 seconds the motor stops, protecting motor and mechanism
closeRetriesIf it jams while closing, the door reopens and tries again 10 minutes later; FAULT on the 3rd try
FAULTThe LED blinks fast; pressing the button clears the fault and opens the door
Position check in setup()After a power cut it finds the door position from the switches or the light

Thresholds differ for every LDR and every coop. After uploading, add a line that prints the light value every second and watch the Serial Monitor one evening: use the value at the moment the hens start going in as DARK_LEVEL and pick LIGHT_LEVEL at about 1.5–2 times that. If the two thresholds are too close, the door opens and closes at dusk, which is called oscillation; hysteresis and the 10-minute confirmation time prevent exactly that. Because the code uses millis instead of delay, it reacts to the button at any moment; the millis vs delay article covers this technique in detail.

Running from a time table with an RTC

If the inside of the coop is dark, there's no good spot for an LDR, or you want the door to run at the same time every day, use the RTC version. In the code below, the opening and closing times from the table above are written into two arrays as minutes after midnight; Arduino reads the clock every 10 seconds, decides whether the door should be open or closed right now and, if needed, drives the motor to the switch. Thanks to the module's backup battery, the time isn't lost during a power cut. See the RTC clock module article for setup and setting the time.

C++ (Arduino IDE)
1// Kümes kapısı, RTC ile saat tablosu (İstanbul, UTC+3) / Coop door with an RTC time table (Istanbul, UTC+3)
2#include <Wire.h>
3#include <RTClib.h>
4
5RTC_DS1307 rtc;                 // DS3231 için: RTC_DS3231 rtc; / for DS3231: RTC_DS3231 rtc;
6
7const int ENA = 9, IN1 = 7, IN2 = 8;
8const int LIMIT_TOP = 2, LIMIT_BOTTOM = 3;
9const unsigned long MOTOR_TIMEOUT_MS = 25000UL;
10
11// Ay başına açılış ve kapanış, gece yarısından itibaren dakika / per-month open and close, minutes after midnight
12//                         Oca  Şub  Mar  Nis  May  Haz  Tem  Ağu  Eyl  Eki  Kas  Ara
13const int OPEN_MIN[12]  = { 505, 480, 435, 385, 345, 330, 345, 375, 405, 435, 470, 500 };
14const int CLOSE_MIN[12] = {1110,1150,1180,1215,1245,1270,1265,1235,1185,1135,1095,1085 };
15
16void motorUp()   { digitalWrite(IN1, HIGH); digitalWrite(IN2, LOW);  analogWrite(ENA, 200); }
17void motorDown() { digitalWrite(IN1, LOW);  digitalWrite(IN2, HIGH); analogWrite(ENA, 200); }
18void motorStop() { analogWrite(ENA, 0); digitalWrite(IN1, LOW); digitalWrite(IN2, LOW); }
19
20// Switch'e kadar sür, süre aşılırsa dur / drive to the switch, stop on timeout
21bool moveTo(int limitPin, bool up) {
22  if (digitalRead(limitPin) == LOW) return true;    // zaten orada / already there
23  unsigned long start = millis();
24  if (up) motorUp(); else motorDown();
25  while (digitalRead(limitPin) == HIGH) {
26    if (millis() - start > MOTOR_TIMEOUT_MS) { motorStop(); return false; }
27  }
28  motorStop();
29  return true;
30}
31
32void setup() {
33  pinMode(ENA, OUTPUT); pinMode(IN1, OUTPUT); pinMode(IN2, OUTPUT);
34  pinMode(LIMIT_TOP, INPUT_PULLUP); pinMode(LIMIT_BOTTOM, INPUT_PULLUP);
35  motorStop();
36  Serial.begin(9600);
37  if (!rtc.begin()) { Serial.println(F("RTC yok / RTC not found")); while (true) {} }
38  if (!rtc.isrunning()) rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));   // ilk kurulumda saati ayarla / set clock on first run
39}
40
41void loop() {
42  static bool fault = false;
43  if (fault) return;                                   // hata: elle müdahale bekle / fault: wait for a manual reset
44
45  DateTime now = rtc.now();
46  int m = now.month() - 1;
47  int minutes = now.hour() * 60 + now.minute();
48  bool shouldBeOpen = minutes >= OPEN_MIN[m] && minutes < CLOSE_MIN[m];
49
50  bool ok = shouldBeOpen ? moveTo(LIMIT_TOP, true) : moveTo(LIMIT_BOTTOM, false);
51  if (!ok) {
52    if (!shouldBeOpen) moveTo(LIMIT_TOP, true);        // kapanmadıysa geri aç / if it didn't close, reopen
53    fault = true;
54    Serial.println(F("HATA: kapi takildi / FAULT: door jammed"));
55  }
56  delay(10000);                                        // 10 saniyede bir kontrol / check every 10 s
57}

How to protect the door against jamming

  • Time limit: Give each movement about 1.5 times its normal duration. If time runs out, stop the motor; this alone prevents a burnt-out motor and a snapped cord.
  • Reopen: If it jams while closing, open the door again. If a hen is caught under the door, she gets free; try closing again a few minutes later.
  • Current sensing: Add an ACS712 current sensor to the motor line and measure the normal running current. If it rises clearly above that, the door is pushing against something; stop the motor at once.
  • Lower speed: Use PWM to run the motor below full power, for example at 200/255. The door moves more gently and hits an obstacle with less force.
  • Mechanical measures: Leave a few millimetres of play in the rails, fit a soft seal on the bottom edge and attach the cord to the panel through a spring rather than directly.
  • Fault alert: On a fault, blink the LED or sound a buzzer. With an ESP32 you can also send a notification to your phone.

Solar power: a step-by-step energy calculation

Coops are usually far from a socket, so a 12 V sealed lead-acid (AGM) battery, a small solar panel and a charge controller between them is the most practical solution. Always do the maths in the same order: find each consumer's current and how many hours a day it runs, multiply and add them up, then work out how many days the battery lasts and how many watts the panel needs. The values below are approximate; they assume Arduino is fed from 12 V through an LM2596 buck converter set to 5 V with an efficiency of about 85%.

StepCalculationResult (approx.)
1. Arduino UnoAbout 50 mA at 5 V → on the 12 V side 5 × 0.05 ÷ 0.85 ÷ 12≈ 25 mA, 24 h a day → ≈ 0.6 Ah
2. L298N idleAbout 5–15 mA depending on the module (ENA LOW), check by measuring≈ 0.1–0.35 Ah/day
3. MotorExample: 0.4 A × 15 s × 2 moves = 12 A·s≈ 0.003 Ah/day (negligible)
4. Daily total0.6 + 0.35 + 0.003≈ 1 Ah/day ≈ 12 Wh/day
5. Battery autonomyUse at most half of a 7 Ah battery: 3.5 Ah ÷ 1 Ah≈ 3.5 days without sun
6. Panel power (winter)12 Wh ÷ (1.5 peak sun hours × 0.7 efficiency)≈ 11 W → choose a 20 W panel
7. Panel power (summer)12 Wh ÷ (5 h × 0.7)≈ 3.5 W is enough

The calculation shows that almost all the energy goes not to the motor but to the Arduino and driver idling all day. The most effective ways to cut consumption are to use a Pro Mini with its power LED removed instead of an Uno, put Arduino to sleep and wake it every 8 seconds, and switch the L298N's supply on only while moving, using a MOSFET or relay. That brings daily use down to a few tens of mAh, and even a 5 W panel is enough. Sleep modes are covered in the Arduino sleep mode article; to run the numbers with your own values, use the battery life calculator.

Never connect the panel straight to the battery; always use a solar charge controller and power Arduino from its LOAD output, so the load is cut automatically when the battery gets too low. If the coop drops below freezing in winter, don't choose Li-ion: Li-ion cells must not be charged below 0 °C. A lead-acid battery loses capacity in the cold, but it copes better with this job.

Project ideas and upgrades

  • Idea: Add a DHT11 sensor inside the coop and open the door later when it's very cold.
  • Idea: Use an ESP32 to message your phone when the door opens and closes; the ESP32 Telegram bot article is a good starting point.
  • Idea: Add a morning feeder driven by the same RTC; the servo mechanism from the automatic pet feeder article can be adapted.
  • Idea: Watch the water container level with a float switch and raise an alert when it runs low.
  • Idea: If you raise chicks, set up temperature control the way the egg incubator article does.
  • Idea: Store how often the door opened and how many faults occurred in EEPROM and show them on a display.

Common problems and fixes

SymptomLikely causeFix
The door opens and closes several times at duskA single threshold, no hysteresisUse two thresholds and a 10-minute confirmation time
The motor doesn't stop at the switchSwitch wired to NC or the wire is brokenUse COM and NO, print the switch state in the Serial Monitor
The motor turns the wrong wayMotor wires reversedSwap the motor's two wires on the L298N
Arduino resets when the motor startsStart-up current drags the voltage down, brush noiseAdd 100 nF across the motor and 470 µF at the driver input; power Arduino from its own regulator
The door opens very late in the morningLDR in shade or dirty, threshold too highMove the LDR to face east and the sky, lower LIGHT_LEVEL
The RTC drifts a few minutes a monthThe DS1307 crystal drifts with temperatureUse a DS3231 and replace the RTC battery
The panel won't come down in winterThe rails ice upLeave play in the rails, use plastic rails; the time limit protects the motor
Run the door on your desk for a week before fitting it to the coop: put the LDR by a window and hang a spool with a small weight on the motor instead of the panel. Note the opening and closing times from the Serial Monitor; since the hens' safety is at stake, check with your own eyes in the first few evenings that the door really closed.

An automatic coop door is a great learning project because it brings light sensing, motor control, a state machine and an energy budget together in one real build. To strengthen the basics, you can follow projects such as "LDR Night Light", "DS1302 RTC Clock Module Setup" and "Bluetooth-Controlled Car with L298N" step by step in the BlueGrays app, with circuit diagrams and code, and then combine those pieces in your own coop door.

Frequently asked questions

What motor should I use for an automatic chicken coop door?

A 12 V, low-speed (around 10–30 rpm) geared DC motor is the best fit. Worm-gear models hold the door in place when the power is off, so no extra brake is needed. Small motors are enough for a light panel; what matters most is that the panel slides freely in its rails.

Should a coop door use an LDR or an RTC?

An LDR follows the hens' natural light rhythm, so it's more accurate for closing time, but it can be fooled by lights such as headlights. An RTC runs at the table's time every day with few surprises, but it needs updating with the seasons. The safest approach is to follow the light and add a latest closing time.

What time should a chicken coop door close?

Hens go in on their own as it gets dark, so closing the door about 20–30 minutes after sunset is safe. If it closes earlier, a late hen may be left outside. Check the coop at closing time in the first few days and adjust the delay to your own flock.

Can a coop door run on solar power?

Yes. A 12 V lead-acid battery, a charge controller and a 10–20 W panel are enough for most setups. Most of the energy is used not by the motor but by the Arduino waiting all day; with sleep mode and a low-power board the panel can be much smaller.

What happens if the door closes on a hen?

On a vertical door the panel presses down with its own weight, which is why keeping it light matters so much. With a time limit in the code, the motor stops when the door can't reach the bottom switch and the door opens again. Measuring the strain with a current sensor makes the protection even faster.

How do I wire a limit switch to Arduino?

Connect the switch's COM terminal to GND and NO (normally open) to an Arduino digital pin, and set the pin to INPUT_PULLUP. It reads HIGH when free and LOW when the door presses the switch. Since a broken wire would leave the pin HIGH forever, always add a time limit in the code.

See all projects
Night Light with Ldr
AR-12Beginner

Night Light with Ldr

A little night light that turns on by itself when it gets dark and goes off when morning comes.

4.7(107)
247
Measuring Light Intensity with an LDR
AR-11Beginner

Measuring Light Intensity with an LDR

Want to see how bright your room is as a number? The LDR, a small part that reacts to light, measures the light around it, and the Arduino writes the value to your computer screen every half second.

4.5(86)
154
Reading Light Intensity with the ESP32 LDR Module
ES-11Beginner

Reading Light Intensity with the ESP32 LDR Module

Real-time monitoring of the LDR module's raw ADC value and relative light percentage calculated from dark and light reference values in the Serial Monitor. This percentage is not a lux measurement. Teaches the module’s calibration logic. It is ideal to complete this before Project 10, as it is used to determine the threshold value.

4.6(36)
56
DS1302 RTC Clock Module Setup
AR-45Beginner

DS1302 RTC Clock Module Setup

You get a small clock module running that never forgets the time, even when the Arduino is switched off.

4.5(24)
33
DS1302 RTC Clock with LCD Display
AR-46Intermediate
Premium

DS1302 RTC Clock with LCD Display

A little desk clock that keeps the time even when the power goes out. The DS1302 clock module keeps time thanks to its own tiny battery; every second the Arduino reads it and writes the time and date…

4.7(41)
51
Digital Clock with ESP32 and DS1307 RTC (I2C + LCD)
ES-18Intermediate
Premium

Digital Clock with ESP32 and DS1307 RTC (I2C + LCD)

In this project, we display the time and date on a 16x2 I2C LCD screen using the DS1307 real-time clock (RTC) module. The DS1307 is a battery-backed RTC that maintains the time even if the ESP32 is powered off. Both modules share the same I2C bus (SDA/SCL), allowing us to learn how to control multiple devices using just two signal wires. Through this project, you will gain practical knowledge of the I2C communication protocol, RTC module operation, and dynamic data display on an LCD screen.

4.6(26)
40
Bluetooth Controlled Car with L298N
AR-80Advanced
Premium

Bluetooth Controlled Car with L298N

Turn your phone into a remote and drive your own robot car. The Arduino receives commands from a remote-control app on your phone through a Bluetooth module and spins the wheels with a motor driver…

5.0(39)
66
Smart Irrigation Station
AR-83Advanced
Premium

Smart Irrigation Station

A gardener that waters your plants on its own, so they don't dry out while you're on vacation.

5.0(42)
57