Weather station DHT22 - mcworkshop

MC   WORKSHOP
Vai ai contenuti

Menu principale:

Weather station DHT22

Projects
Temperature, humidity, light, wet sensor.


INDICE
Temperature, humidity, light, wet sensor
Wiring diagram
With LCD on I2C
The analog inputs
Sketch
LCD (no I2C) + DHT22 + Pannello solare (fotovoltaico) + sensore di bagnato (NEW agosto 2019)






Wiring diagram
LDR to A0
Wet sensor to A1
Solar panel: not implemented. For technical reasons, the solar panel was removed from the project. I will perform separate tests.

Click on the image to enlarge






out to pin 9
DHT22: pin 1 +Vcc, pin 2 SDA (out), pin 3 no use, pin 4 GND
pin numbering sequence image: from left to right




Click on the image to enlarge


With LCD on I2C

1: Light display on - off
2: display contrast


I used 2 step down. One to power Arduino (7,5Vcc), and the second for LCDs and sensors (5Vcc)
Arduino and step down are mounted on a Plexiglas panel.




I recommend to test the circuit first only with the display. Make sure everything is working properly. As a sketch, load the classic "hello world".
Raccomando di testare il circuito prima solo con il display. Assicurati che tutto funzioni correttamente. Come Sketch, carica il classico "ciao mondo".

The analog inputs

Arduino has a 10-bit analog-to-digital converter. This means that it will map input voltages between 0 and 5 volts in integer values between 0 and 1023. This yields a resolution between readings of: 5 volts / 1024 units ie 0.0049 volts (4.9 mV) per unit. It takes about 100 microseconds (0.0001 s) to read an analog input, so the maximum reading speed is about 10,000 times per second.
As already mentioned, DHT22 does not like to be interrogated too often, so in the code are inserted delays in order to slow down the execution of the sketch.
Arduino ha un convertitore analogico-digitale a 10 bit. Ciò significa che mapperà tensioni di ingresso tra 0 e 5 volt in valori interi compresi tra 0 e 1023. Questo produce una risoluzione tra le letture di: 5 volt / 1024 unità, cioè 0,0049 volt (4,9 mV) per unità. Occorrono circa 100 microsecondi (0,0001 s) per leggere un ingresso analogico, quindi la velocità di lettura massima è di circa 10.000 volte al secondo.
Come già accennato, al DHT22 non piace essere interrogato troppo spesso, quindi nel codice vengono inseriti dei ritardi per rallentare l'esecuzione dello sketch.


In the sketch, the management of input A0 is:

lcd.print ("L ");
 int val0 = analogRead(A0);
 val0 = map(val0, 0, 1023, 0, 100);
 analogWrite(0, val0);
 lcd.print (val0);
 lcd.print (" %");

Sketch

//LCD (no I2C) con DHT22
//Cerani Marco - MPMC Workshop 7 agosto 2018 V1.3
#include <LiquidCrystal.h>
#include <DHT.h>
#include <Adafruit_Sensor.h>
#define DHTTYPE DHT22
#define DHTPIN 9
DHT dht(DHTPIN, DHTTYPE);
//
float celsius;
float humidity;
//
int val0 = A0;
int val1 = A1;
int analogInPin9 = 9;
int sensorValue9 = 0;
//
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
 dht.begin();
 lcd.begin(16, 2);
 //
 pinMode( analogInPin9, INPUT);
 pinMode( val0, INPUT);
 pinMode( val1, INPUT);
 //
}
void loop() {
 humidity = dht.readHumidity();
 celsius = dht.readTemperature();
 sensorValue9 = analogRead(analogInPin9);
 delay (1000);
 char lcd_buffer[16];
 lcd.setCursor(0, 0); //riposiziono il cursore
 sprintf(lcd_buffer, "%02d.%01d %cC ", (int)celsius, (int)(celsius * 10.0) % 100, (char)223);
 lcd.print(lcd_buffer);
 sprintf(lcd_buffer, "%02d.%01d %cC", (int)humidity, (int)(humidity * 10.0) % 100, (char)37);
 lcd.print(lcd_buffer);
 lcd.setCursor(0, 1);
 //
 delay (1000);
 lcd.print ("L ");
 int val0 = analogRead(A0);
 val0 = map(val0, 0, 1023, 0, 100);
 analogWrite(0, val0);
 lcd.print (val0);
 lcd.print (" %");
 //
 delay (1000);
 lcd.print (" B ");
 int val1 = analogRead(A1);
 val1 = map(val1, 0, 1023, 0, 100);
 analogWrite(0, val1);
 lcd.print (val1);
 lcd.print (" %");
 //
 delay (1000);
}







Microclimatic study. PDF in italian tongue.


LCD (no I2C) + DHT22 + Pannello solare (fotovoltaico) + sensore di bagnato
Temperature, humidity, photovoltaic panel, wet sensor.
11 august 2019

Questo nuovo sketch evita i classici delay. I sensori vengono interrogati ogni minuto. Il pannello fotovoltaico è in funzione. Il pannello produce 1,2 Volt. Sul display si legge la percentuale di resa. Ho sostituito il sensore di pioggia, con un modello semplice costruito in casa.
This new sketch avoids the classic delays. The sensors are interrogated every minute. The photovoltaic panel is in operation. The panel produces 1.2 Volt. The yield percentage is shown on the display. I replaced the rain sensor with a simple model built at home.






clic to enlarge


pin 9 DHT 22 // int analogInPin9 = 9;
pin A0 photovoltaic panel // pinMode( val0, INPUT);
pin A1 wet sensor / rain sensor // pinMode( val1, INPUT_PULLUP); do not use resistors

//LCD (no I2C) + DHT22 + Pannello solare + sensore di bagnato
//MC Workshop
//rev. v1.4 11/08/2019 - 19:00

#include <LiquidCrystal.h>
#include <DHT.h>
#include <Adafruit_Sensor.h>
#define DHTTYPE DHT22
#define DHTPIN 9
DHT dht(DHTPIN, DHTTYPE);
unsigned long last = 0;
//
float celsius;
float humidity;
//
int val0 = A0;
int val1 = A1;
int analogInPin9 = 9;
int sensorValue9 = 0;
//
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
 dht.begin();
 lcd.begin(16, 2);
 //
 pinMode( analogInPin9, INPUT);
 pinMode( val0, INPUT);
 pinMode( val1, INPUT_PULLUP);
 //
}
void loop() {
 unsigned long current = millis();
 if ((current - last) >= 60000) {
   humidity = dht.readHumidity();
   celsius = dht.readTemperature();
   sensorValue9 = analogRead(analogInPin9);
   delay (1000);
   char lcd_buffer[16];
   lcd.setCursor(0, 0);
   sprintf(lcd_buffer, "%02d.%01d %cC ", (int)celsius, (int)(celsius * 10.0) % 100, (char)223);
   lcd.print(lcd_buffer);
   sprintf(lcd_buffer, "%02d.%01d %cC", (int)humidity, (int)(humidity * 10.0) % 100, (char)37);
   lcd.print(lcd_buffer);
   lcd.setCursor(0, 1);
 }
 //
 if ((current - last) >= 62000) {
   lcd.print ("PS ");//rendimento pannello solare 1,2V 750mA
   int val0 = analogRead(A0);
   val0 = map(val0, 0, 294, 0, 100);//1023:5=x:1,2  1V = 24,52 0,1V = 24,5
   analogWrite(0, val0);
   lcd.print (val0);
   lcd.print (" %");
 }
 //
if ((current - last) >= 64000) {
   lcd.print ("  B "); //bagnato, pioggia
   int val1 = analogRead(A1);
   val1 = map(val1, 0, 995, 100, 0); //mappatura prove sperimentali
   analogWrite(0, val1);
   lcd.print (val1);
   lcd.print (" %");
   //
   if ((current - last) >= 66000)
   {
     last = current;
   }
 }
}
 
Copyright 2015. All rights reserved.
Torna ai contenuti | Torna al menu