Stap 2: De Code
Het is heel erg basic en heel eenvoudig.
#include < Wire.h > //libraries nodig
#include < LCD.h >
#include < LiquidCrystal_I2C.h >
#include < dht11.h >
I2C-Controller
#define I2C_ADDR 0x20 / / I2C adres definiƫren voor controller
#define BACKLIGHT_PIN 7
#define En_pin 4
#define Rw_pin 5
#define Rs_pin 6
#define D4_pin 0
#define D5_pin 1
#define D6_pin 2
#define D7_pin 3
#define LED_OFF 0
#define LED_ON 1
DHT11
#define DHT11PIN 2
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
dht11 DHT11;
VOID Setup
{
LCD.begin (16,2);
De achtergrondverlichting inschakelen
lcd.setBacklightPin(BACKLIGHT_PIN,NEGATIVE);
lcd.setBacklight(LED_ON);
}
void loop
{
LCD.Clear();
LCD.Home();
int chk = DHT11.read(DHT11PIN);
lcd.setCursor(0,0);
LCD.Print ("Humy (%):");
LCD.Print ((float) DHT11.humidity, 2);
lcd.setCursor(0,1);
LCD.Print ("Temp (van):");
LCD.Print(Fahrenheit(DHT11.temperature), 2);
delay(5000);
}
Temp conversie
dubbele Fahrenheit (dubbele celsius)
{
retourneren van 1.8 * celsius + 32;
}