Arduino Projects – Garden Sensor Suite (DHT11, DS3231, Light, Moisture, I2C LCD)

This project is a full sensor suite device for a garden or your indoor plants. This has a Moisture Sensor, Temperature/ Humidity Sensor, Light Sensor and Real Time Clock that output to a 20×4 LCD I2C screen.

Note:

  • If the project fails to print out to screen it may be an issue with the DS3231 Clock module. Comment out the clock code and see if it works.

Prerequisite Classes:

Libraries:

Functional Parts in the Project:

#include <DHT.h>
#include <DS3231.h>
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>

//Light Sensor
#define lightSensor A0

//Soil Moisture Sensor
#define moistureSensor A1

//Configure DHT11 Sensor
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

//Configure I2C 20x4 LCD Display
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7);

//Configure DS321 Real Time Clock
DS3231  rtc(6, 7);

void setup()
{
  //Start LCD Screen
  lcd.begin(20, 4);
  lcd.setBacklightPin(3, POSITIVE);
  lcd.setBacklight(HIGH);

  //Start Temperature Sensor
  dht.begin();

  //Start Clock
  rtc.begin();

  //The following lines can be uncommented to set the date and time
  //rtc.setDOW(WEDNESDAY);     // Set Day-of-Week to SUNDAY
  //rtc.setTime(12, 0, 0);     // Set the time to 12:00:00 (24hr format)
  //rtc.setDate(1, 1, 2014);   // Set the date to January 1st, 2014

}

void loop()
{
  //2 Second Delay to Allow DHT11 to Calibrate
  delay(2000);

  //Get Light Level
  int lightLevel = analogRead(lightSensor);

  //Get Moisture Level
  int moistureLevel = analogRead(moistureSensor);

  //Standard LCD Print Out
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(rtc.getTimeStr());
  lcd.setCursor(10,0);
  lcd.print(rtc.getDateStr());
  lcd.setCursor(0, 1);
  lcd.print("Temp ");
  lcd.setCursor(5, 1);
  lcd.print(dht.readTemperature(true));
  lcd.setCursor(11, 1);
  lcd.print("Hum ");
  lcd.setCursor(15, 1);
  lcd.print(dht.readHumidity());
  lcd.setCursor(0,2);
  lcd.print("Light Level:");
  lcd.setCursor(13,2);
  lcd.print(lightLevel);
  lcd.setCursor(0,3);
  lcd.print("Moisture Level: ");
  lcd.setCursor(16,3);
  lcd.print(moistureLevel);

}

Be the first to comment

Leave a Reply