There is a website called gardenbot.org, and it is a site documenting how to make a garden monitoring robot (is that the right word?) to water your plants automatically. My version currently doesn’t water the plants, but it monitors light levels and the moisture content of the soil. I have some pictures! Note: I can’t seem to embed pictures, I’m trying to upload them by putting the file path in between the image labels.
Building the Sensors:
I built the light sensor just using a medium sized photocell. I made the soil moisture sensor using a couple of straightened large paper clips. The control circuits I used are exactly the same as on the GardenBot website. IMPORTANT: The light sensor is on ANALOG 0 and the soil moisture sensor is on ANALOG 1. I used some phone wire to connect the sensors to the Arduino.
The Code:
Right now, the code just finds the mimimum, maximum (all time), and current readings, converted to percentages, and sends them to the computer through the Serial Window. You will probably have to resize the window to just fit one reading at a time.
Here is my code:
runOnce Program
//RUN THIS BEFORE FIRST USE OF MAIN GARDENBOT PROGRAM
#include <EEPROM.h>
const int LTS = 0;
const int SMS = 1;
int SM = 0;
int minSM = 0;
int maxSM = 0;
int LT = 0;
int minLT = 0;
int maxLT = 0;
void setup()
{
Serial.begin(9600);
Serial.println("Started");
SM = analogRead(SMS);
SM = 1024 - SM;
SM = SM / 10.24;
LT = analogRead(LTS);
LT = 1024 - LT;
LT = LT / 10.24;
minSM = SM;
maxSM = SM;
minLT = LT;
maxLT = LT;
EEPROM.write(0, minSM);
EEPROM.write(1, maxSM);
EEPROM.write(2, minLT);
EEPROM.write(3, maxLT);
}
void loop()
{
Serial.println("Done");
delay(60000);
}
gardenBot Program (Note: Does not yet water plants)
#include <EEPROM.h>
const int LTS = 0;
const int SMS = 1;
int SM = 0;
int minSM = 0;
int maxSM = 0;
int LT = 0;
int minLT = 0;
int maxLT = 0;
int watering = false;
void setup()
{
Serial.begin(9600);
delay(100);
Serial.println("Started");
SM = analogRead(SMS);
SM = 1024 - SM;
SM = SM / 10.24;
LT = analogRead(LTS);
LT = 1024 - LT;
LT = LT / 10.24;
minSM = EEPROM.read(0);
maxSM = EEPROM.read(1);
minLT = EEPROM.read(2);
maxLT = EEPROM.read(3);
}
void loop()
{
LT = analogRead(LTS);
LT = 1024 - LT;
LT = LT / 10.24;
SM = analogRead(SMS);
SM = 1024 - SM;
SM = SM / 10.24;
maxminchange();
printstats();
delay(5000);
}
void maxminchange()
{
if (SM < minSM)
{
minSM = SM;
EEPROM.write(0, minSM);
}
if (SM > maxSM)
{
maxSM = SM;
EEPROM.write(1, maxSM);
}
if (LT < minLT)
{
minLT = LT;
EEPROM.write(3, minLT);
}
if (LT > maxLT)
{
maxLT = LT;
EEPROM.write(4, maxLT);
}
}
void printstats()
{
Serial.println("----------------------");
Serial.println("Current Soil Moisture:");
Serial.println(SM);
Serial.println("Min Soil Moisture:");
Serial.println(minSM);
Serial.println("Max Soil Moisture:");
Serial.println(maxSM);
Serial.println();
Serial.println("Current Light Level:");
Serial.println(LT);
Serial.println("Min Light Level:");
Serial.println(minLT);
Serial.println("Max Light Level:");
Serial.println(maxLT);
Serial.println();
if (watering == true)
{
Serial.println("Watering");
}
else
{
Serial.println("Not Watering");
}
Serial.println("----------------------");
Serial.println();
}
I have attached the files to save you the trouble of copying and pasting.
Thanks for looking, and make sure to post about how it could be improved!
058606
runOnce.pde (608 Bytes)
gardenBot.pde (1.61 KB)