safwan092

Project-code-pump-with-relay

Jul 13th, 2020
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.34 KB | None | 0 0
  1. int WATERPUMP = 12; //motor pump connected to pin 13
  2. int sensor = 8; //sensor digital pin vonnected to pin 8
  3. int val; //This variable stores the value received from Soil moisture sensor.
  4.  
  5. void setup() {
  6.  
  7.   pinMode(WATERPUMP,OUTPUT); //Set pin 13 as OUTPUT pin
  8.   pinMode(sensor,INPUT); //Set pin 8 as input pin, to receive data from Soil moisture sensor.
  9.   //Initialize serial and wait for port to open:
  10.   //Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
  11.   //while (! Serial);// wait for serial port to connect. Needed for native USB
  12.   //Serial.println("Speed 0 to 255");
  13. }
  14.  
  15. void loop()
  16.   {
  17.   /*if (Serial.available()) //loop to operate motor
  18.   {
  19.     int speed = Serial.parseInt(); // to read the number entered as text in the Serial Monitor
  20.     if (speed >= 0 && speed <= 255)
  21.     {
  22.       analogWrite(WATERPUMP, speed);// tuns on the motor at specified speed
  23.     }
  24.   }*/
  25.   val = digitalRead(sensor);  //Read data from soil moisture sensor  
  26.   if(val == LOW)
  27.   {
  28.   digitalWrite(WATERPUMP,LOW); //if soil moisture sensor provides LOW value send LOW value to motor pump and motor pump goes off
  29.   }
  30.   else
  31.   {
  32.   digitalWrite(WATERPUMP,HIGH); //if soil moisture sensor provides HIGH value send HIGH value to motor pump and motor pump get on
  33.     }
  34.     delay(500);//Wait for few second and then continue the loop.
  35. }
Add Comment
Please, Sign In to add comment