Sunlight Detection Alarm




Most technology Instructables are fun to construct, and often easy to build. This is one that shares those features, but also solves a practical problem we had.

To prevent fading of furniture, carpet, and the wood flooring in our foyer, my spouse and I installed one-way blackout shades. However, after installation and use, a problem arose. The air in the foyer began to have a slightly “musty” odor as no sunlight was coming in. My solution was to build a direct sunlight detector, allowing us to close the shades only when the buzzer went off. On overcast days the shades would stay open, as the direct sunlight would not set the alarm off (we live in the Eastern US, so overcast days are not uncommon). It also meant that we could leave the shades open until we heard the alarm on clear days. The result – all the “mustiness” is now gone and as a bonus the foyer is less “gloomy”. A quick, inexpensive and winning solution on all counts. The video shows the alarm "in action".

Like many readers and posters here, I really like LEDs and so have added one to this project. However, it is optional and not a requirement.

Step 1: What's Needed

Required Items

- 95DB 3-24v High-decibel Electronic Buzzer

- An Experimental Prototype Board

- A Half-Size, 400 tie points, Breadboard

- An Arduino UNO R3

- A 10k Resistor (1/4 to 1 Watt)

- A photoresistor, almost any will do (e.g., 112582, 5516, 5528, 5537, 5539, or 5549)

Optional Items

- Two Pieces Heat Shrink Wire Wrap (Size 2.5 x 40mm)

- An LED (any color in 3mm, 5mm, or 10mm size)

- A 2k Resistor (1/4 to 1 Watt)

The optional items are just that. While I used shrink wrap to cover the solder joints to the buzzer, black electrician’s tape should work just as well. I added the LED so that in addition to the sound of the alarm it would blink on and off when direct sunlight was detected. However, since the high-decibel alarm goes off when this is the case, the LED and its 2k resistor can be left off without any lose in detection function.

Step 2: Connecting the Arduino UNO and Half-Size Breadboard to the Experimental Platform.

See my earlier Instructable, “Experimental Platform For the Arduino UNO R3 - How To Prepare It For Use“, at to see how this can be easily done.

Step 3: Alarm Wires

I removed the plastic cover on one side of a red Dupont male-to-male cable and soldered the pin to the red lead from the alarm. I did the same thing with a dark blue Dupont cable and soldered it to the black wire from the alarm. I covered both solder joints with heat shrink wire wrap (see 1st photograph), although as noted above black electrician’s tape will work as well. I connected the red wire to the breadboard and then, using an additional jumper cable, connected that wire to digital socket two of the Arduino Uno

That is,

- Red wire from alarm to digital socket 2 on UNO

I connected the black wire from the alarm to the ground rail on the breadboard which went to a GND pin on the UNO.

That is,

- Black wire from alarm to GND socket on UNO

Step 4: Adding the Optional LED

The positive side of the LED is connected to digital socket 12 of the Arduino UNO, and the negative side is connected through a 2k resistor to a UNO GND socket.

I do not like excessively bright, to me, LEDs so I used a 2k resistor here. If you do not mind, or you would like, a brighter LED you may want to use a 330-560 ohm resistor instead of the 2k one I used.

That is,

- Long wire on LED to UNO digital socket 12

- Short wire on LED, going through a 2k resistor, to UNO GND socket.

Step 5: Adding the Photoresistor

I used a T5516, but as noted above almost any photosensitive resistor will do. One side of the photoresistor goes to 5v on the Arduino. The other side goes through a 10k resistor to a GND socket on the Arduino. I connected a wire from GND on the Arduino UNO to the negative rail on the breadboard and used it for all my ground connections. The 10k resistor and photoresistor formed a voltage divider. I took the location on the breadboard where the photoresitor connected to one side of the 10k resistor and connected it to analog socket A1 to be able to obtain photoresistor measurements of the light.

That is,

- One side of the photoresistor to 5v on the UNO

- The other side of the photoresistor connects on the breadboard to a 10k resistor and then that resistor goes to ground.

- Lastly, the location where the photoresistor and 10k resistor join was connected to UNO analog socket A1.

Interesting discussions, about photoresistors can be found in the Instructables, "How to use a Photoresistor (or photocell) - Arduino Tutorial" by codebender_cc and "Photoresistors" by OlaC.

Step 6: The Sketch

Enter the sketch below into the Arduino IDE, and run it.

int photoresistorPin = A1; // Photoresistor pin connection

int ledPin = 13; // LED pin connection

int dacValue = 0; // Store the value read from the sensor

int buzzerPin = 2; // Buzzer pin connection

unsigned int x=65535; // Stores mapped dac value (ranges from 0 - 100%)

void setup() {

pinMode(ledPin, OUTPUT);

pinMode(buzzerPin, OUTPUT);

pinMode(photoresistorPin, INPUT);


void loop() {

dacValue = analogRead(photoresistorPin);

x = map(dacValue, 0, 1023, 0, 65000);

x = round(x/650.0); // To obtain a range from 0 to 100


if(x >= 95) {

digitalWrite(buzzerPin, HIGH);

digitalWrite(ledPin, HIGH);


digitalWrite(ledPin, LOW);



if(x< 94) digitalWrite(buzzerPin, LOW);


Step 7: Afterwards

The last picture shows the assembled detection alarm systems in the foyer from somewhat of a distance. The first photograph shows an assembled system close-up. I powered my UNO using a 9v DC "wall wart". However, power can be provided to the UNO in a variety of other ways, including battery if you need a portable sunlight detector. Depending on where you place this alarm, and the photoresistor you use, you may want to change the value of 95 used in the sketch. This value represents the threshold, out of a total of 100, at which the alarm goes off.

That is all there is to it; it is as simple as it seems. If you leave off the LED and associated resistor, not really required to detect direct sunlight, the alarm is even easier to construct.

Congratulations, if you followed the steps above you now have your own sunlight detection alarm.

If you would like to contact me with any questions or for additional information, or to expand my knowledge in the area presented, I can be reached at (please replace the second 'i' with an 'e' to contact me.



    • Frozen Treats Challenge

      Frozen Treats Challenge
    • 1 Hour Challenge

      1 Hour Challenge
    • Sensors Contest

      Sensors Contest

    12 Discussions


    2 years ago

    Nice project! I'm just curious about these two lines:

    x = map(dacValue, 0, 1023, 0, 65000);

    x = round(x/650.0); // To obtain a range from 0 to 100

    Why not just use a single map function with 0 to 100 as the target values?

    x = map(dacValue, 0, 1023, 0, 100);


    1 reply

    Thank you for your interest and question.

    You can map the result of the analogRead() to 0-100, and considering how I use the results, that would likely work. However, to quote “”, “The map() function uses integer math so will not generate fractions, when the math might indicate that it should do so. Fractional remainders are truncated, and are not rounded or averaged.”

    The very best.

    R Jordan KreindlerThrone85

    Reply 2 years ago

    Thank you for taking the time to post your kind comments. They are appreciated.

    The very best.


    2 years ago

    Interesting reason for building this project. Now that you have it proto-typed, why don't you incoropate it into some motor driven shades and have your circuit control everything? Just a suggestion. Thumbs Up.

    3 replies
    R Jordan Kreindlergm280

    Reply 2 years ago

    Thank you for taking the time to send this message and the kindness of your note. It is appreciated.

    We had considered this extension to the project but have not yet found a way to hide the motor and wires.

    The very best.

    gm280R Jordan Kreindler

    Reply 2 years ago

    Have you looked at planetary gear motors that would easily go on the inside of a blind sleeve setup and the only thing you would have to control would be the distance it would travel/run. Maybe a stepper motor configuration with a planetary geared motor in the sleeve then you can count the steps for any position and make presets. IDK, just thinking out my self.

    R Jordan Kreindlergm280

    Reply 2 years ago

    Thank you for the follow-up.

    A planetary gear motor would work at the voltages we would use,
    and provide the torque required at the speed needed. Unfortunately, although possibly reducing the footprint of the needed components, it would not eliminate the need to hide motors and wires.

    Our shades are not the conventional “Venetian Blinds” but shades whose height is controlled by a chain loop with plastic stops for height control. With four shades across the entrance, hiding is difficult but would be required. The “cornice” above these shades is quite small being only large enough to conceal the shades when not in use.

    However, we would be pleased to consider your suggestions in more detail, and perhaps we will find a solution to the “hiding” issue. If so, we would be happy to post it as a follow-up Instructable.

    Thank you again for your comment, and the very best.

    P.S. I have now included a video in this Instructable to show the alarm in use.