From 38affc3c98870a811c1bc58e814a3289534d1526 Mon Sep 17 00:00:00 2001 From: Roald Batts Date: Wed, 28 Dec 2022 21:57:16 -0500 Subject: [PATCH] working on the humidity sensor --- soler_chager.ino | 136 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 soler_chager.ino diff --git a/soler_chager.ino b/soler_chager.ino new file mode 100644 index 0000000..2825473 --- /dev/null +++ b/soler_chager.ino @@ -0,0 +1,136 @@ +#include +#include +#include +#define DHT11_PIN 7 +#define photos A0 +#define LED 3 +#define button 2 +#define buzzer 6 + +volatile int buttonState; +volatile int value = 0; +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!"); + Serial.print("done setting up!\n"); +} + +void loop()// the loop function runs over and over again forever +{ + Serial.print("["); + Serial.print(count); + Serial.print("] hey\n"); + + int chk; + chk = DHT.read(DHT11_PIN); + switch (chk) { + case DHTLIB_OK: + break; + case DHTLIB_ERROR_CHECKSUM: + break; + case DHTLIB_ERROR_TIMEOUT: + break; + default: + break; + } + { + Serial.print("humidity:"); + Serial.print(DHT.humidity); + Serial.print(" temperature:"); + Serial.println)DHT.temperature); + delay(200); + } + value = analogRead(photos); + Serial.println(value); + if (value > 300){ + digitalWrite(LED, HIGH); + } + else{ + digitalWrite(LED, LOW); + } + delay(100); + + //blink(); + + + buttonState = digitalRead(button); + if(buttonState == 0) { + digitalWrite(LED, HIGH); + birthdaySong(); + } else { + digitalWrite(LED, LOW); + } + delay(100); + + + count++; + + +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 +}