Arduino Automatic Curtain: Stepper Motor, LDR, RTC and Alexa
Arduino automatic curtain guide: torque table for 28BYJ-48 or NEMA 17, homing with a limit switch, LDR and RTC opening, plus ESP32 web and Alexa control.
An Arduino automatic curtain is the cheapest way to build a curtain or roller blind that opens when the sun comes up in the morning and closes on its own when it gets dark. A stepper motor pulls the curtain through a rope pulley or a blind tube, an LDR measures how bright the room is, and an RTC clock module keeps track of the time. The Arduino combines these three pieces of information to open and close the curtain and stop it exactly at the end positions.
In this guide you'll learn the three ways to move a curtain, the torque calculation that tells you whether to choose a 28BYJ-48 or a NEMA 17 for your curtain's weight, homing with a limit switch and saving the open end position to EEPROM. Then you'll write a complete Arduino sketch that works with an LDR and a DS3231, and finally you'll use an ESP32 to control the curtain from your phone and tell Alexa to "set the curtain to fifty percent".

How does an automatic curtain work? Rail, rope pulley and roller blind
Most curtains at home fall into three groups, and the motor sees a different load in each. On a curtain rail the motor pulls the curtain sideways; the load is not the curtain's weight but the friction of the runners inside the rail. With a roller blind the fabric winds onto a tube and the motor lifts it, so you carry the full weight of the blind. Outdoor roller shutters have heavy slats that also get pushed by the wind, which is why a ready-made tubular motor is used instead of a stepper. Knowing which group you're in is the first step to choosing the right motor.
- Rail curtain and rope loop: A pulley goes at each end of the rail, with a closed loop of cord or a GT2 belt running between them. The curtain's first runner is tied to one side of the loop; when the motor turns the pulley one way the curtain opens, and the other way it closes.
- Roller blind: You connect the motor shaft to the blind tube directly or with a coupler. As the tube turns, the fabric winds up or rolls down. On chain-operated blinds, fitting a sprocket that turns the chain onto the motor is also a common approach.
- Outdoor roller shutter: These use a 230 V AC tubular motor that already has end switches built in. Here the Arduino only gives the up and down command through two relays; it doesn't drive the motor itself.
Choosing the motor and torque for your curtain's weight
A simple calculation tells you whether a motor is strong enough: Torque = Force × pulley radius. For a roller blind, the force is the blind's weight: 1 × 9.81 = 9.8 N for 1 kg. For a rail curtain, the force is friction, which on a good rail is about 0.3 times the weight; for a 2 kg drape that's 0.3 × 2 × 9.81 ≈ 5.9 N. Multiply that force by a pulley with a 1 cm radius and you get 0.059 N·m. Multiply the result by at least 2 to allow for a dirty rail, fabric that snags, and the torque the motor loses as it speeds up. The table below shows the result of this calculation for common curtains (1 N·m ≈ 10.2 kg·cm).
| Curtain type | Approx. weight | Required torque (2× margin) | Recommended motor |
|---|---|---|---|
| Sheer curtain on a rail (pulley r = 1 cm) | 0.5 kg | 0.03 N·m (0.3 kg·cm) | 28BYJ-48 (borderline, use a smaller pulley) |
| Drape on a rail | 2 kg | 0.12 N·m (1.2 kg·cm) | NEMA 17 (0.4 N·m) + A4988 |
| Heavy blackout curtain on a rail | 4 kg | 0.24 N·m (2.4 kg·cm) | NEMA 17 (0.45 N·m) + TMC2209 |
| Roller blind (tube r = 1.5 cm) | 1 kg | 0.29 N·m (3 kg·cm) | NEMA 17 (0.45 N·m) |
| Heavy roller blind or wooden Venetian blind | 2.5 kg | 0.74 N·m (7.5 kg·cm) | NEMA 17 + 1:5 planetary gearbox, or NEMA 23 |
| Outdoor roller shutter | 5–10 kg | 2 N·m and up | Ready-made 230 V tubular motor + two relays |
| Feature | 28BYJ-48 + ULN2003 | NEMA 17 + A4988 / TMC2209 | Tubular motor (230 V AC) |
|---|---|---|---|
| Supply | 5 V (a 12 V version also exists) | 12–24 V | 230 V AC |
| Torque | About 0.03 N·m | 0.26–0.6 N·m (depends on model) | 6–50 N·m |
| One revolution | 2048 full steps / 4096 half steps | 200 full steps (1600 at 1/8 microstepping) | No steps, built-in end switches |
| Practical speed | 10–15 rpm | 60–300 rpm | About 15–17 rpm |
| 1.2 m rail (about 19 turns) | About 1.5–2 minutes | 5–20 seconds | 20–40 seconds depending on shutter height |
| Position info | By counting steps | By counting steps | Only by measuring time |
| Best use | Sheer curtain, small blind | Drape, roller blind | Outdoor shutter, heavy blind |
Parts list and wiring
- Arduino Uno (or Nano) or an ESP32 development board
- 28BYJ-48 + ULN2003 (light curtain) or NEMA 17 + A4988 or TMC2209 (medium and heavy curtains)
- Two pulleys and a closed cord loop, or a GT2 belt and a 20-tooth pulley; for a roller blind, a coupler that fits the tube
- One micro switch (limit switch) at the closed end of the curtain
- LDR and a 10 kΩ resistor; DS3231 RTC module
- Two push buttons; a separate power adapter for the motor (5 V 1 A for the 28BYJ-48, 12 V 2 A for the NEMA 17)
- If you use an A4988, a 100 µF electrolytic capacitor between VMOT and GND
| Connection | Arduino Uno (28BYJ-48 version) | ESP32 (NEMA 17 version) |
|---|---|---|
| Motor driver | ULN2003 IN1, IN2, IN3, IN4 → D8, D9, D10, D11 | A4988 STEP → GPIO 26, DIR → GPIO 27, EN → GPIO 25 |
| Homing switch (NO terminal, other side to GND) | D2 | GPIO 33 |
| LDR divider (LDR to the positive rail, 10 kΩ to GND) | A0 (LDR to 5 V) | Optional: GPIO 34 (LDR to 3.3 V) |
| RTC DS3231 | SDA → A4, SCL → A5 | Not needed, time comes from NTP |
| Buttons (to GND) | Open → D4, Close → D5 | Phone web page and Alexa |
| Motor power | ULN2003 + and − → separate 5 V, GNDs shared | VMOT → 12 V, VDD → 3.3 V, 100 µF capacitor |
| Microstepping | None (half-step in the code) | MS1 and MS2 → 3.3 V, MS3 → GND (1/8) |
Setting the end positions: homing switch and step count
A stepper motor knows how many steps it has taken but not where it started. When the power goes out and comes back, the Arduino can't tell whether the curtain is half open or closed. That's why you do homing at every start-up: the motor slowly pulls the curtain toward the closed end, stops when the micro switch at the closed end is pressed, and treats that point as 0. The open end is found without a switch, by counting steps. A pulley with a 1 cm radius has a circumference of 2 × 3.14 × 1 = 6.28 cm, so a 1.2 m rail needs 120 / 6.28 ≈ 19 turns. Since the 28BYJ-48 takes 4096 half-steps per turn, that's about 78,000 steps. The calculation is only a starting point; because the cord stretches and the pulley slips, you have to adjust the real value by hand and save it.
- Upload the sketch and open the Serial Monitor at 9600 baud. When the board starts, the curtain travels to the closed end and stops at the switch.
- Type + in the Serial Monitor and send it; each time, the motor opens half a turn. Repeat until the curtain reaches the open point you want, and use - to go back if you went too far.
- At the right point, send s. The sketch writes this position to EEPROM as the open end; even after a power cut it reads the same value at the next start-up.
- Close with k, open with a, and check that the curtain stops correctly at both ends. If the motor turns the wrong way, don't flip the ULN2003 connector; swap 8 and 10 in the pin order in the code (10, 8, 9, 11); this reverses one coil.
- Mount the micro switch on the rail so the curtain's last runner presses it lightly without jamming. If the switch lever bends too much, the homing point shifts by a few millimetres every time.
Automatic opening and closing with an LDR and RTC
A curtain that only looks at the LDR closes when a cloud passes at noon and opens in a car's headlights. A curtain that only looks at the clock opens in the dark in winter. Combining the two gives the best result: the RTC defines a time window (07:30–21:00 in this example), and inside that window the LDR decides whether the room is bright enough. There are two safeguards against sudden changes in light. The first is hysteresis: the dark threshold is 250 and the bright threshold is 400, so the curtain doesn't jitter while the reading hovers around one value. The second is a hold time: a new light state is ignored unless it stays the same for 2 minutes. The sketch also moves the motor only when the decision changes, so automatic mode doesn't immediately close a curtain you opened with the button; it waits for the next real change. You'll find how to wire an LDR and measure thresholds in the LDR light sensor article, and the DS3231 settings in the RTC clock module article.
| Time | Light (for 2 min) | Curtain state |
|---|---|---|
| Before 07:30 | Doesn't matter | Closed |
| 07:30–21:00 | Bright (above 400) | Open |
| 07:30–21:00 | Dark (below 250) | Closed (early dusk or a storm) |
| After 21:00 | Doesn't matter | Closed |
| Any time | Button pressed | Whatever the button says; automatic mode waits for the next change |
Arduino code: 28BYJ-48, LDR and DS3231
- Open the Library Manager in the Arduino IDE and install Mike McCauley's AccelStepper and Adafruit's RTClib.
- Build the circuit as in the table and power the motor from a separate 5 V adapter.
- Change OPEN_MIN, CLOSE_MIN, DARK_LEVEL and BRIGHT_LEVEL in the code to suit your room. To find the thresholds, reading the LDR value in the Serial Monitor once in the morning and once in the evening is enough.
- Upload the code, then do the end position setup described above.
1// Arduino otomatik perde: 28BYJ-48 + ULN2003, uç anahtarıyla sıfırlama, LDR + DS3231 RTC
2// Arduino automatic curtain: 28BYJ-48 + ULN2003, homing switch, LDR + DS3231 RTC
3#include <AccelStepper.h>
4#include <Wire.h>
5#include <RTClib.h>
6#include <EEPROM.h>
7
8// ULN2003 IN1..IN4 = D8..D11; AccelStepper sırası IN1, IN3, IN2, IN4 / AccelStepper order IN1, IN3, IN2, IN4
9AccelStepper motor(AccelStepper::HALF4WIRE, 8, 10, 9, 11);
10RTC_DS3231 rtc;
11
12const int PIN_HOME = 2; // kapalı uçtaki mikro anahtar, basılınca LOW / closed-end micro switch, LOW when pressed
13const int PIN_OPEN_BTN = 4; // aç butonu / open button
14const int PIN_CLOSE_BTN = 5; // kapat butonu / close button
15const int PIN_LDR = A0; // LDR gerilim bölücü / LDR voltage divider
16
17const int OPEN_MIN = 7 * 60 + 30; // 07:30 sonrası açılabilir / may open after 07:30
18const int CLOSE_MIN = 21 * 60; // 21:00'de kapanır / closes at 21:00
19const int DARK_LEVEL = 250; // bunun altı karanlık / below this is dark
20const int BRIGHT_LEVEL = 400; // bunun üstü aydınlık (histerezis) / above this is bright (hysteresis)
21const unsigned long LIGHT_HOLD_MS = 120000UL; // ışık 2 dk aynı kalmalı / light must stay 2 min
22
23const long DEFAULT_OPEN = 20L * 4096; // 20 tur, yarım adımda 4096 adım/tur / 20 turns, 4096 half-steps per turn
24const int EE_ADDR = 0;
25long openPos = DEFAULT_OPEN; // açık uç konumu (adım) / open end position (steps)
26
27bool rawBright = true, lightBright = true;
28unsigned long lightChange = 0, lastCheck = 0;
29int autoState = -1; // -1: henüz karar yok / no decision yet
30
31void goTo(long pos) {
32 motor.enableOutputs();
33 motor.moveTo(constrain(pos, 0L, openPos));
34}
35
36void homeMotor() {
37 // Anahtara basılana kadar kapanma yönünde yavaş git / move slowly toward closed until the switch is pressed
38 motor.setMaxSpeed(400);
39 motor.moveTo(-1000000L);
40 while (digitalRead(PIN_HOME) == HIGH) motor.run();
41 motor.setCurrentPosition(0); // kapalı uç = 0 / closed end = 0
42 motor.setMaxSpeed(800); // yaklaşık 12 dev/dk / about 12 rpm
43}
44
45void handleSerial() {
46 if (!Serial.available()) return;
47 char c = Serial.read();
48 long p = motor.targetPosition();
49 if (c == '+') { motor.enableOutputs(); motor.moveTo(p + 2048); } // yarım tur aç / open half a turn
50 if (c == '-') { motor.enableOutputs(); motor.moveTo(max(0L, p - 2048)); }
51 if (c == 's') { // şu anki konumu açık uç yap / save current as open end
52 openPos = motor.currentPosition();
53 EEPROM.put(EE_ADDR, openPos);
54 Serial.print(F("Acik uc kaydedildi / open end saved: ")); Serial.println(openPos);
55 }
56 if (c == 'a') goTo(openPos);
57 if (c == 'k') goTo(0);
58}
59
60void setup() {
61 Serial.begin(9600);
62 pinMode(PIN_HOME, INPUT_PULLUP);
63 pinMode(PIN_OPEN_BTN, INPUT_PULLUP);
64 pinMode(PIN_CLOSE_BTN, INPUT_PULLUP);
65
66 EEPROM.get(EE_ADDR, openPos);
67 if (openPos < 1000L || openPos > 2000000L) openPos = DEFAULT_OPEN; // boş EEPROM / empty EEPROM
68
69 if (!rtc.begin()) Serial.println(F("DS3231 bulunamadi / not found"));
70 if (rtc.lostPower()) rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // saati derleme anına kur / set to compile time
71
72 rawBright = lightBright = analogRead(PIN_LDR) > DARK_LEVEL;
73 motor.setAcceleration(400);
74 homeMotor();
75}
76
77void loop() {
78 motor.run();
79 if (motor.distanceToGo() == 0) motor.disableOutputs(); // durunca bobinleri kapat, ısınmasın / cut coils when idle
80
81 handleSerial();
82 if (digitalRead(PIN_OPEN_BTN) == LOW) goTo(openPos);
83 if (digitalRead(PIN_CLOSE_BTN) == LOW) goTo(0);
84
85 if (millis() - lastCheck < 1000) return; // otomatik karar saniyede bir / automatic decision once per second
86 lastCheck = millis();
87
88 int light = analogRead(PIN_LDR);
89 bool r = rawBright ? (light >= DARK_LEVEL) : (light > BRIGHT_LEVEL);
90 if (r != rawBright) { rawBright = r; lightChange = millis(); }
91 if (rawBright != lightBright && millis() - lightChange >= LIGHT_HOLD_MS) lightBright = rawBright;
92
93 DateTime now = rtc.now();
94 int m = now.hour() * 60 + now.minute();
95 int wantOpen = (m >= OPEN_MIN && m < CLOSE_MIN && lightBright) ? 1 : 0;
96 if (wantOpen != autoState) { // yalnız karar değişince hareket et / move only when the decision changes
97 autoState = wantOpen;
98 goTo(wantOpen ? openPos : 0);
99 Serial.println(wantOpen ? F("Otomatik: ac / open") : F("Otomatik: kapat / close"));
100 }
101}
102The heart of the code is AccelStepper's run() function. It never blocks; each time you call it, it takes a single step if one is due and handles acceleration and deceleration by itself. That way you can keep reading the buttons, the Serial Monitor and the LDR while the motor turns. When the motor reaches its target, disableOutputs() cuts the coil current; the 28BYJ-48 heats up even when standing still, and its gearbox holds a rail curtain in place anyway. If the RTC isn't found, the sketch prints a warning to the Serial Monitor; if the DS3231's battery has run out, the clock is set to the compile time.
| Serial Monitor command | What it does |
|---|---|
| + | Moves the target 2048 steps (half a turn) toward open |
| - | Moves the target 2048 steps toward closed, never below 0 |
| s | Saves the current position as the open end in EEPROM |
| a | Moves the curtain to the open end |
| k | Moves the curtain to the closed end (0) |
Phone control with an ESP32 and a NEMA 17
Two things change in the ESP32 version: a stronger NEMA 17 motor and Wi-Fi. The A4988 driver runs at 1/8 microstepping, so the motor takes 1600 steps per turn and runs both quieter and smoother. The code serves a small web page that you open in your phone's browser; its Open, 50% and Close buttons move the curtain to the position you want. If you'd rather get the time from the internet instead of an RTC, you can add the method from the ESP32 NTP article and move the LDR logic from the Arduino sketch to GPIO 34 unchanged. Don't forget to set the A4988's current limit with Vref to match your motor; you'll find the Vref calculation step by step in the A4988 guide. If silence matters, you can use a TMC2209 with the same wiring; in a bedroom you'll hear the difference right away.

1// ESP32 otomatik perde: NEMA 17 + A4988, telefondan web kontrolü ve Alexa (Espalexa)
2// ESP32 automatic curtain: NEMA 17 + A4988, phone web control and Alexa (Espalexa)
3#include <WiFi.h>
4#include <WebServer.h>
5#include <Espalexa.h>
6#include <AccelStepper.h>
7
8const char* WIFI_SSID = "WIFI_ADIN"; // ağ adın / your network name
9const char* WIFI_PASS = "WIFI_SIFREN"; // ağ şifren / your password
10
11const int PIN_STEP = 26, PIN_DIR = 27, PIN_EN = 25; // A4988 STEP, DIR, EN (EN LOW = sürücü açık / driver on)
12const int PIN_HOME = 33; // kapalı uç anahtarı, GND'ye / closed-end switch to GND
13const long OPEN_POS = 38000; // 1/8 mikro adım: 1600 adım/tur, yaklaşık 24 tur / 1/8 microstep: 1600 steps/rev, ~24 turns
14const bool HOLD_WHEN_IDLE = false; // stor ise true: motor boruyu tutsun / true for roller blinds: keep holding
15
16AccelStepper motor(AccelStepper::DRIVER, PIN_STEP, PIN_DIR);
17WebServer server(80);
18Espalexa espalexa;
19EspalexaDevice* curtain;
20
21int currentPercent() { return (int)(motor.currentPosition() * 100L / OPEN_POS); }
22
23void goPercent(int p) {
24 p = constrain(p, 0, 100);
25 digitalWrite(PIN_EN, LOW);
26 motor.moveTo(OPEN_POS * p / 100);
27}
28
29void onAlexa(uint8_t value) {
30 // Alexa 0-255 değer gönderir: 0 = kapalı, 255 = tam açık / Alexa sends 0-255: 0 = closed, 255 = fully open
31 goPercent(map(value, 0, 255, 0, 100));
32}
33
34void handleRoot() {
35 String html = "<!DOCTYPE html><html><head><meta charset='utf-8'>"
36 "<meta name='viewport' content='width=device-width'><title>Perde</title></head>"
37 "<body style='font-family:sans-serif;text-align:center'><h2>Perde %" + String(currentPercent()) + "</h2>"
38 "<p><a href='/set?p=100'><button>Aç</button></a> <a href='/set?p=50'><button>%50</button></a> "
39 "<a href='/set?p=0'><button>Kapat</button></a></p></body></html>";
40 server.send(200, "text/html", html);
41}
42
43void handleSet() {
44 int p = server.arg("p").toInt();
45 goPercent(p);
46 curtain->setPercent(p); // Alexa uygulamasındaki durumu da güncelle / sync the state in the Alexa app
47 server.sendHeader("Location", "/");
48 server.send(303);
49}
50
51void setup() {
52 Serial.begin(115200);
53 pinMode(PIN_EN, OUTPUT);
54 pinMode(PIN_HOME, INPUT_PULLUP);
55 digitalWrite(PIN_EN, LOW);
56
57 // Sıfırlama: kapalı uca kadar yavaş git / homing: move slowly to the closed end
58 motor.setAcceleration(2000);
59 motor.setMaxSpeed(800);
60 motor.moveTo(-10000000L);
61 while (digitalRead(PIN_HOME) == HIGH) motor.run();
62 motor.setCurrentPosition(0);
63 motor.setMaxSpeed(3200); // 2 tur/sn = 120 dev/dk / 2 rev/s = 120 rpm
64
65 WiFi.mode(WIFI_STA);
66 WiFi.begin(WIFI_SSID, WIFI_PASS);
67 while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print('.'); }
68 Serial.print(F("\nIP: ")); Serial.println(WiFi.localIP());
69
70 server.on("/", HTTP_GET, handleRoot);
71 server.on("/set", HTTP_GET, handleSet);
72 server.onNotFound([]() {
73 // Alexa isteklerini Espalexa'ya ver / pass Alexa requests to Espalexa
74 if (!espalexa.handleAlexaApiCall(server.uri(), server.arg(0))) server.send(404, "text/plain", "Not found");
75 });
76
77 curtain = new EspalexaDevice("Curtain", onAlexa); // Alexa'daki adı / name shown in Alexa
78 espalexa.addDevice(curtain);
79 espalexa.begin(&server); // sunucuyu Espalexa başlatır / Espalexa starts the server
80}
81
82void loop() {
83 espalexa.loop(); // server.handleClient() burada çağrılır / calls server.handleClient()
84 motor.run();
85 if (motor.distanceToGo() == 0 && !HOLD_WHEN_IDLE) digitalWrite(PIN_EN, HIGH); // boşta sürücüyü kapat / disable when idle
86}
87Adding Alexa
The Espalexa library used in the code makes the ESP32 appear on your local network as a dimmable light, so you don't need a cloud account or any extra service. When you choose "Add device" in the Alexa app, a device called "Curtain" shows up. Alexa sends a light a brightness value from 0 to 255, and the code turns that value into the curtain's open percentage. "Turn on" opens the curtain fully, "turn off" closes it, and a percentage command moves it to that point. When you change the curtain from the web page, the code also updates its state in Alexa. If the device isn't found, check that your phone and the ESP32 are on the same 2.4 GHz network; you'll find detailed troubleshooting in the ESP32 Alexa and Google Home article.
Common problems and fixes
| Symptom | Likely cause | Fix |
|---|---|---|
| Motor vibrates but doesn't turn | Wrong coil order or speed too high | On the 28BYJ-48 use pin order 8, 10, 9, 11; keep speed below 800 steps/s |
| Curtain opens a little less every day | Motor is skipping steps or the cord slips on the pulley | Increase the torque margin, tension the cord; home once a day |
| Motor never stops during homing | Switch wired to the wrong terminal or motor turning the wrong way | Use the switch's NO terminal; if the motor moves away from the switch, reverse the direction |
| Curtain keeps opening and closing on cloudy days | No hysteresis or hold time | Separate the thresholds (250/400), set LIGHT_HOLD_MS to 2–5 minutes |
| Arduino resets when the motor starts | Motor is powered from the Arduino's 5V | Power the motor from a separate adapter, connect the GNDs |
| NEMA 17 gets hot but the curtain still struggles | Vref too high or too low | Set Vref to the motor's rated current, reduce the speed |
Project ideas
- Idea: A curtain that opens at a slightly different time every day, following sunrise. Get the date with NTP and work out sunrise with a simple table.
- Idea: Connect the curtain to Home Assistant and close the south-facing blinds when the room temperature goes above 28 °C. To get started, see the ESP32 MQTT and Home Assistant article.
- Idea: Add a settings form to the web page to change the open end position over Wi-Fi, and store the value in the ESP32's memory; on the Uno, EEPROM does the same job.
- Idea: Use the same motor and code to build a system that closes a chicken coop door at sunset; the ready-made version of this idea is in the automatic chicken coop door article.
- Idea: Add a magnetic door sensor to the window; the blind won't come down while the window is open, so the fabric can't get caught in the wind.
An automatic curtain is a very instructive home automation project because it brings stepper motor control, sensor readings and time-based decisions together in one build. Start with a light sheer curtain and a 28BYJ-48, then move on to a NEMA 17 and an ESP32 once the logic clicks. If you want to try the parts one by one, you can follow the circuit diagram and code of the "Step Motor Usage", "Night Light with LDR" and "DS1302 RTC Clock Module Setup" projects step by step in the BlueGrays app.
Frequently asked questions
Which motor should I use for an automatic curtain?
A 28BYJ-48 stepper motor is enough for light sheer curtains. For drapes of 2 kg and more, roller blinds and blackout curtains, use a NEMA 17 with an A4988 or TMC2209 driver. For outdoor roller shutters, a 230 V tubular motor with built-in end switches is the better choice.
Can a 28BYJ-48 lift a roller blind?
Usually not, except for very small and light blinds. The 28BYJ-48 has about 0.03 N·m of torque, while lifting a 1 kg blind on a tube with a 1.5 cm radius needs about 0.29 N·m with a 2× margin. Use a NEMA 17 for this job.
How does the curtain remember its position after a power cut?
A stepper motor doesn't know its own position, so at every start-up you drive the curtain to the micro switch at the closed end and call that point zero. The open end position is stored in EEPROM as a step count. That way the curtain finds the right points again at the next start-up, even after a power cut.
Should an automatic curtain use an LDR or an RTC?
The best result comes from using both. The RTC sets the time window in which the curtain may open, and the LDR checks whether it's bright inside that window. Hysteresis and a hold time of a few minutes stop the curtain from opening and closing because of clouds or car headlights.
How do I control the curtain from my phone with an ESP32?
The ESP32 joins your home network and serves a small web page. Open the ESP32's IP address in your phone's browser and you'll see Open, 50% and Close buttons. To reach it from outside your home, you need to add MQTT or a cloud service.
How do I connect my Arduino curtain to Alexa?
The Espalexa library makes an ESP32 appear on your local network as a dimmable light, so the curtain shows up when you search for devices in the Alexa app. The 0–255 value Alexa sends is converted into the curtain's open percentage in the code. Since the Arduino Uno has no Wi-Fi, this is done with an ESP32 or ESP8266.
Projects to build after reading this
See all projects
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.

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

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.

Using a Stepper Motor
A motor that turns step by step, exactly as far as you want, like the hand of a clock.

360-Degree Servo from a Stepper Motor
Teach an ordinary stepper motor to go to any angle you want, all the way around the circle.

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

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.

ESP32 Asynchronous Web Server (with IP Display on LCD)
In this project, we’re turning the ESP32 into an asynchronous web server that you can control from your phone or computer on the same Wi-Fi network. Thanks to the ESPAsyncWebServer library, the server can process multiple requests simultaneously (unlike the classic WebServer.h, which blocks on a single request). You’ll be able to open the ESP32’s IP address in a browser and click the ON/OFF buttons (the /on and /off routes) to turn the LED connected to GPIO 5 on and off.
More articles
BlueGrays app
Build this circuit step by step on your phone
Wiring diagram, code and parts list on one screen. 500+ Arduino, ESP32, ESP8266, Pico, mBot and micro:bit projects ready to build.
Scan with your phone
Point your camera at the code and your phone's app store opens.
or open the store

