مشروع الحلقة 6: تصنيع محطة أرصاد جوية

نص البرنامج (الكود):

// Arduino-Weather Station -Darah
// Darahmakers.com

#include <dht22.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address

dht22 DHT22;

void setup()
{
DHT22.attach(2);
Serial.begin(9600);

Serial.println(“DHT22 TEST PROGRAM “);
Serial.print(“LIBRARY VERSION: “);
Serial.println(DHT22LIB_VERSION);

lcd.begin(20,4);

}

void loop()

{
Serial.println(“\n”);

int chk = DHT22.read();

switch (chk)
{
case 0: break;
case -1: Serial.println(“Checksum error”); break;
case -2: Serial.println(“Time out error”); break;
default: Serial.println(“Unknown error”); break;
}

Serial.print(“Temperature (°C): “);
lcd.setCursor(0,0);
lcd.print(“Temperature (C): “);

Serial.println((float)DHT22.temperature, DEC);
lcd.setCursor(6,1);
lcd.print((float)DHT22.temperature, DEC);

Serial.print(“Humidity (%): “);
lcd.setCursor(0,2);
lcd.print(“Humidity (%): “);

Serial.println((float)DHT22.humidity, DEC);
lcd.setCursor(6,3);
lcd.print((float)DHT22.humidity, DEC);

delay(2000);
}