Arduino nano digital pins occasionally not working

Question:
I bought an Arduino nano clone a couple of months ago on ebay. When I plug it in, the nano lights up and works and everything, the problem I am having with it is that every so often I plug it in, the digital pins don't get powered. There is nothing wrong with my code or circuit because it works sometimes(I have to unplug the Arduino, plug it back in and then reload the sketch) and works perfectly. So my question is, is this a software problem with my Arduino Chinese clone, or could it be a hardware problem, because my header pins are poorly soldered(they are on the board and have a good connection, but doesn't look nice.)

My Goal:
I am trying to make an automatic plant waterer for my indoor house plant using a soil moisture sensor and a mini liquid pump. When I attach my sensor to analog pin 0 it reads fine. Although, when I use my pump (pin 11)when the sensor is below a certain point, sometimes it does not work. For me to get it to work again, I would need to unplug the arduino, plug it back in and reload the sketch.

Code:

int sensor = 0;
int pump = 11;
int ledGreen = 12;
int ledRed = 13;
void setup()  {
  pinMode(pump, OUTPUT);
  pinMode(sensor, INPUT);
  Serial.begin(9600);  
}
void loop(){
  float value = analogRead(sensor);
  float dryPercentage = (value / 1023) * 100;
  float moistPercentage = 100 - dryPercentage;
  Serial.print(moistPercentage);
  Serial.println();
  delay(1000); 
  if(moistPercentage < 50){
    Serial.print("Dry, watering now: ");
    digitalWrite(pump, HIGH);
    digitalWrite(ledRed, HIGH);
    digitalWrite(ledGreen, LOW);
  }else{
    Serial.print("Soil Moisture optimal: ");
    digitalWrite(pump, LOW);
    digitalWrite(ledGreen, HIGH);
    digitalWrite(ledRed, LOW);
  }
}

Note:
-The red led works fine when detecting the signal from the sensor(however green does not).
-The pump works fine when connected to the 5v, so the pump is not broken.
-I've had this problem with many of the outputs in the past(motor, buzzer)

stuartfong:
because it works sometimes(I have to unplug the Arduino, plug it back in and then reload the sketch) and works perfectly.

does NOT exclude:

stuartfong:
There is nothing wrong with my code or circuit

I never had a problem with a Chinese clone. And it shouldn't be, all it is is a ATmega32p soldered to a board. And even if it was a fake ATmega32p, I never came across a not working one and an intermediate fault would be rare. Bad soldering might happen.

stuartfong:
and reload the sketch.

You never need to reload the sketch unless you made a bug with EEPROM :wink:

And what do you mean by "does notwork"? That's the most terrible phrase when troubleshooting. Doesn't it become HIGH or LOW? Did you try to add debug info (serial prints)? And if yes, what is the output when it goes wrong?

And how is it actually connected?

And what powers it?

Aka, your jumping to conclusions :wink:

The Arduino is powered by my computer, and when I mean does not work, I mean it returns nothing at all(not powered). and the times that it does work the serial prints still do print correctly, as I mentioned, everything else seems to work fine except output like motors, pumps, etc.

stuartfong:
The Arduino is powered by my computer

That might be the problem. But we have no idea what is connected so we can't say for sure...

stuartfong:
, and when I mean does not work, I mean it returns nothing at all(not powered).

Aka floating or stays LOW?

stuartfong:
and the times that it does work the serial prints still do print correctly,

We're a bunch of non-believers :wink: Please show us!

stuartfong:
as I mentioned, everything else seems to work fine except output like motors, pumps, etc.

Time for a schematic :wink: NOT a Fritzing mess or only a photo... Hand drawing will do.

Sorry, I don't know how to make a hand drawing of a circuit, I made a Fritzing sketch and made it as neat as possible! Please let me know if anything is unclear or covered up. Forgot to mention this earlier but I am fairly new to Arduino, started a couple of months ago, barely touched it until the beginning of summer.

You haven't set the led pins as OUTPUTs, so start by calling pinMode on those...

I've just finished doing that. Could the problem be that when I remove the wire that's connected to my pump and plug it back in that I have to power off the Arduino and power it on again?

How do you have the pump hooked up? Where does it get it's power? A simple diagram would help a lot.

Hi,

Please do not connect or disconnect anything from your controller with the power ON.

Tom.... :slight_smile:

stuartfong:
Sorry, I don't know how to make a hand drawing of a circuit

Do you have paper? A pen(cil)? You know how to use them? That's already 90%! And Google can help you with symbols for electronic components :wink:

But for now, I see LEDs without resistors, a motor without a driver and you all try to power it from a poor USB port. No wonder it does not work :wink: