Project showcase

Automated Home Garden + Timelapse © LGPL

Gardening is a very long time taking task every day. In this tutorial, I will show how to make everything automated in an easy way.

  • 530 views
  • 1 comment
  • 4 respects

Components and supplies

Apps and online services

About this project

About This Project

What's Connected

  • Arduino UNO
  • Raspberry Pi any should work
  • Ethernet shield arduino
  • Relay
  • Wire (I like these wire they are already cut in different size but it's obviously optional)
  • Photoresistor
  • Soil moisture
  • Water pump
  • Pipe
  • Fan (I used the one from an old computer)
  • Transistor
  • Light
  • Humidity/temperature sensor
  • Raspberry Pi camera
  • SD card 16GB 8Gb would work but will be short for time lapse

Setting Up the Arduino

In order to monitor our farm, I took a few devices which can be helpful. Before to start, remember to connect the Ethernet shield to the Arduino.

Soil moisture:

To check if the plants need water:

  • VCC: 5v
  • GND:GND
  • A0: A1

The Fan:

If it gets too hot it will activate or just give some fresh air.

  • One wire goes from the resistor to pin 3.
  • The GND of the fan goes on the middle pin of the transistor.
  • The + of the fan goes to the relay (middle pin)
  • The last pin of the transistor goes to GND
  • The diode goes to the middle pin of transistor and to the GND

The water pump:

  • This part will allow us to measure if there is enough light in the room One part is connected to A0 with the resistor connected to the ground. The other one to the 5v
  • the + goes to midlle on the relay and GND to GND of the power source

Photoresistor (optional):

This part will allow us to measure if there is enough light in the room

  • One part is connected to A0 with the resistor connected to the ground.
  • The other one to the 5v.
  • The anode(+) goes to the relay The other to the GND of the power supply.

Light:

The anode(+) goes to the relay The other to the GND of the power supply.

Humidity /temperature sensor:

Some codes are required for this device in order to work properly with Cayenne.

  • VCC: 3.3V
  • GND:GND
  • DAT:digital pin 8

Water level sensor:

  • VCC:5V
  • GND:GND
  • SIG:A2

Final Mounting

See the final schema.

I used 2 relays in the graphic. Fritzing does not have relay 4channel yet.

Important for the relay I used only one 12v power supply. I separated the wire positive and negative then solder 3 wire from the positive and connect each part on the relay.

One is enough as everything does not turn on at the same time. I used a 5v power supply for the Arduino.

Relay:

  • VCC: 5V
  • GND: GND
  • IN1: PIN2 Activate the light
  • IN2: PIN5 Activate the water pump
  • IN3: none IN4
  • PiN4: activate the FAN

Cayenne Pre Required

Here we will see how to configure Cayenne which is very easy. First create an account here. Then you should have your Ethernet shield with RJ45 cable connected.

Here is the code to connect to Cayenne and also to configure the hum/temp sensor. This code works for the w5100 shield. The code is available on Cayenne for other Ethernet/WiFi shield. Also don't forget to add your token you get it after creating your account.

#include "DHT.h"<br>//#define CAYENNE_DEBUG         // Uncomment to show debug messages<br>#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include </p><p>#define DHTPIN 8     // what digital pin we're connected to
#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321</p><p>#define VIRT_TEMP V1
#define VIRT_HUM V2</p><p>// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "your toker";</p><p>DHT dht(DHTPIN, DHTTYPE);
unsigned long prev_DHT_refresh, interval_DHT_refresh = 1000;</p><p>void setup()
{
  Serial.begin(9600);
  Cayenne.begin(token);</p><p>  dht.begin();
}</p><p>void loop()
{
  Cayenne.run();  getDhtValues();
}void getDhtValues() {  unsigned long now = millis();
 if (now - prev_DHT_refresh > interval_DHT_refresh) {
    // Reading temperature or humidity takes about 250 milliseconds!
    // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
    float h = dht.readHumidity();
    // Read temperature as Celsius (the default)
    float t = dht.readTemperature();</p><p>    // Check if any reads failed
    if (!isnan(h) && !isnan(t)) {
      Cayenne.virtualWrite(VIRT_HUM, h);
      Cayenne.celsiusWrite(VIRT_TEMP, t);
    }
    prev_DHT_refresh = now;
  }
}

Configuration Cayenne:

We're almost done for Arduino, and now it's the easy part. We're going to add all the devices on Cayenne, check the picture.

  • GO to add device
  • Custom widget
  • Select the kind of widget you like. I used chart for humidity and water level otherwise I used value
  • For the humidity temp sensor we use virtual pin
  • Temp: Vpin1
  • Humidity: VPin2

For the other device, instead of choosing virtual pin, take analog with the pin and link to it. The data will be voltage.

Relay:

Same procedure, but this time in actuators. Then select the pin of the Arduino connected to the relay for the light/fan/water pump.

Event and Trigger

Now that we have the dashboard we gonna finish the configuration.

Trigger:

  • Water pump: This will turn on the pump when the soil moisture detects it's too dry. Notice I used 2 triggers, one to start the water pump and to stop.
  • Water level: When the value is high means water is missing. Here we will receive an email to alert us.
  • Event: I set up 4 events, one to start the light in the morning and one to stop it in the evening, 2 for the fan on/off.

Raspberry:

Let's do a time lapse of the plant growing.

3 Software:

  • Raspbian
  • Win32diskimager to burn the image on the SD card
  • Putty to connect in remote to the Raspberry

WIn32 disk imager:

After download install it, open it.

  • You will see "device," in general the default is good (if you only have the SD card connected)
  • Click on the blue icon folder and select the Raspbian image you have downloaded
  • Click write and it's done. You can now insert the card to the Raspberry.

Putty:

It allows us to connect via SSH, open Putty (no need to install).

  • Connect internet cable to the Raspberry
  • You need to find the IP of the raspberry 2 easy way
  • Connect to your box interface you will be able to see the device with the IP
  • Connect the touchscreen and keyboard go to terminal then ifconfig. Now in Putty enter the IP address will be something like 192.168.0.3 then enter
  • it will ask to trust click yes (picture)
  • login: Pi, password: Raspberry. Leave the windows on the side we will come back here later

Now that we have the Raspberry running few update are needed so in Putty copy paste the command:

sudo apt-get update
sudo apt-get upgrade

VNC:

If you don't have a screen to connect your Raspberry install VNC to remote control.

sudo apt-get install tightvncserver

When finished, start the server:

vncserver :1

Download vncviewer on your computer to connect, enter IP and number server. It will look like this 192.168.0.3:1

Cayenne:

You can take remote control of you Raspberry with Cayenne, only have to install it:

wget https://cayenne.mydevices.com/dl/rpi_03wl1tt4nt.sh
sudo bash rpi_03wl1tt4nt.sh -v

Timelapse

Last step!

We can now enable the camera to do so in Putty or in a terminal paste:

sudo raspi-config 

then go to enable camera. We have to create a folder to store the picture.

cd /home/pi/Desktop
mkdir timelapse

After plugging the webcam we gonna create a script to take picture every hour.

cd /home/pi/Desktop 
nano timelapse.sh

Paste this:

SAVEDIR=/home/pi/Desktop/timelapse/
while [ true ]; 
do filename=-$(date -u +"%d%m%Y_%H%M-%S").jpg
/opt/vc/bin/raspistill -o $SAVEDIR/$filename
sleep 3600;
done;

And to make sure the script is executable

chmod +x timelapse.sh

Conclusion:

The tutorial was long, but very easy. Just few devices to connect and configure the platform. On the picture is a big messy because I use too long wire. I will post the result of my time lapse when the plants are done growing.

Advice:

The Ethernet shield can get the error DHCP fail when trying to connect. I found the solution on Arduino forum. You have to solder two 100 oHm resistors.

Code

Code snippet #1Plain text
#include "DHT.h"<br>//#define CAYENNE_DEBUG         // Uncomment to show debug messages<br>#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include </p><p>#define DHTPIN 8     // what digital pin we're connected to
#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321</p><p>#define VIRT_TEMP V1
#define VIRT_HUM V2</p><p>// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "your toker";</p><p>DHT dht(DHTPIN, DHTTYPE);
unsigned long prev_DHT_refresh, interval_DHT_refresh = 1000;</p><p>void setup()
{
  Serial.begin(9600);
  Cayenne.begin(token);</p><p>  dht.begin();
}</p><p>void loop()
{
  Cayenne.run();  getDhtValues();
Code snippet #2Plain text
#include "DHT.h"<br>//#define CAYENNE_DEBUG         // Uncomment to show debug messages<br>#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include </p><p>#define DHTPIN 8     // what digital pin we're connected to
#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321</p><p>#define VIRT_TEMP V1
#define VIRT_HUM V2</p><p>// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "your toker";</p><p>DHT dht(DHTPIN, DHTTYPE);
unsigned long prev_DHT_refresh, interval_DHT_refresh = 1000;</p><p>void setup()
{
  Serial.begin(9600);
  Cayenne.begin(token);</p><p>  dht.begin();
}</p><p>void loop()
{
  Cayenne.run();  getDhtValues();
Code snippet #3Plain text
  if (now - prev_DHT_refresh > interval_DHT_refresh) {
    // Reading temperature or humidity takes about 250 milliseconds!
    // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
    float h = dht.readHumidity();
    // Read temperature as Celsius (the default)
    float t = dht.readTemperature();</p><p>    // Check if any reads failed
    if (!isnan(h) && !isnan(t)) {
      Cayenne.virtualWrite(VIRT_HUM, h);
      Cayenne.celsiusWrite(VIRT_TEMP, t);
    }
    prev_DHT_refresh = now;
  }
}
Code snippet #4Plain text
  if (now - prev_DHT_refresh > interval_DHT_refresh) {
    // Reading temperature or humidity takes about 250 milliseconds!
    // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
    float h = dht.readHumidity();
    // Read temperature as Celsius (the default)
    float t = dht.readTemperature();</p><p>    // Check if any reads failed
    if (!isnan(h) && !isnan(t)) {
      Cayenne.virtualWrite(VIRT_HUM, h);
      Cayenne.celsiusWrite(VIRT_TEMP, t);
    }
    prev_DHT_refresh = now;
  }
}
Code snippet #13Plain text
SAVEDIR=/home/pi/Desktop/timelapse/

while [ true ]; 

do filename=-$(date -u +"%d%m%Y_%H%M-%S").jpg
/opt/vc/bin/raspistill -o $SAVEDIR/$filename
sleep 3600;
done;
Code snippet #14Plain text
SAVEDIR=/home/pi/Desktop/timelapse/

while [ true ]; 

do filename=-$(date -u +"%d%m%Y_%H%M-%S").jpg
/opt/vc/bin/raspistill -o $SAVEDIR/$filename
sleep 3600;
done;

Comments

Similar projects you might like

LED Roulette Game

Project tutorial by Arduino “having11” Guy

  • 66 views
  • 0 comments
  • 3 respects

Using 9 Axes Motion Shield with Arduino

by Techduino

  • 54 views
  • 0 comments
  • 3 respects

Guess the Number With Arduino KeyPad

Project tutorial by Giovanni Gentile

  • 116 views
  • 2 comments
  • 3 respects

Bluetooth Control Multitap

Project showcase by gledel and 윤원호

  • 96 views
  • 0 comments
  • 2 respects

Know the Temp of Your Home From Anywhere with Arduino Cloud!

Project tutorial by Isaac100

  • 2,108 views
  • 2 comments
  • 11 respects

Launch Pad Count Down Sequence Display

Project in progress by Douglas Frey

  • 111 views
  • 0 comments
  • 2 respects
Add projectSign up / Login