How to run a 12V water pump with soil moisture sensor



The best way you can run a 12V dc motor with Arduino is to use L293D, which can supply from 5volts to 36volts. The below diagram is for a soil moisture sensor with a motor which could be 12V DC.
Pins:
  • Pin 1,16 and 9 are for Arduino 5V only.
  • Pin 4,5,12 and 13 are for both Arduino and external power ground.
  • Pin 8 is for only external VCC.
  • Pin 3 and 6 are for motor.
  • Pin 2 and 7 are for controlling the motor which ever way you want.
Let's see the sketch now.

int motorf = 2;
int motorb = 7;


void setup() {
// initialize serial communication at 9600 bits per second:
pinMode(motorf, OUTPUT);
pinMode(motorb, OUTPUT);
Serial.begin(9600);
}


void loop() {
// read the input on analog pin 1:
int sensorValue1 = analogRead(A1);

if (sensorValue1 >=600){
Serial.println(sensorValue1);
  digitalWrite(motorb, HIGH);
  }
  else {
Serial.println(sensorValue1);
  digitalWrite(motorb, LOW);
  }
 
delay(500);
}

int motorf = 2;  This is for motor to spin one way.
int motorb = 7;  And this is for motor to spin other way.

To control the spin of the motor you simply change "f" to "b" or "b" to "f" in [ digitalWrite(motorb, HIGH); ]

if (sensorValue1 >=600){ This means if moisture reading is above 600 then it will turn on the motor.


delay(500); This means it will get the reading every half a second, you can increase as you like.


2 comments:

  1. I can see that you are an expert at your field! I am launching a website soon, and your information will be very useful for me.. Thanks for all your help and wishing you all the success in your business. small fountain pumps by Danner

    ReplyDelete
  2. You need a minimized, calm, and powerful siphon that can work for in any event the initial a half year of the child's life, or anyway long you intend to bosom feed.Warmtepomp

    ReplyDelete



Newly posted:
Reason why rich getting richer and poor getting poorer