Go Down

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

talasb

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");
      digitalWrite(4,HIGH);
    }
     else if ((value > 300) && (value <= 500))
     {   
      Serial.println("AVERAGE Rain");
       digitalWrite(4,HIGH);

      }
     
      else {
        Serial.println("Dry Weather");
 
        }
        delay(100);}





Idahowalker

#1
May 02, 2019, 04:58 pm Last Edit: May 02, 2019, 05:00 pm by Idahowalker
Does
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?

talasb

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

groundFungus

#3
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.

talasb

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

groundFungus

#5
May 02, 2019, 05:37 pm Last Edit: May 02, 2019, 05:41 pm by groundFungus
Quote
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