Code
Code
void setup() {
void loop()
{
if (Serial.available()) //loop to operate motor
{
int speed = Serial.parseInt(); // to read the number entered as text in the
Serial Monitor
if (speed >= 0 && speed <= 255)
{
analogWrite(WATERPUMP, speed);// tuns on the motor at specified speed
}
}
val = digitalRead(8); //Read data from soil moisture sensor
if(val == LOW)
{
digitalWrite(13,LOW); //if soil moisture sensor provides LOW value send LOW value
to motor pump and motor pump goes off
}
else
{
digitalWrite(13,HIGH); //if soil moisture sensor provides HIGH value send HIGH
value to motor pump and motor pump get on
}
delay(400); //Wait for few second and then continue the loop.
}