Moisture sensor with pump

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

Generally you wouldn't connect a motor directly to the board. You should either use a transistor to switch it or a relay or perhaps you need a motor driver depending on what type of motor it is. You kind of left that critical piece of information out.

This is the pump I bought. As its wuite small would a transistor be used?

marcdoole:
This is the pump I bought. As its wuite small would a transistor be used?

It's about the type of motor, not the size.

That looks like it is probably a regular old brushed DC motor. In that case you would use a transistor or a relay. There are tons of examples online of how to switch a DC motor from an Arduino.

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);
}

}

moisture = digitalRead(sensor_pin);

digitalRead gets digital data. HIGH or LOW which are defined as 1 or 0 respectively.

if(moisture < sensor_value)

Both HIGH and LOW will be less than sensor_value all the time.

  1. Please read the "How to use this forum - please read" thread and learnt he forum rules for posting code.

  2. Have a look at the internet and see if you can find some examples where others are using that sensor. How do they read the sensor?