Stap 5: LCD + temperatuur sensor
Nadat ik de wifi sensor werkt niet krijgen, besloten heb ik om te gaan met een LCD-scherm, om de gegevens weer te geven. Aanvulling op dit ik gebruikte een Potentiometer (10K) om het contrast van de LCD dienovereenkomstig aan te passen.
De eerste stap is alles aan elkaar koppelen.
Van links naar rechts:
LCD <> - Arduino
VSS <> - GND
VDD <> - 5V
V0 <> - Potmeter signaal (middelste stift)
RS <> - TX
RW <> - GND
E <> - Digital 2
D4 <> - Digitale 4
D5 <> - digitale 5
D6 <> - digitale 6
D7 <> - digitale 7
Een <> - 5V
K <> - GND
Potentiometer
GND GND <> -
Signaal <> - V0
5V <> - 5V
Ik alles boven in combinatie met de vorige stap van de DHT11. De volgende code werd gebruikt om de temperatuur en vochtigheid op het scherm weer te geven:
// include the library code:#include <LiquidCrystal.h>#include <dht.h>// Analog Pin sensor is connected to #define dht_apin A0 // initialize the library with the numbers of the interface pins LiquidCrystal lcd(1, 2, 4, 5, 6, 7); dht DHT;void setup() { //initializes the interface and specifies the dimension of the LCD lcd.begin(16, 2); printTemperature(); printHumidity(); //Wait before accessing Sensor delay(1000); }//function to print characters of temperature that don't need to be updated void printTemperature() { lcd.setCursor(0, 0); lcd.print("Temp : "); lcd.print(" "); lcd.setCursor(12, 0); lcd.print("C"); }//function to print characters of humidity that don't need to be updated void printHumidity() { lcd.setCursor(0, 1); lcd.print("Hmid : "); lcd.print(" "); lcd.setCursor(12, 1); lcd.print("%"); }void loop() { //Let the sensor check the new temperature DHT.read11(dht_apin); //retrieve data from temperature/humidity sensor float temperature = DHT.temperature; float humidity = DHT.humidity; //functions to update temperature and humidity on LCD updateTemperature(temperature); updateHumidity(humidity); //wait 5 seconds before updating again delay(5000); }void updateTemperature(float temperature) { lcd.setCursor(7, 0); lcd.print(temperature, 1); }void updateHumidity(float humidity) { lcd.setCursor(7, 1); lcd.print(humidity, 1); }