# Attiny85 water plant with mini water pump

Im new to electrical engineering, so it's probably a newbie problem.

I'm using a wall power supply(5V-2A) to power the DC Motor and the Attiny85.

A C1 470uF to make the power more stable. I don't know if it is necessary, but it helped.

A D1 green led to show if it's on.

A reset button connected to ground to reset(Duh).

One relay(833H-1C-C) connected to the digital pin 0 of the attiny to turn the motor on and off.

Two rotational potentiometer connected to two analog pins(2,3) to decide how much time the mini water pump will be on(0-1023 to 1s-30s) and the other to compare to the humidity sensor to decide how dry the soil will need to be to turn on the motor.

And one humidity sensor.

#include "kPot.h" // my library, just analogReads

#define HUMIDITY_PIN 1 //humidity sensor
#define LEVEL_PIN 3 //rotational potentiometer
#define TIMER_PIN 2 //rotational potentiometer
#define MOTOR_PIN 0 //connected to the relay switch

kPot humiditySensor = kPot(HUMIDITY_PIN, 10); //(pin, average of 10 reads)
kPot levelPot = kPot(LEVEL_PIN, 10);
kPot timerPot = kPot(TIMER_PIN, 10);

int humidity = 0;
int level = 0;
int timer = 0;

void setup() {
pinMode(MOTOR_PIN, HIGH);

}

void loop() {

timer = map(timer, 0, 1023, 1000, 30000); //1s to 30s

if(humidity < level){
digitalWrite(MOTOR_PIN, HIGH);
delay(timer);
digitalWrite(MOTOR_PIN, LOW);
}

delay(300000); // 5min Update
}
`

The problem: The mini water pump turns on and won't stop.
I removed the reset button to make sure that wasn't resetting, didn't help.
Maybe the motor is taking too much current and reseting the attiny?
I probably have to put a diode somewhere, but as I said, I'm a newbie, so...

thanks.

• Where is the decoupling capacitor? And why is there a resistor on the supply line? – Ignacio Vazquez-Abrams Jan 30 '16 at 0:27
• Is your reset switch designed exactly as drawn? If so you probably need either an internal or external pull-up resistor to keep that input from floating when the reset button isn't pressed. – DigitalNinja Jan 30 '16 at 0:44
• @RobhercKV5ROB pull-up is correct. A pull-down would hold it permanently in reset whether the button is pressed or not. – brhans Jan 30 '16 at 1:25
• Lose the resistor. Don't try to drive the relay directly from your Attiny - use a transistor. Put a diode across the relay coil. – brhans Jan 30 '16 at 1:28
• 20ohms is far too small for your LEDs series resistor. You should use one 10 to 20 times higher than that. – brhans Jan 30 '16 at 1:31

Ok, not sure this will fix everything, but it should at least improve several problems (and avoid some component damage).

Try adding 2 diodes, a transistor, and a decoupling capacitor to your circuit like this:

EDIT: Updated schematic to include decoupling cap.

• I'm adding right now the Diodes and transistor. But the decoupling capacitor was already there...C1 on the original schematic. – Kaique Gomes Jan 30 '16 at 2:20
• ok, but it needs to be on the other side of R2 from your orig. schematic (i.e. attached to the same end of R2 as your ttiny) – Robherc KV5ROB Jan 30 '16 at 2:24
• It's working perfectly with the adding of a transistor, diodes, capacitor in this schematic and the pull up resistor on the reset button. Thanks! – Kaique Gomes Jan 30 '16 at 2:47
• @KaiqueGomes: C1 is bulk, not decoupling. They serve different purposes. – Ignacio Vazquez-Abrams Jan 31 '16 at 13:09