Water pump controlled by soil moisture sensor I'm just learning to code in Arduino. 

The purpose is that first the sensor measures the moist level (I mapped the reading values from 0 to 100). If the value is less than threshold 70, then it will turn on a water pump. As soon as the value goes beyond 70, the pump stops pumping water.

The problem is that even when the value is less than 70, the pump doesn't work. 

I tried replacing the pump with a LED, it turns on a the right moment. I tested the pump itself, and it also works perfectly.


//for mapping values
int mostMoist = 100;
int leastMoist = 600;
int percent;

//direct value from sensor
int raw;

//threshold for minimum percentage to turn on pump
const int threshold = 70;

//initial state of water pump
bool dosomething = false;

void setup() {
  Serial.begin(9600);
  pinMode(13, OUTPUT);
}

void loop() {
  //if it's not pumping water:
  while (dosomething == false){
  //check sensor value, map out of 100, and display on monitor   
  raw = analogRead(A0);
  percent = map(raw,leastMoist,mostMoist,0,100);
  if (percent &lt; 0){
    percent = 0;
  }
  Serial.println(percent);
  Serial.println("dosomething is set to false");


  //check if percentage moist is less than threshold. if so, set dosomething true, orelse, loop dosomething false
  if (percent&lt;threshold){
    dosomething = true;
  } else{
    dosomething = false;
  }
  delay(2);  
  }



  //if it's pumping water:
  while (dosomething==true){
  //check sensor value, map out of 100, and display on monitor
  raw = analogRead(A0);
  percent = map(raw,leastMoist,mostMoist,0,100);
  if (percent &lt; 0){
    percent = 0;
  }
  //turn on pump
  digitalWrite(13,HIGH);
  Serial.println("dosomething is set to true");
  //check if percent moist is less than threshold value, if so, loop dosomething true, orelse, set dosomething false
    if (percent&lt;threshold){
    dosomething = true;
  } else{
    dosomething = false;
  }
    Serial.println(percent);
  delay(2);  
  } 


}
I don't see a second power-supply in your photo. If you're trying to run the pump directly from an Arduino pin, it is highly likely that the pump needs way more current than the pin can supply.

It may be possible to power the motor from the USB but 1) the Uno board doesn't make that readily available, 2) it puts your PC at some risk (of back-EMF or of over-drawing the port's capability. But the ideal would be a separate power supply (don't forget to connect that supply's ground to the Uno's ground).

Also, if you tested the pump while dry it may have been able to run, yet with water in it, have been unable pull enough starting current to get going.