Open/close skylight + rain sensor failsafe

Hi all,

I'm new to the Arduino community and, before I take on my first project, I wanted to run my idea past the experts.

I recently moved into an apartment on the top floor of a nine-story building. On a nice day, it gets pretty warm, and there's no A/C. Fortunately there's a skylight that opens to vent some of the heat, however; the ceilings are fairly high, and the skylight can only be opened using a 15 ft. pole, which fits into a socket, forming a vertical crank. I'd like to reduce that to flipping an open/close switch. I also need to factor in a way for the unit to sense moisture so that, if it starts raining, it closes the skylight automatically.

My idea is to use an Arduino board to control a continuous rotation servo motor, then attach that to the crank socket. I imagine I could attach a potentiometer to control it...? I would also attach a moisture sensor to the board that, when triggered, would run the same code as the off position of the potentiometer.

Is that possible? Is there anything that would work better as an on/off switch than a potentiometer? Rookie question, but after it's all programmed, the Arduino can operate independently from a computer, right?

Any insight or links that will point me in the right direction would be greatly appreciated!

You must have a very small skylight (the size of one that would be in a dollhouse) or an unusually large servo motor ....


Hmm... I haven't worked with servo motors before. I take it they're not very powerful... Are there any other types of motors that would be more appropriate?

I can't really picture how your system works but if you have to push this pole that will be difficult to replicate because a lot of force would be required I think.

One gadget that would do it is a "linear actuator", look them up.

As for rain detection, there must be existing "sensors" that do this. Have a look for things used with weather stations, they often have tipping bucket things for measuring rain fall, you could use one to detect any rain (if it's sensitive enough to very small amounts).


The pole he refers to is likely the end of a threaded rod, basically a nut on the rod goes up & down with the window, or perhaps moves an arm on a lever. Either way, just need to spin it back & forth. Microswitch on the ends to prevent over turning, or a sensor to keep track of # of revolutions, store in EEPROM in case of power loss. As for detecting rain, reallly need to decide how hard it has to come down before you decide to close. Will a couple of probes sitting in the bottom of a cup shorted together with water do it? Maybe a heavier rain in a slow leak cup lifting up a float?

So pretty much replace this with a motor:|0||p_product_qty_sales_dollar|1&pl=1¤tURL=%2Fpl_Skylights%2B_4294858054_4294937087_%3FNs%3Dp_product_prd_lis_ord_nbr%7C0%7C%7Cp_product_qty_sales_dollar%7C1&facetInfo=

Thanks! Great ideas.

Graynomad - I looked up linear actuators and I believe what I need is some sort of electric motor to generate rotary motion. I got on the ladder to see what kind of force is required to turn the socket, and it doesn't seem too bad. It turns relatively easily by hand. Do you know of an electric motor that works well with Arduino boards?

Microswitch on the ends to prevent over turning, or a sensor to keep track of # of revolutions, store in EEPROM in case of power loss.

CrossRoads - I hadn't thought of this. Thank you! What type of sensor would measure the # of rotations? I haven't delved into the coding aspect yet, so forgive my ignorance, but could I have the sensor's input into the Arduino board act as a variable in the code that will control the motor? So the logic would be something to the effect of: Upon activation of the "open" switch, rotate the motor clockwise until the sensor's input value = 7000 degrees, then stop.

Would a microswitch work along the same lines as the dial on an electric screwdriver/drill that let's you specify the amount of torque to apply?

Any electric motor can be made to work with the right collection of transistors, relays, or H-Bridge if you want to go in two directions. An example which would work okay since you don't need variable speed or anything. Maybe mount a power drill to the end of the shaft?

Maybe something like this doesn't turn too fast, should be not too complicated to couple onto your existing shaft

  1. Sensor - how about a simple tab on the shaft that closes a microswitch every time it goes by? (Assuming the electronics on the motor above can't be adpated) Or a magnet that closes a reed switch? Or a mirror that reflects light back to an optical sensor? Or ...
  2. Yes.
  3. Yes.
  4. No. Microswitch can only give you a 1/0 back. I would suggest current sensing for torque (measure voltage drop across a shunt), when you see the current rise to known full open/full shut point, stop driving! Here is some shunt examples, you'

Ok i'm also new to arduino and wanted the same start project for the arduino for my house XD

i'm thinking of using a ac 230 motor to turn left and right the crank of the skylux thinking on this motor.

The only problem is for me how to turn a 230 motor left and right using arduino XD

picture motor below here XD technical of the motor

the motor:

sorry for the dutch pages but i'm from belgium and this motor should cost 300 €

so if someone could guide me trough the project XD

thx in advanced

If it is possible to access the skylight, I’d go with the linear actuator. They have internal limit switches and ones like below have internal feedback pots. If just open/closed is needed the below light duty actuator could be used. These probably could be simply controlled using a pair of relays like bottom.

So these are 12V Dc motors and therefore you can use the H-Bridge Right?

Thx for showing me this motor :-) now ionly need to find them here in Belgium or where i can order them thx Xd

I implemented a similar project using three relays and a couple of limit switches. This was to power a chicken coop door but the basic principle is the same.

Also, most relay shields are active LOW so you’d probably have to alter the logic if you use it on a conventional relay board.

The motor I used was out of an old cordless drill (actually rated at 18v but it performed OK with just 12v).

This is the circuit I used. The limit switches make it fool proof in operation and also provide feedback. I also included the third relay to disable the whole circuit when not being used, to allow manual operation of the door.


this is as far i get

#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
#define REQ_BUF_SZ 20
File webFile;
char HTTP_req[REQ_BUF_SZ] = {0}; // buffered HTTP request stored as null terminated string
char req_index = 0; // index into HTTP_req buffer
byte mac = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA };
IPAddress ip(192, 168 , 0, 177);
EthernetServer server(8100);

int regensensor = 6;
int K1K4 = 7;
int K2K3 = 8;

int motorcheck = 0;
int teller = 0;
int safetyswitch = 4000;
int regencheck = 0;

void setup() {
pinMode(regensensor, INPUT);
pinMode(K1K4, OUTPUT);
pinMode(K2K3, OUTPUT);
digitalWrite(K1K4, HIGH);
digitalWrite(K2K3, HIGH);
Ethernet.begin(mac, ip);
Serial.println(“Initializing SD card…”);
if (!SD.begin(4)) {
Serial.println(“ERROR - SD card initialization failed!”);
return; // init failed
Serial.println(“SUCCESS - SD card initialized.”);
if (!SD.exists(“index.htm”)) {
Serial.println(“ERROR - Can’t find index.htm file!”);
Serial.println(“SUCCESS - Found index.htm file.”);
Serial.println(“You have now control trough”);

void loop() {
regencheck = digitalRead(regensensor);
EthernetClient client = server.available(); // try to get client
if (client) { // got client?
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) { // client data available to read
char c =; // read 1 byte (character) from client
// buffer first part of HTTP request in HTTP_req array (string)
// leave last element in array as 0 to null terminate string (REQ_BUF_SZ - 1)
if (req_index < (REQ_BUF_SZ - 1)) {
HTTP_req[req_index] = c; // save HTTP request character
Serial.print(c); // print HTTP request character to serial monitor
// last line of client request is blank and ends with \n
// respond to client only after last line received
if (c == ‘\n’ && currentLineIsBlank) {
// send a standard http response header
client.println(“HTTP/1.1 200 OK”);
client.println(“Content-Type: text/html”);
client.println(“Connnection: close”);
// open requested web page file
if (StrContains(HTTP_req, "GET / ")

|| StrContains(HTTP_req, “GET /index.htm”)) {
motorcheck = 0;
webFile =“index.htm”);
else if (StrContains(HTTP_req, “GET /omhoog.htm”)) {
motorcheck = 1;
webFile ="/omhoog.htm"); // open web page file
else if (StrContains(HTTP_req, “GET /omlaag.htm”)) {
motorcheck = 2;
webFile ="/omlaag.htm"); // open web page file
else if (StrContains(HTTP_req, “GET /stop.htm”)) {
motorcheck = 0;
webFile ="/stop.htm"); // open web page file
if (webFile) {
while (webFile.available()) {
// reset buffer index and all buffer elements to 0
req_index = 0;
StrClear(HTTP_req, REQ_BUF_SZ);
// every line of text received from the client ends with \r\n
if (c == ‘\n’) {
// last character on line of received text
// starting new line with next character read
currentLineIsBlank = true;
else if (c != ‘\r’) {
// a text character was received from client
currentLineIsBlank = false;
} // end if (client.available())
} // end while (client.connected())
delay(2); // give the web browser time to receive the data
client.stop(); // close the connection
} // end if (client)

void StrClear(char *str, char length)
for (int i = 0; i < length; i++) {
str = 0;

  • }*
    char StrContains(char *str, char *sfind)
  • char found = 0;*
  • char index = 0;*
  • char len;*
  • len = strlen(str);*
  • if (strlen(sfind) > len) {*
  • return 0;*
  • }*
  • while (index < len) {*
  • if (str[index] == sfind[found]) {*
  • found++;*
  • if (strlen(sfind) == found) {*
  • return 1;*
  • }*
  • }*
  • else {*
  • found = 0;*
  • }*
  • index++;*
  • }*
  • return 0;*
    void mcheck()
  • if (motorcheck == 0 ) {*
  • digitalWrite(K1K4, HIGH);*
  • digitalWrite(K2K3, HIGH);*
  • }*
  • if (motorcheck == 1 ) {*
  • if (teller == safetyswitch)*
  • {*
  • digitalWrite(K1K4, HIGH);*
  • digitalWrite(K2K3, HIGH);*
  • }*
  • if (teller >= 0 && teller < safetyswitch && regencheck == 1 ) {*
  • digitalWrite(K1K4, LOW);*
  • teller = teller + 1;*
  • }*
  • }*
  • if (motorcheck == 2) {*
  • if (teller == 0)*
  • {*
  • digitalWrite(K1K4, HIGH);*
  • digitalWrite(K2K3, HIGH);*
  • }*
  • if (teller <= safetyswitch && teller > 0 && regencheck == 1 ) {*
  • digitalWrite(K2K3, LOW);*
  • teller = teller - 1;*
  • }*
  • }*
  • if (regencheck == 0 ){*
  • if (teller > 0){*
  • digitalWrite(K2K3, LOW);*
  • teller = teller -1;*
  • }*
  • }*
    the last raincheck isn’t right
    still working on that
    working indeed with the h bridge 4 relay contactors over a dc motor

this is as far i get

#7 below:,148850.0.html