Introduction: Automated FARM Arduino (fan,lights,water Pump)

Picture of Automated FARM Arduino (fan,lights,water Pump)

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

-Relay

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

-Photo resistor

-Soil moisture

-Water pump

-Pipe

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

Diode 1n4007

Transistor

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

Optional:

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

Picture of 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

FAN:

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

LIGHT:

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

Picture of 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

RELAY:

VCC: 5V

GND: GND

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(5,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
 Serial.println(value);  
 if(value<5)  //modify here the value
 {  
     
   digitalWrite(5, HIGH);  
     
 }  
 else  
 {  
   digitalWrite(5, LOW);  
 } 
  }

Step 5: Conclusion

Picture of 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

Comments

BoxerSamuel (author)2017-09-10

so i built the system and imported the code, and I turned it on and the relay light will turn on for the light sensor when it gets dark but it won't turn the light on, same with the pump and the fan. I have already checked the wiring and it looked good. I was wondering if you had any idea on what is wrong

Thomas sxt (author)BoxerSamuel2017-10-19

For the light maybe try change the variable of darkness , otherwise if none of three are working it looks like a material issue because they are working separately for example the fan is program to work a certain amount of time so nothing to do with the light or the pump

BoxerSamuel (author)Thomas sxt2017-10-19

Awesome, thank you!

sagabals (author)2017-09-03

please, any seed ?

Thomas sxt (author)sagabals2017-10-19

Hello sorry for the delay, yes any seed more or less , i am not an expert but you will have to check how much light water etc they need

sagabals (author)2017-09-03

thomas, thank you for this code. what seed can be plant ?

BoxerSamuel (author)2017-08-20

also can you use a zener diode instead of the one you use?

Thomas sxt (author)BoxerSamuel2017-08-24

Yes there is nothing mandatory just check it's the right voltage .

BoxerSamuel (author)2017-08-14

question on the relay vcc goes to 5v, where does that go since something is already plugged in. Also GND goes to GND, but which GND port?

Thomas sxt (author)BoxerSamuel2017-08-15

You have two 5v on the arduino same for GND and it doesn't matter its the ground .

PaulG353 (author)2017-03-16

Hello Thomas, you didn't precise the value of the resistance which is connected to the fan, is it a 10k like the photoresistor?
Thank you

Thomas sxt (author)PaulG3532017-03-16

Hello , you can connect the fan directly to the relay without the transistor and resistor otherwise 10k will do.

TomK167 (author)2017-02-14

I've copied the code in and...

Arduino: 1.8.1 (Windows 10), Board: "Arduino/Genuino Uno"

sketch_feb14a:1: error: expected unqualified-id before '<' token

<p>int PROBE= 1;<br>int value= 0;

^

sketch_feb14a:1: error: expected unqualified-id before '<' token

<p>int PROBE= 1;<br>int value= 0;

^

sketch_feb14a:9: error: expected unqualified-id before '{' token

{

^

C:\Users\Tom\AppData\Local\Temp\arduino_modified_sketch_490438\sketch_feb14a.ino: In function 'void loop()':

sketch_feb14a:47: error: 'value' was not declared in this scope

value= analogRead(PROBE);

^

sketch_feb14a:47: error: 'PROBE' was not declared in this scope

value= analogRead(PROBE);

^

C:\Users\Tom\AppData\Local\Temp\arduino_modified_sketch_490438\sketch_feb14a.ino: At global scope:

sketch_feb14a:60: error: expected unqualified-id before '<' token

}</p>

^

exit status 1
expected unqualified-id before '<' token

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Thomas sxt (author)TomK1672017-02-14

Hi,

It was because some HTML tag got inside the code... ( the <p>)

I changed it it will worked now

IdhamZ1 (author)2016-10-01

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

gustavio101 (author)IdhamZ12016-10-18

You have no following command for "if" nor for "else" in about the middle of your picture. Either delete that or fix it by filling in what you want it to do.

Example:

if (sensorvalue > 400)

{

digitalWrite(relay, HIGH); // Or whatever you would like to happen next

}

else

{

digitalWrite(relay, LOW);

}

Thomas sxt (author)2016-10-08

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

ErcanB (author)2016-10-07

Light is ineffective in your system depands on plants groeth.

Thomas sxt (author)2016-10-03

Please re upload the code i made some improvement.

Thomas sxt (author)2016-10-02

Yes you were righ somehow one line of then code dissapeared , i have modify the code now will be fine.

The line missing was :if(sensorValue > 400) //Modify here for the light

digitalWrite(2,HIGH); //turn relay ON

else digitalWrite(2,LOW); //turn relay OFF

Let me know how it goes !

About This Instructable

6,110views

91favorites

License:

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