Hardware components | ||||||
| × | 1 | ||||
| × | 1 | ||||
| × | 1 | ||||
| × | 1 | ||||
| × | 1 | ||||
Software apps and online services | ||||||
|
I have built an light depended alarm clock using arduino nano, RTC module, ISD module, LDR, button, etc
all of the details are in the video
you are more than welcom to ask me here or in private anything.
#include <DS3231.h>
#define Hour 7 //define hour to wake up
#define minute 0 //define minute to wake up
// Init the DS3231 using the hardware interface
DS3231 rtc(SDA, SCL); //set up RTC module
int Shout = 7; //this is connected to the ISD module
int Butt = 6; //this is the button
int Light = A0; //LDR
bool Stop; //Bool to stop screaming
long Read; //to read LDR analog value
Time t; //from the Library
void setup()
{
Serial.begin(115200); //just for debug. not important
pinMode(Shout,OUTPUT); //define inputs and outputs
pinMode(Butt,INPUT);
rtc.begin(); //from library
Stop = false; //Scream at mE!!! (not yet)
}
void loop()
{
t = rtc.getTime(); //get the time from RTC module
if(rtc.getDOWStr()!= "FRIDAY" &&rtc.getDOWStr()!= "SATURSDAY")//unless its the weekend!
{
if((t.hour)== Hour && (t.min) == minute ) //when Time as come...
{
while(Stop==false) //as long as the Bool is false (starting poin is false)
{
Read = analogRead(Light); //read analog value
digitalWrite(Shout,HIGH); //the routine to oparate scream flow
delay(20);
digitalWrite(Shout,LOW);
if((t.hour)== Hour && (t.min) == (minute+20))//if it lastad for more than 20 minutes
Stop=true; //Stop screaming at me!!
if(digitalRead(Butt)==1 && Read >=905)//if the button is Pressed AND the light is ON!
Stop=true; // STOP THIS MADDNESSSSSS
}
delay(80000);
Stop=false; //get ready to start again tomorrow!
}
Serial.print(rtc.getDOWStr());
Serial.print(" ");
// Send date
Serial.print(rtc.getDateStr());
Serial.print(" -- ");
// Send time
Serial.println(rtc.getTimeStr());
// Wait one second before repeating :)
delay (1000);
/* SET this to change time! do this if u didn't set the RTC time
if(digitalRead(Butt))
{
rtc.setDOW(MONDAY); // Set Day-of-Week to MONDAY
rtc.setTime(19,35, 0); // Set the time to 19:35:00 (24hr format)
rtc.setDate(8, 4, 2019); // Set the date to april 8, 2019
}
*/
}
}
Comments