Electrical – Attiny85 water plant with mini water pump

attiny85cfluid-pumprelay

I`m 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);  

  humidity = humiditySensor.Read();
  level = levelPot.Read();
  timer = timerPot.Read();
}

void loop() {
  humidity = humiditySensor.Read();
  level = levelPot.Read();

  timer = timerPot.Read();
  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
}

enter image description here

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.

Best Answer

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:
enter image description here

EDIT: Updated schematic to include decoupling cap.