Last active
April 4, 2020 11:39
-
-
Save andraantariksa/bb82f5fdc3e101e2ca8e218c25587437 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <LiquidCrystal_I2C.h> | |
#include <dht.h> | |
//#define SERIALPRINT 1 | |
#define DHT_ANALOG_PIN A0 | |
#define SOIL_MOISTURE_ANALOG_PIN A1 | |
#define RAINDROP_ANALOG_PIN A2 | |
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); | |
dht DHT; | |
void setup() { | |
Serial.begin(9600); | |
lcd.begin(16, 2); | |
lcd.clear(); | |
// lcd.print("Hello, world!"); | |
pinMode(LED_BUILTIN, OUTPUT); | |
} | |
void loop() { | |
digitalWrite(LED_BUILTIN, HIGH); | |
delay(100); | |
digitalWrite(LED_BUILTIN, LOW); | |
delay(100); | |
digitalWrite(LED_BUILTIN, HIGH); | |
delay(100); | |
digitalWrite(LED_BUILTIN, LOW); | |
delay(2000); | |
#ifdef SERIALPRINT | |
Serial.println("Soil"); | |
Serial.println(1023 - analogRead(SOIL_MOISTURE_ANALOG_PIN)); | |
#endif | |
#ifdef SERIALPRINT | |
Serial.println("Raindrop"); | |
#endif | |
char* isRain = (analogRead(RAINDROP_ANALOG_PIN) < 500)? "It's raining" : "Not raining"; | |
#ifdef SERIALPRINT | |
Serial.print(isRain); | |
Serial.print(" - "); | |
Serial.println(analogRead(RAINDROP_ANALOG_PIN)); | |
#endif | |
int soilMoisture = 1023 - analogRead(SOIL_MOISTURE_ANALOG_PIN); | |
lcd.print(String("Soil ") + soilMoisture + " " + isRain); | |
DHT.read11(DHT_ANALOG_PIN); | |
// Ok wtf AVR device can't use printf for floating point | |
String line2; | |
line2 += DHT.temperature; | |
line2 += " C "; | |
line2 += DHT.humidity; | |
line2 += " %"; | |
lcd.setCursor(0, 1); | |
#ifdef SERIALPRINT | |
Serial.println(line2); | |
#endif | |
lcd.print(line2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment