dupa cum spune si titlul, am inlocuit senzorul DHT11 cu DHT22 (AM2302), care este mult mai performant si are domeniul de masura mai larg (precizie +0,50C si
Pentru informatii suplimentare recomand articolul DHTxx Sensors postat pe site-ul Adafruit.
DHT11 / DHT22
Deoarece ministatia meteo cu ceas, varianta propusa de Janos, mi s-a parut ok, am refacut schema partial (practic nu am mai pus cele trei butoane fara retinere pentru reglare ore si minute).Daca aveti modulul cu 3 pini, schema de conectare este identica:
Practic, montajul arata asa, iar pe ecran informatiile sunt prezentate astfel (am schimbat 3 afisaje, care cu fundal rosu, albastru si galben):
// Date and time functions using a DS1307 RTC
// original sketck from http://learn.adafruit.com/ds1307-real-time-clock-breakout-board-kit/
// add part with SQW=1Hz from http://tronixstuff.wordpress.com/ & http://www.bristolwatch.com/arduino/arduino_ds1307.htm
// DHT library from https://github.com/adafruit/DHT-sensor-library
// adapted sketch by niq_ro from http://nicuflorica.blogspot.ro/
// original article from http://nicuflorica.blogspot.ro/2013/06/ceas-de-timp-real-rtc-cu-ds1307-si.html
// adapted sketch drom http://nicuflorica.blogspot.ro/2014/09/ceas-rtc-cu-ds1307-si-date-mediu-cu.html
#include <Wire.h>
#include "RTClib.h"
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
/* -------------------
| LCD | Arduino |
-------------------
LCD RS pin to digital pin 7 | RS | D7 |
LCD Enable pin to digital pin 6 | E | D6 |
LCD D4 pin to digital pin 5 | D4 | D6 |
LCD D5 pin to digital pin 4 | D5 | D4 |
LCD D6 pin to digital pin 3 | D6 | D3 |
LCD D7 pin to digital pin 2 | D7 | D2 |
LCD R/W pin to ground | R/W | GND |
-------------------
*/
// http://arduino.cc/en/Reference/LiquidCrystalCreateChar
byte grad[8] = {
B01100,
B10010,
B10010,
B01100,
B00000,
B00000,
B00000,
};
RTC_DS1307 RTC;
#include <DHT.h>
#define DHTPIN 8 // what pin we're connected DHT11/22
//#define DHTTYPE DHT11 // DHT 11
#define DHTTYPE DHT22 // DHT 22
DHT dht(DHTPIN, DHTTYPE);
byte SW0 = A0;
byte SW1 = A1;
byte SW2 = A2;
// use for hexa in zecimal conversion
int zh, uh, ore;
int zm, um, miniti;
//
float t1;
void setup () {
// DHT init
dht.begin();
// create custom symbol
lcd.createChar(0, grad);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a logo message to the LCD.
lcd.print("www.tehnic.go.ro");
lcd.setCursor(0, 1);
lcd.print("creat de niq_ro");
delay (2500);
lcd.clear();
// Print a logo message to the LCD.
lcd.print("ministatie meteo");
lcd.setCursor(0, 1);
lcd.print("cu DHT22 ver.1.0");
delay (2500);
lcd.clear();
// Serial.begin(9600);
Wire.begin();
// part code from http://tronixstuff.wordpress.com/
Wire.beginTransmission(0x68);
Wire.write(0x07); // move pointer to SQW address
Wire.write(0x10); // sends 0x10 (hex) 00010000 (binary) to control register - turns on square wave
Wire.endTransmission();
// end part code from http://tronixstuff.wordpress.com/
RTC.begin();
if (! RTC.isrunning()) {
//Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
RTC.adjust(DateTime(__DATE__, __TIME__));
}
pinMode(SW0, INPUT); // for this use a slide switch
pinMode(SW1, INPUT); // N.O. push button switch
pinMode(SW2, INPUT); // N.O. push button switch
digitalWrite(SW0, HIGH); // pull-ups on
digitalWrite(SW1, HIGH);
digitalWrite(SW2, HIGH);
}
void loop () {
DateTime now = RTC.now();
int h = dht.readHumidity();
float t = dht.readTemperature();
// float t = 23.56;
//float t = 7.32;
//float t = 0.01;
//float t = 0;
//float t = -0.02;
//float t = -6.45;
//float t=-13.25;
lcd.setCursor(4, 0);
if ( now.hour() < 10)
{
lcd.print(" ");
lcd.print(now.hour(), DEC);
}
else
{
lcd.print(now.hour(), DEC);
}
lcd.print(":");
if ( now.minute() < 10)
{
lcd.print("0");
lcd.print(now.minute(), DEC);
}
else
{
lcd.print(now.minute(), DEC);
}
lcd.print(":");
if ( now.second() < 10)
{
lcd.print("0");
lcd.print(now.second(), DEC);
}
else
{
lcd.print(now.second(), DEC);
}
lcd.print(" ");
lcd.setCursor(0, 1);
// lcd.print("t=");
if (t < 0)
{t1=-t;}
else t1=t;
if ( t1 < 10)
{
lcd.print(" ");
}
if (t>0) lcd.print("+");
if (t==0) lcd.print(" ");
if (t<0) lcd.print("-");
lcd.print(t1,1);
//lcd.print(",0");
// lcd.write(0b11011111);
lcd.write(byte(0));
lcd.print("C ");
lcd.setCursor(10, 1);
// lcd.print("H=");
lcd.print(h);
lcd.print("%RH");
if (!(digitalRead(SW0))) set_time(); // hold the switch to set time
delay(500);
}
void set_time() {
byte minutes1 = 0;
byte hours1 = 0;
byte minutes = 0;
byte hours = 0;
while (!digitalRead(SW0)) // set time switch must be released to exit
{
minutes1=minutes;
hours1=hours;
while (!digitalRead(SW1)) // set minutes
{
minutes++;
// converting hexa in zecimal:
zh = hours / 16;
uh = hours - 16 * zh ;
ore = 10 * zh + uh;
zm = minutes / 16;
um = minutes - 16 * zm ;
miniti = 10 * zm + um;
/*
for(int i = 20 ; i >0 ; i--) {
displayNumber01(ore*100+miniti);
}
*/
lcd.setCursor(4, 0);
if ( ore < 10)
{
lcd.print(" ");
lcd.print(ore);
}
else
{
lcd.print(ore);
}
lcd.print(":");
if ( miniti < 10)
{
lcd.print("0");
lcd.print(miniti);
}
else
{
lcd.print(miniti);
}
lcd.print(":");
lcd.print("00");
if ((minutes & 0x0f) > 9) minutes = minutes + 6;
if (minutes > 0x59) minutes = 0;
Serial.print("Minutes = ");
if (minutes >= 9) Serial.print("0");
Serial.println(minutes, HEX);
delay(150);
}
while (!digitalRead(SW2)) // set hours
{
hours++;
// converting hexa in zecimal:
zh = hours / 16;
uh = hours - 16 * zh ;
ore = 10 * zh + uh;
zm = minutes / 16;
um = minutes - 16 * zm ;
miniti = 10 * zm + um;
/*
for(int i = 20 ; i >0 ; i--) {
displayNumber01(ore*100+miniti);
}
*/
lcd.setCursor(4, 0);
if ( ore < 10)
{
lcd.print(" ");
lcd.print(ore);
}
else
{
lcd.print(ore);
}
lcd.print(":");
if ( miniti < 10)
{
lcd.print("0");
lcd.print(miniti);
}
else
{
lcd.print(miniti);
}
lcd.print(":");
lcd.print("00");
if ((hours & 0x0f) > 9) hours = hours + 6;
if (hours > 0x23) hours = 0;
Serial.print("Hours = ");
if (hours <= 9) Serial.print("0");
Serial.println(hours, HEX);
delay(150);
}
Wire.beginTransmission(0x68); // activate DS1307
Wire.write(0); // where to begin
Wire.write(0x00); //seconds
Wire.write(minutes); //minutes
Wire.write(0x80 | hours); //hours (24hr time)
Wire.write(0x06); // Day 01-07
Wire.write(0x01); // Date 0-31
Wire.write(0x05); // month 0-12
Wire.write(0x09); // Year 00-99
Wire.write(0x10); // Control 0x10 produces a 1 HZ square wave on pin 7.
Wire.endTransmission();
// converting hexa in zecimal:
zh = hours / 16;
uh = hours - 16 * zh ;
ore = 10 * zh + uh;
zm = minutes / 16;
um = minutes - 16 * zm ;
miniti = 10 * zm + um;
/* for(int i = 20 ; i >0 ; i--) {
displayNumber01(ore*100+miniti);
}
// delay(150);
*/
lcd.setCursor(4, 0);
if ( ore < 10)
{
lcd.print(" ");
lcd.print(ore);
}
else
{
lcd.print(ore);
}
lcd.print(":");
if ( miniti < 10)
{
lcd.print("0");
lcd.print(miniti);
}
else
{
lcd.print(miniti);
}
lcd.print(":");
lcd.print("00");
}
}
In filmuletul numit ministatie meteo cu DHT22 si ceas cu DS1307 am prezentat aceasta ministatie meteo c senzorul DHT22, partea de ceas este fara butoanele de reglaj: