My circuit diagram it's just in my head, but here is the code for the two units i have.
This is code for the main sensor with LCD, temperature sensor, LED, LDR etc.
#include <LiquidCrystal_I2C.h>
#include <DHT.h>;
LiquidCrystal_I2C lcd(0x27, 20, 4);
byte CelciusSymbol[] = {
B00111,
B00101,
B00111,
B00000,
B00000,
B00000,
B00000,
B00000
};
#define DHTPIN 19 // what pin we're connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE);
int chk;
float hum; //Stores humidity value
float temp; //Stores temperature value
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
int sensorPin = 34;
int sensorValue = 0;
int redled = 13;
int blueled = 12;
int greenled = 14;
int freq = 5000;
int ledChannel = 13;
int ledChannel2 = 12;
int ledChannel3 = 14;
int resolution = 8;
BlynkTimer timer;
char auth[] = "***";
char ssid[] = "***";
char pass[] = "***";
void startup() {
lcd.begin();
lcd.backlight();
ledcWrite(redled, 255);
delay(1000);
lcd.setCursor(0, 2);
lcd.print("Ver.2.0");
delay(1000);
lcd.setCursor(0, 3);
lcd.print("Starting up");
delay(2000);
ledcWrite(blueled, 0);
ledcWrite(redled, 200);
ledcWrite(greenled, 30);
lcd.setCursor(11, 3);
lcd.print(".");
delay(500);
lcd.setCursor(12, 3);
lcd.print(".");
delay(500);
lcd.setCursor(13, 3);
lcd.print(".");
delay(500);
lcd.setCursor(14, 3);
lcd.print(".");
delay(500);
lcd.setCursor(15, 3);
lcd.print(".");
delay(500);
lcd.setCursor(16, 3);
lcd.print(".");
delay(1000);
lcd.clear();
}
void sensorData(){
// some code for writing temperature and humidity values to serial monitor
hum = dht.readHumidity();
temp = dht.readTemperature();
Serial.print("Fuktighet: ");
Serial.print(hum);
Serial.print(" %, Temperatur: ");
Serial.print(temp);
Serial.println(" Celsius");
lcd.createChar(0, CelciusSymbol);
// code for showing temperature innside the box
lcd.setCursor(0, 0);
lcd.print("FURTEBUA");
lcd.setCursor(13, 0);
lcd.print("Ver.2.0");
lcd.setCursor(0, 1);
lcd.print("--------------------");
// code for showing temperature values on LCD display
lcd.setCursor(0, 2);
lcd.print("Temperatur: ");
// code for showing temperature values on LCD display
lcd.setCursor(13, 2);
lcd.print(temp);
lcd.write(0);
lcd.setCursor(19, 2);
lcd.print("C");
// code for showing temperature innside the box
lcd.setCursor(0, 3);
lcd.print("Fuktighet: ");
// code for showing humidity values on LCD display
lcd.setCursor(13, 3);
lcd.print(hum);
lcd.print(" %");
// some code that makes the value "sensorValue"
sensorValue = analogRead(sensorPin); // read the value from the sensor
Serial.println(sensorValue); //prints the values coming from the sensor on the
// some statements that turns on and off the LCD display regards to light in the room
if (sensorValue > 3000) {
lcd.noBacklight();
ledcWrite(redled, 15);
ledcWrite(greenled, 0);
ledcWrite(blueled, 0);
}
if (sensorValue < 3000) {
lcd.display();
lcd.backlight();
ledcWrite(redled, 0);
ledcWrite(greenled, 15);
ledcWrite(blueled, 0);
}
// some code that sends virtual data to the Blynk app
Blynk.virtualWrite(V5, temp);
Blynk.virtualWrite(V6, hum);
}
void setup()
{
Blynk.begin(auth, ssid, pass);
timer.setInterval(2000L, sensorData);
Serial.begin(9600);
// configure LED PWM functionalitites
ledcSetup(ledChannel, freq, resolution);
ledcSetup(ledChannel2, freq, resolution);
ledcSetup(ledChannel3, freq, resolution);
// attach the channel to the GPIO to be controlled
ledcAttachPin(redled, ledChannel);
ledcAttachPin(greenled, ledChannel2);
ledcAttachPin(blueled, ledChannel3);
pinMode(redled, OUTPUT);
pinMode(greenled, OUTPUT);
pinMode(blueled, OUTPUT);
pinMode(sensorPin, INPUT);
ledcWrite(redled, 0);
ledcWrite(greenled, 0);
ledcWrite(blueled, 0);
dht.begin();
startup();
}
void loop() {
Blynk.run();
timer.run();
}
And this is the code for the internal temperature sensor inside project box:
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
BlynkTimer timer;
int dark=1000; //Specified in Hz
int light=1300; //Specified in Hz
int buzzPin=15;
int timeOn=300; //specified in milliseconds
int timeOff=300; //specified in millisecods
char auth[] = "***";
char ssid[] = "***";
char pass[] = "***";
int ledred = 14;
int ledyellow = 12;
int ledblue = 13;
void buzzer(){
tone(buzzPin, dark);
delay(timeOn);
noTone(buzzPin);
tone(buzzPin, light);
delay(timeOff);
}
void sensorData(){
sensors.requestTemperatures();
Serial.print("Temperatur: ");
Serial.println(sensors.getTempCByIndex(0));
Blynk.virtualWrite(V5, sensors.getTempCByIndex(0));
ledgrid();
}
void ledgrid(){
if (sensors.getTempCByIndex(0) <20){
digitalWrite(ledblue, HIGH);
digitalWrite(ledyellow, LOW);
digitalWrite(ledred, LOW);
noTone(buzzPin);
}
if (sensors.getTempCByIndex(0) >=20 && sensors.getTempCByIndex(0) <=25){
digitalWrite(ledblue, LOW);
digitalWrite(ledyellow, HIGH);
digitalWrite(ledred, LOW);
noTone(buzzPin);
}
if (sensors.getTempCByIndex(0) >25){
digitalWrite(ledblue, LOW);
digitalWrite(ledyellow, LOW);
digitalWrite(ledred, HIGH);
buzzer();
Blynk.notify("WARNNG! Over 60 grader i boksen!");
}
}
void setup()
{
timer.setInterval(10000L, sensorData);
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
pinMode(ledred, OUTPUT);
pinMode(ledyellow, OUTPUT);
pinMode(ledblue, OUTPUT);
pinMode(buzzPin, OUTPUT);
}
void loop() {
Blynk.run();
timer.run();
}