Go Down

Topic: using submersible 5v water pump for irrigation system (Read 310 times) previous topic - next topic


Hello, I'm building a smart irrigation system and I'm trying to make the motor pump work depending on the rain sensor value, but it is not working for some reason, however, the rain sensor alone is working and displaying the right value and this is my code:

Code: [Select]
void setup () {
  // initialize serial communication at 9600 bits per second
  Serial.begin (9600);
  pinMode(4,OUTPUT); //for the pump
  void loop() {
    // read the input on analog pin 0:
    int value = analogRead(A0); //for the rain sensor
    if (value > 500) {   
     Serial.println("Very heavy Rain");
     else if ((value > 300) && (value <= 500))
      Serial.println("AVERAGE Rain");

      else {
        Serial.println("Dry Weather");


May 02, 2019, 04:58 pm Last Edit: May 02, 2019, 05:00 pm by Idahowalker
Code: [Select]
digitalWrite(4,HIGH);enable the motor? When does
Code: [Select]
digitalWrite(4, LOW); happen, not saying that this is the issue you are having.

Do the serial prints happen?


I wrote that line of code every time there is average or heavy rain, so it is supposed to work whenever there is water (just for testing) and the prints saying 'average rain' does happen


May 02, 2019, 05:01 pm Last Edit: May 02, 2019, 05:03 pm by groundFungus
I have to guess that pin 4 controls the pump?  Is a HIGH on pin 4 pump on or off?  If HIGH is on where do you ever turn the pump off?  What is the pump motor driver?  The Arduino pin cannot drive a pump without a transistor or motor driver.  A schematic that shows all components and power supplies would be helpful.

Naming the pins makes the code easier to follow and commenting the code lets us know what is supposed to happen.


The pump would be off when there is rain but right now just for testing I just wanted to make sure the pump is working, and I used this video as a reference: https://www.youtube.com/watch?v=eZwzJMWs50o&t=170s

In the video a motor wasn't used, just the pump


May 02, 2019, 05:37 pm Last Edit: May 02, 2019, 05:41 pm by groundFungus
In the video a motor wasn't used, just the pump
The pump is driven by a motor.  In the video the poster is driving the motor (pump) with an Arduino pin.  BAD idea.  There is no flyback diode to absorb the back EMF that the motor generates when the motor is powered off.  BAD idea.  If your Arduino is not damaged it would just be lucky.

Here is a simple logic level MOSFET motor driver.

Choose the MOSFET based on the motor stall current (to be found on the pump data sheet).

Go Up