Sunrise Alarm Clock

by SunriseAlarmClock in Circuits > Arduino

33 Views, 0 Favorites, 0 Comments

Sunrise Alarm Clock

Screenshot 2024-12-09 161321.png

The sunrise alarm clock's primary function is to raise and lower blinds in the morning. To achieve this function place the clock by the window attached to the blinds. When the sunrises in the morning the clock motor will raise the blinds waking up the customer. When the photosensor detects darkness it will lower the blinds.

Supplies

Screenshot 2024-12-09 161027.png

**All supplies can be found in the Sparkfun kit**

• Arduino Uno

• Small Breadboard

• Wires (13)

• Photoresistor

• Hobby Gearmotor

• Motor Driver

• resistor

• Cardboard and Ducktape

Summary of Project (Poster):

Poster summarizing and explaining the project

Build Instructions

1) Gather materials to make a box (we used cardboard and tape).

2) Make the dimensions of box approx. the size of your Arduino and breadboard.

3)Make a hole to wire the power cord through.

4) Make a hole for the gear motor.

5) Make sure you leave a way for light to get through to the photoresistor (we left the top open).

6) Tie your blind string to the gearmotor by taping, gluing, or tying it.


Electrical Wiring

Screenshot_9-12-2024_1607_kansas.sharepoint.com.jpeg
messy diagram.png

The 1st picture is how to wire the gearmotor and the 2nd is of the photogoniometer and how to wire the gearmotor in Tinkercad.

Code

The code consists of many different aspects that tell the Arduino what specifically it should be looking for and what operations it should be doing. These two aspects can be combined within the code to form certain conditions. When writing code that anyone will read make sure to add comments with the characters “//” and your comment explaining the purpose of that are of code


In the language of C++, which is what we are using, variable have to be declared before being used. The declaration can be made while assigning a value or just leaving it as an unassigned value. Here below is the calibration portion of our establishment of variables. These are the ones that can be changed based on certain preferences, such as how long the motor runs depending on the length of the blinds.


//These can be changed based on preferences.

int lightThreshold = 100; // Adjust this value based on testing in sunlight conditions

int moterTimeRun = 5000; // Run motor for 5000 milliseconds (5 seconds)

int motorOffTime = 43200000; // Turns off motor for 12 hours (time is in milli-seconds)


These here are the pin variables. The first purpose is so the coder does not have to put in a certain number whenever calling on the pins. The pins are what are going to be registering any devices within the system, in this case a motor (AIN1, AIN2, PWMA) and our photoresistor (lightsensorpin). The other purpose is to provide information on where the wires should be set up if the need to rebuild or adjust the system arises.


int AIN1 = 13;

int AIN2 = 12;

int PWMA = 11;

int lightSensorPin = A1; // Pin for the light sensor


The above portion was declaring variables for the entire code, if declared within a function such as the one below it will only exist when that function is running. The function below is one of two standard functions that C++ starts with (setup and loop). This is commonly used for assigning pins and starting the serial monitor.


void setup() {


This is establishing the pins as either output pins or input pins (in this case only output pins). The photoresistor pin does need to be established because it’s an analog reader. A way to tell the difference is if the sensor has a gradient of values, it most likely will be analong.


pinMode(AIN1, OUTPUT);

pinMode(AIN2, OUTPUT);

pinMode(PWMA, OUTPUT);


This starts with the serial monitor which allows the Arduino to send values back to the computer, which is helpful in debugging and creating code that goes outside the Arduino system.


Serial.begin(9600);

}


This is the loop function, like the name suggests it will continue to run as long as the Arduino has power.


void loop() {


This is the process of reading the photoresistor, assigning it to a variable declared earlier, and serial printing to allow for debugging and information to be seen. Notice that the photoresistor, which uses an analog pin also uses analog read to read the value.


// Read light sensor data

int lightValue = analogRead(lightSensorPin);

// Print light sensor value to the serial monitor

Serial.print("Light sensor value: ");

Serial.println(lightValue);

// Control motor based on light sensor


This is the condition with the code that checks if the light has passed the light threshold to trigger the motor. If the value is higher than the threshold the code continues down the line, if not it jumps to next condition or else statement.


if (lightValue > lightThreshold) {


This is setting the motors to run forwards. The AIN values set the direction and the PWMA sets the speed. The delay is how long the motor runs followed by a stanza code that stops the motor and waits for a long time until allowing the code to continue.


// Spin motor forwards when sunlight is detected

digitalWrite(AIN1, HIGH);

digitalWrite(AIN2, LOW);

analogWrite(PWMA, 255); // Full speed for the motor

delay(moterTimeRun);

// Stop the motor

digitalWrite(AIN1, LOW);

digitalWrite(AIN2, LOW);

analogWrite(PWMA, 0);

delay(motorOffTime);

}


This else statement just stops the motor if it was running and then waits a second to keep things from overloading or moving too fast


else {

// Stop the motor

digitalWrite(AIN1, LOW);

digitalWrite(AIN2, LOW);

analogWrite(PWMA, 0);

}

delay(1000); // Delay to stabilize readings

}


Video