Stap 2: codering
Na het uploaden van de schets, zal het LCD-scherm tonen de temperatuur en vochtigheid, evenals de bodem vochtigheid voorwaarde.
// Guardian of Eden#include LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // Initiate the LCD display with the numbers of the interface pinsint TemperaturePin=A1; //The pin number of the temperature sensorint HumidityPin=A2; //The pin number of the humidity sensorvoid setup() { lcd.begin(16, 2); // set up the LCD's number of columns and rows}void loop() { int temperatureValue; //store the analog value from temperature sensor int humidityValue; //store the analog value from humidity sensor int temperature; //store the real temperature. temperatureValue=analogRead(TemperaturePin); //read the temperature sensor humidityValue=analogRead(HumidityPin); //read the humidity sensor temperature=(500 * temperatureValue) /1024; //Convert the analog value to real temperature. //LCD shows the temperature lcd.setCursor(0, 0); // set the cursor to column 0, line 0 lcd.print("T:"); lcd.print(temperature); lcd.print("C"); //LCD shows the humidity of the soil lcd.setCursor(0, 6); // set the cursor to column 6, line 0 lcd.print("H:"); lcd.print(humidityValue); //Show the situation of the soil lcd.setCursor(1, 0); // set the cursor to column 0, line 1 if (humidityValue<300) { lcd.print("Soil: Dry"); } else if (humidityValue>=300 && humidityValue<700){ lcd.print("Soil: Humid"); } else{ lcd.print("Soil: Water") } delay(500);}