Gardening is very long task taking time every day .

In this tutorial i will show how to make everything automated in a easy way .

The arduino will automatically detect if the plants need something.

-When it's getting dark the light will turn on.

-If the plants need water it's activate the water pump.

-Every few hours the fan will turn on to give some fresh air.

And a timelapse.

Step 1: What You Need :

Let's have look :

-Arduino uno


-Wire i like these wire they are already cut in different size but it's obviously optional

-Photo resistor

-Soil moisture

-Water pump


-FAN i used a 12v from an old computer: (zalman)

Diode 1n4007


-Light If you can't order this one check "12v light Photosynthesis"


To get the project funnier i added a raspberry pi with camera to get a timelapse, if you interrested i will add a tutorial to set it up (very easy)

Step 2: Getting Started

It can look complicated but if you do part by part is simple:

Soil moisture:

To mesure if the plants need water we gonna mesure the humidity .

One pin goes to 5V , other one to ground and third the anolog to A1

Light sensor:

This part will allow us to mesure 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


This will be the most complicated of the project if you don't want a fan just skip it.

I posted one photo without the relay to get better idea.

- 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 midlle pin of transistor and to the GND


The anode(+) goes to the relay

The other to the GND of the power supply

Water Pump:

Still the same the + goes to midlle on the relay and GND to GND of the power source

We almost done! Just need to connect the relay to the arduino and updload the code .

Step 3: Final Schema

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

Important for the relay i used only one 12v power supply , i separate 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




IN1: PIN2 Activate the light

IN2: PIN5 Activate the water pump

IN3: none

IN4: PiN4 activate the FAN

Step 4: The Code

To finish upload the code to the arduinio.

I wrote comment on the line to modify if you want to change the value (when to turn on the light or the water pump or how long the fan must be on or off).

Don't pay attention to the name of the variable as they are not relevant .

int PROBE= 1;
int value= 0; 
int TIP120pin = 3; //for this project, 
int ledState = LOW;             // 
unsigned long previousMillis = 0;        // will store last time LED was updated
long OnTime = 3600000;           // milliseconds of on-time FAN modify here
long OffTime = 60000;          // milliseconds of off-time FAN modify here
 int sensorPin = A0;   // select the input pin 
int sensorValue = 0;  // variable to store the value coming from the sensor

void setup() 
  // set the digital pin as output:
  pinMode(TIP120pin, OUTPUT); // Set pin for output to control TIP120 Base pin    
pinMode(4, OUTPUT);
  pinMode(2, OUTPUT); //pin connected to the relay
  Serial.begin(9600); //sets serial port for communication
void loop()
  // check to see if it's time to change the state of the FAN
  unsigned long currentMillis = millis();
  if((ledState == HIGH) && (currentMillis - previousMillis >= OnTime))
    ledState = LOW;  // Turn fan off
    digitalWrite(4,LOW);//tur off the relay
    previousMillis = currentMillis;  // Remember the time
    digitalWrite(TIP120pin, ledState);  // Update
  else if ((ledState == LOW) && (currentMillis - previousMillis >= OffTime))
    ledState = HIGH;  // turn fan on
    digitalWrite(4,HIGH);// turn on the relay
    previousMillis = currentMillis;   // Remember the time
    digitalWrite(TIP120pin, ledState);    // Update 
  //code for the light
    sensorValue = analogRead(sensorPin);    
  Serial.println(sensorValue); //prints the values coming from the sensor on the screen
  if(sensorValue > 150) //Modify here for the light
  digitalWrite(2,HIGH); //turn relay ON
  else digitalWrite(2,LOW); //turn relay OFF
//code water pump
 value= analogRead(PROBE);  
 value= value/100;  //divided by 100
 if(value<5)  //modify here the value
   digitalWrite(5, HIGH);  
   digitalWrite(5, LOW);  

Step 5: Conclusion

If you respect the few steps in order will be very easy

My water pump is directly immerge into the water and the pipe deep in the ground , this is fine to get water everywhere in your farm but could be improve in order to control where the water is going.

Same for the soil moisture deep in the ground . Think to check it sometime because it gets damage fast .

The fan on the top to give fresh air or to renew it

For my use i kept the default value on the code but think maybe to modify it for the light to turn on when it's darker.

On the picture you can see it's a big mess i used to long cable so think carefully!

My plants grew up pretty fast but pay attention to what seeds you get mine are up to 90cm !

Looking forward for your comments of any improvement.

For the timelapse here

Hello Thomas, you didn't precise the value of the resistance which is connected to the fan, is it a 10k like the photoresistor?<br>Thank you
Hello , you can connect the fan directly to the relay without the transistor and resistor otherwise 10k will do.
<p>I've copied the code in and...</p><p>Arduino: 1.8.1 (Windows 10), Board: &quot;Arduino/Genuino Uno&quot;</p><p>sketch_feb14a:1: error: expected unqualified-id before '&lt;' token</p><p> &lt;p&gt;int PROBE= 1;&lt;br&gt;int value= 0; </p><p> ^</p><p>sketch_feb14a:1: error: expected unqualified-id before '&lt;' token</p><p> &lt;p&gt;int PROBE= 1;&lt;br&gt;int value= 0; </p><p> ^</p><p>sketch_feb14a:9: error: expected unqualified-id before '{' token</p><p> {</p><p> ^</p><p>C:\Users\Tom\AppData\Local\Temp\arduino_modified_sketch_490438\sketch_feb14a.ino: In function 'void loop()':</p><p>sketch_feb14a:47: error: 'value' was not declared in this scope</p><p> value= analogRead(PROBE); </p><p> ^</p><p>sketch_feb14a:47: error: 'PROBE' was not declared in this scope</p><p> value= analogRead(PROBE); </p><p> ^</p><p>C:\Users\Tom\AppData\Local\Temp\arduino_modified_sketch_490438\sketch_feb14a.ino: At global scope:</p><p>sketch_feb14a:60: error: expected unqualified-id before '&lt;' token</p><p> }&lt;/p&gt;</p><p> ^</p><p>exit status 1<br>expected unqualified-id before '&lt;' token</p><div>This report would have more information with<br>&quot;Show verbose output during compilation&quot;<br>option enabled in File -&gt; Preferences.</div>
<p>Hi,</p><p>It was because some HTML tag got inside the code... ( the &lt;p&gt;)</p><p>I changed it it will worked now</p>
<p>excuse me Sir, i had an error with your coding. When I try to verify the coding using arduino software version 1.6.9, it fail. What should I do to fix this error?? you can refer the picture I upload</p>
<p>You have no following command for &quot;if&quot; nor for &quot;else&quot; in about the middle of your picture. Either delete that or fix it by filling in what you want it to do.</p><p>Example:</p><p>if (sensorvalue &gt; 400)</p><p>{</p><p>digitalWrite(relay, HIGH); // Or whatever you would like to happen next</p><p>}</p><p>else</p><p>{</p><p>digitalWrite(relay, LOW); </p><p>}</p>
<p>Well most the plants grow better with sun/light and you can adapt the code to turn it on when you need ,so no it's not inneffective </p>
Light is ineffective in your system depands on plants groeth.
<p>Please re upload the code i made some improvement.</p>
<p>Yes you were righ somehow one line of then code dissapeared , i have modify the code now will be fine.</p><p>The line missing was :if(sensorValue &gt; 400) //Modify here for the light</p><p> digitalWrite(2,HIGH); //turn relay ON</p><p> else digitalWrite(2,LOW); //turn relay OFF</p><p>Let me know how it goes !</p>

About This Instructable




More by Thomas sxt:IOT Farm + Timelapse Cayenne Arduino/Raspberry Cocktail Machine With GUI Raspberry Auto Coffee machine bluetooth arduino + android app 
Add instructable to: