furrie's oasis

Submitted by furriephillips on Wed, 07/20/2016 - 11:55

This is an Arduino-based greenhouse plant-watering management system, for my little oasis.

I started with setting up an old LCD display I bought years ago but never got working (it used a parralell interface and it really was a long long time ago).

I've got some environmental sensors connected & knocked up some code to read them, but stumbled a bit on the temperature sensor, which so far, I've yet to master, and the humidity sensor is a bit fancy and doesn't need an inline resistor (I think), but I have yet to fully discover it's depths either... It's not as hot and steamy here, as the LCD suggests!

Hardware

LCD Output

Sketch


/*
furrie's oasis

Features (x=not yet)
* LCD
* Environmental Sensors
** Light Level
*x Temperature
*x Relative Humidity
x Ethernet client
x Web server
x SD card manipulation
x Tweeting various events (@furries_oasis on Twitter)

// LCD Component
The 20x4 LCD uses the LiquidCrystal library, which works
using the Hitachi HD44780 driver, with 16-pin interface.
The circuit: -
* LCD RS pin to digital pin 7
* LCD Enable pin to digital pin 8
* LCD D4 pin to digital pin 9
* LCD D5 pin to digital pin 10
* LCD D6 pin to digital pin 11
* LCD D7 pin to digital pin 12
* LCD R/W pin to ground
* 10K Potentiometer (variable resistor): -
** ends to +5V and ground
** wiper (Potentiometer output) to LCD VO pin (pin 3)
* Sensors: -
** Temperature to A0
** Light Level to A1
** RelHumidity to A2
Arduino LCD Tutorial: http://www.arduino.cc/en/Tutorial/LiquidCrystal
Arduino Character LCDs: http://www.ladyada.net/learn/lcd/charlcd.html
HD44780 LCD User-Defined Graphics: http://www.quinapalus.com/hd44780udg.html

// Debug Component
Standard debug to serial, with pauses to prevent brain melting serial scroll

// Environmental Sensor Component
We read from several environmental sensors, map the values read,
to sensible real-world values (and some pictorial ones, for display on the LCD)
*/

// Includes
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

// Initialize the LCD library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
// Create some special characters for the LCD
byte smiley[8] = {0,0,10,0,17,14,0};
byte shades[8] = {0,31,27,0,17,14,0};
byte degreeC[8] = {12,18,18,12,0,0,0};
byte heart[8] = {0,10,31,31,31,14,4};
byte sun[8] = {0,21,14,31,14,21,0};

// Define the sensor array items
// Light Sensor
int lightPin = 0;
// Temperature Sensor
int tempPin = 1;
// Humidity Sensor
int relhumPin = 2;

void setup() {
// Set up debugging if required
Serial.begin(9600);

// Set up the fancy LCD characters
lcd.createChar(0, smiley);
lcd.createChar(1, shades);
lcd.createChar(2, degreeC);
lcd.createChar(3, heart);
lcd.createChar(4, sun);

// Initialise the LCD, defining the number of columns and rows
lcd.begin(20, 4);
}

void loop() {
/*
Environmental sensor data capture & mapping to display values
*/
// Read the Light sensor
int lightval = analogRead(lightPin);
// Constrain the LDR min & max values
lightval = constrain(lightval, 20, 60);
// Map the LDR values to the whole 10bit range
int lightLevel = map(lightval, 20, 60, 0, 5); // These values need calibration for the outside

// Read the Temperature sensor
int tempval = analogRead(tempPin);
// Constrain the Temp. min & max values
//tempval = constrain(tempval, 20, 30);
// Map the thermistor values to the whole 10bit range
//int tempLevel = map(tempval, 20, 30, 0, 60); // These values need calibration and +/- logic
int tempLevel = tempval;

// Read the Relative Humidity sensor
int relhumval = analogRead(relhumPin);
// Constrain the min & max values
relhumval = constrain(relhumval, 400, 1023);
// Map the mumidity sendor values to the whole 10bit range
int relhumLevel = map(relhumval, 1023, 400, 100, 0); // These values need calibration

/*
Print a message to the LCD for prettiness and the serial "device" for debugging
(LCD row numbering begins at 0)
*/
// LCD Line 1 (0)
lcd.setCursor(1, 0);
lcd.print((char)1);
lcd.print(" furrie's oasis ");
lcd.print((char)1);
// Debug
Serial.println("\nEnvironment Variables (real,mapped,LCD): -");

// LCD Line 2 (1) Print the current light level (Suns)
Serial.print(" Light Level:\t\t");
Serial.print(lightval);
Serial.print(",");
Serial.print(lightLevel);
Serial.print(",");
lcd.setCursor(0, 1);
lcd.print("Light Level: ");
// Determine the level of darkness, from "SCARY" (dark), to 5 Suns
if (lightLevel == 0) { // If it's completely dark, say so
Serial.println("SCARY");
lcd.print("SCARY");
} else { // If it's not completely dark, represent light levels with Suns
int suns = 0; // Setting starts to 0, so we can count up as we print them
while (suns < lightLevel) { // Traverse the loop until we've printed all required Suns
lcd.print((char)4);
Serial.print("*");
suns++;
}
while (suns < 5) { // Make sure that we clear any old values longer than the current one
Serial.print(".");
lcd.print(" "); // this is to avoid such junk as ***RY where it went from dark to level 3
suns++;
}
Serial.println();
}

// LCD Line 3 (2) Print the current temperature (degrees °C)
Serial.print(" Temperature:\t\t");
Serial.print(tempval);
Serial.print(",");
//Serial.print(tempLevel);
Serial.print(tempval); // Replace this line with the one above, when you've figured out the sensor
Serial.print(",");
Serial.print("+");
Serial.print(tempval);
Serial.print("Deg");
Serial.println("C");
lcd.setCursor(0, 2);
lcd.print("Temperature: ");
lcd.print("+");
lcd.print(tempLevel);
lcd.print((char)2);
lcd.print("C");

// LCD Line 4 (3) Print the current relative humidity (%)
Serial.print(" Relative Humidity:\t");
Serial.print(relhumval);
Serial.print(",");
Serial.print(relhumLevel);
Serial.print(",");
Serial.print(relhumLevel);
Serial.println("%");
lcd.setCursor(0, 3);
lcd.print("RelHumidity: ");
lcd.print(relhumLevel);
lcd.print("%");

// Pause for a bit, during iterations (so that we don't go blinking mad)
delay(5000);
}