#include <Wire.h>
#include <LiquidCrystal.h>
#include "RTClib.h"
#include "pitches.h"
#define LDR_PIN A0
#define SPEAKER_PIN 6
// These constants should match the photoresistor's "gamma" and "rl10" attributes
const float GAMMA = 0.7;
const float RL10 = 50;
RTC_DS1307 rtc;
char daysOfTheWeek[7][12] = {"Sun", "Mon", "Tues", "Wed", "Thur", "Fri", "Sat"};
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
void setup()
{
Serial.begin(115200);
//kill function
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
abort();
}
//pin mdoes
pinMode(LDR_PIN, INPUT);
pinMode(LED_BUILTIN, OUTPUT);
pinMode(4, OUTPUT);
pinMode(SPEAKER_PIN, OUTPUT);
Wire.begin();
// Initializes the LCD
lcd.begin(1, 1);
}
void loop()
{
int analogValue = analogRead(A0);
float voltage = analogValue / 1024. * 5;
float resistance = 2000 * voltage / (1 - voltage / 5);
float lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA));
DateTime now = rtc.now();
lcd.print(daysOfTheWeek[now.dayOfTheWeek()]);
lcd.print(" ");
lcd.print(now.hour(), DEC);
lcd.print(':');
lcd.print(now.minute(), DEC);
lcd.print(':');
lcd.print(now.second(), DEC);
delay(1000);
lcd.clear();
delay(0.000000000000000000001);
if (lux >= 400) {
digitalWrite(LED_BUILTIN, HIGH);
tone(SPEAKER_PIN, NOTE_G4);
delay(250);
tone(SPEAKER_PIN, NOTE_C5);
delay(250);
tone(SPEAKER_PIN, NOTE_G4);
delay(250);
tone(SPEAKER_PIN, NOTE_C5);
delay(250);
tone(SPEAKER_PIN, NOTE_C4);
delay(1000);
noTone(SPEAKER_PIN);
digitalWrite(LED_BUILTIN, LOW);
} else {
return;
}
}
nano1:12
nano1:11
nano1:10
nano1:9
nano1:8
nano1:7
nano1:6
nano1:5
nano1:4
nano1:3
nano1:2
nano1:GND.2
nano1:RESET.2
nano1:0
nano1:1
nano1:13
nano1:3.3V
nano1:AREF
nano1:A0
nano1:A1
nano1:A2
nano1:A3
nano1:A4
nano1:A5
nano1:A6
nano1:A7
nano1:5V
nano1:RESET
nano1:GND.1
nano1:VIN
nano1:12.2
nano1:5V.2
nano1:13.2
nano1:11.2
nano1:RESET.3
nano1:GND.3
lcd1:VSS
lcd1:VDD
lcd1:V0
lcd1:RS
lcd1:RW
lcd1:E
lcd1:D0
lcd1:D1
lcd1:D2
lcd1:D3
lcd1:D4
lcd1:D5
lcd1:D6
lcd1:D7
lcd1:A
lcd1:K
r1:1
r1:2
ds1:GND
ds1:5V
ds1:SDA
ds1:SCL
ds1:SQW
wokwi-photoresistor-sensor-1:VCC
wokwi-photoresistor-sensor-1:GND
wokwi-photoresistor-sensor-1:DO
wokwi-photoresistor-sensor-1:AO
wokwi-buzzer-1:1
wokwi-buzzer-1:2