Thomas sxt
Published © CERN-OHL

Automated FARM (fan, lights, water Pump)

Gardening is very long task taking time every day.

BeginnerFull instructions provided2 hours1,529
Automated FARM (fan, lights, water Pump)

Things used in this project

Story

Read more

Schematics

schema automatic watering

Code

Code snippet #1

Plain text
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);  
 } 
  }

Credits

Thomas sxt

Thomas sxt

7 projects • 24 followers
🔩Maker Arduino Rasp. 🖨️3DPrint/design creation ! My STL:https://cults3d.com/fr/utilisateurs/diyfunproject 📲WEBSITE:diyfp.fr/thomassxt

Comments