#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Arduino.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include "RTClib.h"
#include "HX711.h"
LiquidCrystal_I2C lcd(0x27,16,2);
RTC_DS1307 rtc;
// #define ONE_WIRE_BUS 2
// Create a new instance of the oneWire class to communicate with any OneWire device:
OneWire oneWire(11);
// Pass the oneWire reference to DallasTemperature library:
DallasTemperature sensors(&oneWire);
HX711 scale;
// HX711 circuit wiring
const int LOADCELL_DOUT_PIN = 2;
const int LOADCELL_SCK_PIN = 3;
void setup()
{
Serial.begin(9600);
// Setup RTC
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
abort();
}
pinMode(A0, INPUT);
lcd.init();
lcd.backlight();
// Start up the library:
sensors.begin();
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
scale.set_scale(-459.542);
//scale.set_scale(-471.497); // this value is obtained by calibrating the scale with known weights; see the README for details
scale.tare();
}
void loop()
{
lcd.clear();
lcd.print("DAYLIGHT: ");
lcd.setCursor (0, 1);
DateTime now = rtc.now();
int hour = now.hour();
String timecheck;
if (6 < hour && hour < 18){
timecheck = "SUNRISE";
} else{
timecheck = "SUNSET";
}
lcd.print(timecheck);
delay(2000);
lcd.clear();
int16_t i = analogRead(A0);
String msg = i < 300 ? "WET SOIL" : i > 400 ? "DRY SOIL" : "OK";
lcd.clear();
lcd.print("MOISTURE: ");
lcd.setCursor (0, 1);
lcd.print(msg);
delay(2000);
lcd.clear();
lcd.print("TEMPERATURE: ");
lcd.setCursor (0, 1);
// Fetch the temperature in degrees Celsius for device index:
float tempC = sensors.getTempCByIndex(0); // the index 0 refers to the first device
// Print the temperature in Celsius in the Serial Monitor:
// Serial.print("Temperature: ");
lcd.print(tempC);
lcd.print(" C");
delay(2000);
lcd.clear();
// Print Rain Status
lcd.print("RAIN: ");
lcd.setCursor (0, 1);
// Serial.print("Day Status: ");
if (scale.get_units(10) > 0.04){
lcd.print("RAINY");
}else{
lcd.print("NONE");
}
delay(2000);
lcd.clear();
}
Loading
ds18b20
ds18b20