2022-12-29 02:57:16 +00:00
|
|
|
#include <Wire.h>
|
|
|
|
#include <LiquidCrystal_I2C.h>
|
2022-12-29 03:25:00 +00:00
|
|
|
#include <DHT.h>
|
2023-01-15 23:38:29 +00:00
|
|
|
#include <BH1750.h>
|
2022-12-29 03:25:00 +00:00
|
|
|
|
2022-12-29 02:57:16 +00:00
|
|
|
#define DHT11_PIN 7
|
2023-01-15 23:38:29 +00:00
|
|
|
#define photoL1 A0
|
2022-12-29 02:57:16 +00:00
|
|
|
#define LED 3
|
|
|
|
#define button 2
|
|
|
|
#define buzzer 6
|
|
|
|
|
2023-01-15 23:38:29 +00:00
|
|
|
BH1750 lightMeter;
|
2022-12-29 03:25:00 +00:00
|
|
|
DHT dht(DHT11_PIN, DHT11);
|
2022-12-29 02:57:16 +00:00
|
|
|
volatile int buttonState;
|
2023-01-15 23:38:29 +00:00
|
|
|
volatile int lightReadL1 = 0;
|
2022-12-29 02:57:16 +00:00
|
|
|
int count;
|
|
|
|
LiquidCrystal_I2C lcd(0x27, 16, 2);
|
|
|
|
|
|
|
|
void setup()
|
|
|
|
{
|
|
|
|
Serial.begin(9600);
|
|
|
|
Serial.print("setting up!\n");
|
|
|
|
pinMode(LED, OUTPUT); //initialize digital pin LED as an output.
|
|
|
|
pinMode(button, INPUT);
|
|
|
|
pinMode(buzzer, OUTPUT);
|
|
|
|
Serial.print("init lcd\n");
|
|
|
|
lcd.init();
|
|
|
|
lcd.backlight();
|
|
|
|
lcd.setCursor(0,0);
|
|
|
|
lcd.printstr("Hello, World!");
|
|
|
|
lcd.setCursor(0,1);
|
|
|
|
lcd.printstr("hello, Roald!");
|
2022-12-29 03:25:00 +00:00
|
|
|
|
2022-12-29 03:58:04 +00:00
|
|
|
dht.begin(20);
|
2022-12-29 03:25:00 +00:00
|
|
|
|
2022-12-29 02:57:16 +00:00
|
|
|
Serial.print("done setting up!\n");
|
2023-01-26 23:30:22 +00:00
|
|
|
//Intialize the 12C bus
|
|
|
|
Wire.begin();
|
|
|
|
//On esp8266 you can select SCL and SDA pins using Wire.begin
|
|
|
|
//For Wemos /Lolin D1 Mini Pro and the Ambient Light shield use
|
|
|
|
Wire.begin();
|
|
|
|
lightMeter.begin();
|
|
|
|
Serial.println(F("BH1750 Test begin"));
|
2022-12-29 02:57:16 +00:00
|
|
|
}
|
|
|
|
|
2023-01-26 23:30:22 +00:00
|
|
|
void loop(){
|
2022-12-29 03:58:04 +00:00
|
|
|
//Serial.print("[");
|
|
|
|
//Serial.print(count);
|
|
|
|
//Serial.print("] hey\n");
|
|
|
|
|
2023-01-15 23:38:29 +00:00
|
|
|
lightReadL1 = analogRead(photoL1);
|
|
|
|
if (lightReadL1 > 300){
|
2022-12-29 03:58:04 +00:00
|
|
|
digitalWrite(LED, HIGH);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
digitalWrite(LED, LOW);
|
|
|
|
}
|
2022-12-29 02:57:16 +00:00
|
|
|
|
2023-01-26 23:30:22 +00:00
|
|
|
float lux = lightMeter.readLightLevel();
|
|
|
|
float hum = dht.readTemperature();
|
|
|
|
float temp = dht.readHumidity();
|
2022-12-29 02:57:16 +00:00
|
|
|
{
|
2023-01-26 23:30:22 +00:00
|
|
|
Serial.print("hum: ");
|
2022-12-29 03:25:00 +00:00
|
|
|
Serial.print(hum);
|
2023-01-26 23:30:22 +00:00
|
|
|
Serial.print(" temp: ");
|
2022-12-29 03:58:04 +00:00
|
|
|
Serial.print(dht.convertCtoF(temp));
|
2023-01-26 23:30:22 +00:00
|
|
|
Serial.print(" L1: ");
|
|
|
|
Serial.print(lightReadL1);
|
|
|
|
Serial.print(" PanL: ");
|
|
|
|
Serial.print(lux);
|
|
|
|
Serial.println("lx");
|
2022-12-29 03:58:04 +00:00
|
|
|
delay(50);
|
2022-12-29 02:57:16 +00:00
|
|
|
}
|
2022-12-29 03:25:00 +00:00
|
|
|
|
2022-12-29 03:58:04 +00:00
|
|
|
//delay(100);
|
2022-12-29 02:57:16 +00:00
|
|
|
|
|
|
|
//blink();
|
|
|
|
|
|
|
|
buttonState = digitalRead(button);
|
|
|
|
if(buttonState == 0) {
|
|
|
|
digitalWrite(LED, HIGH);
|
|
|
|
birthdaySong();
|
|
|
|
} else {
|
|
|
|
digitalWrite(LED, LOW);
|
|
|
|
}
|
2022-12-29 03:58:04 +00:00
|
|
|
//delay(100);
|
2022-12-29 02:57:16 +00:00
|
|
|
|
2022-12-29 03:58:04 +00:00
|
|
|
//count++;
|
2022-12-29 03:25:00 +00:00
|
|
|
}
|
2022-12-29 02:57:16 +00:00
|
|
|
|
|
|
|
void birthdaySong() {
|
|
|
|
tone(buzzer, 294);
|
|
|
|
delay(250);
|
|
|
|
tone(buzzer, 440);
|
|
|
|
delay(250);
|
|
|
|
tone(buzzer, 392);
|
|
|
|
delay(250);
|
|
|
|
tone(buzzer, 532);
|
|
|
|
delay(250);
|
|
|
|
tone(buzzer, 494);
|
|
|
|
delay(500);
|
|
|
|
tone(buzzer, 392);
|
|
|
|
delay(250);
|
|
|
|
tone(buzzer, 440);
|
|
|
|
delay(250);
|
|
|
|
tone(buzzer, 392);
|
|
|
|
delay(250);
|
|
|
|
noTone(buzzer);
|
|
|
|
tone(buzzer, 587);
|
|
|
|
delay(250);
|
|
|
|
tone(buzzer, 532);
|
|
|
|
delay(500);
|
|
|
|
tone(buzzer, 392);
|
|
|
|
delay(250);
|
|
|
|
tone(buzzer, 784);
|
|
|
|
delay(250);
|
|
|
|
tone(buzzer, 659);
|
|
|
|
delay(250);
|
|
|
|
tone(buzzer, 532);
|
|
|
|
delay(250);
|
|
|
|
tone(buzzer, 494);
|
|
|
|
delay(250);
|
|
|
|
tone(buzzer, 440);
|
|
|
|
delay(250);
|
|
|
|
tone(buzzer, 698);
|
|
|
|
delay(375);
|
|
|
|
tone(buzzer, 659);
|
|
|
|
delay(250);
|
|
|
|
tone(buzzer, 532);
|
|
|
|
delay(250);
|
|
|
|
tone(buzzer, 587);
|
|
|
|
delay(250);
|
|
|
|
tone(buzzer, 532);
|
|
|
|
delay(500);
|
|
|
|
noTone(buzzer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void blink()
|
|
|
|
{
|
|
|
|
digitalWrite(LED,HIGH); //turn the LED on (HIGH is the voltage level
|
|
|
|
delay(1000); //wait for a second
|
|
|
|
digitalWrite(LED,LOW); //turn the LED off by making the voltage LOW
|
|
|
|
delay(1000); //wait for a second
|
|
|
|
}
|