I am in the middle of a project that uses a moisture sensor to turn on a water pump if the soil is too dry.
Can the pump be connected straight into the board? I am using an MKR1000.
I am quite new at this and literally barely have a clue what im doing. Any help or examples of this would be appreciated.
Thanks
This is the pump I bought. As its wuite small would a transistor be used?
Thanks very much, I appreciate it
This is the code I have atm, unfortunately I am unable to build my circuit as a few parts have not yet arrived. Can anyone tell me if they spot any mistakes?
It is so a pump(pump_pin) will be turned on when the moisture levels (sensor_pin)are too low.
thanks
int sensor_pin = 0;
int pump_pin = 1;
int led_pin = 2;
int sensor_value = 250;
int moisture;
const long oneSecond = 1000;
const long oneMinute = oneSecond * 60;
const long oneHour = oneMinute * 60;
const long sixHour = oneHour * 6;
const long twelveHour = oneHour * 12;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600); //setting the data rate between MKR1000 board and PC for communication
while(!Serial); //wait until serial port is ready
pinMode(sensor_pin, INPUT);
pinMode(pump_pin, OUTPUT);
digitalWrite(sensor_pin, LOW); //Default setup
}
void loop() {
moisture = digitalRead(sensor_pin);
Serial.print("The moisture levels are: ");
Serial.print(moisture); //prints the values coming from the sensor on the screen
//Serial.printIn(sensor_value):
Serial.print("% \n");
if(moisture < sensor_value){
//if(sensor_value < 50){
digitalWrite(pump_pin, HIGH);
digitalWrite(led_pin, HIGH);
delay(oneMinute);
}
else if (moisture > sensor_value){
digitalWrite(pump_pin, LOW);
digitalWrite(led_pin, LOW);
delay(sixHour);
}
}