Hello all, I am trying to control a 12 v motor type JCY370 (12V, 0.5A load, 0.6A stall) using an attiny85 controller via two float switches. When switch one is in high position, the motor need to turn for one minute and then there needs to be a timeout of one hour before it can run again. The second float switch acts as a safety; the motor cannot run if this switch is in high position.
Other components used:
RFP30N06LE MOSFET
SB560 Diode
0.1µF ceramic capacitor for decoupling
Did you wait an hour after powering it on so that currentTime - lastRunTime >= TIMEOUT would be true? Because it appears at first glance that you can't start the motor up until an hour after the ATtiny85 starts.
Perhaps try initializing unsigned long lastRunTime = -TIMEOUT; if you want to be able to start the motor up within the first hour of powering up the ATtiny85.
3600000 milliseconds six months from now this is a meaningless number.
60 * 60 * 1000 milliseconds reminds you (hopefully) 60 min in one hour 60 seconds in minute.
Better still, this is often use:
#define ONE_SECOND 1000ul // ms
#define ONE_MINUTE (ONE_SECOND * 60ul) // 60 seconds in one minute
#define ONE_HOUR (ONE_MINUTE * 60ul) // 60 minutes in one hour
#define ONE_DAY (ONE_HOUR * 24ul) // 24 hours in one day
in your code you can write . . .
unsigned long TIMEOUT = ONE_HOUR; // 1 hour
. . .
unsigned long TIMEOUT = 30ul * ONE_MINUTE // 30 minutes
. . .
unsigned long TIMEOUT = 2ul * ONE_HOUR + 23ul * ONE_SECOND; // two hours and 23 seconds
if I look up the shematic for the digispark attiny85 I'm using, I see some capacitors on the 5v to GND lines, but I'm powering it using the same 12v as for the motor. Is it then still usefull to add a 0.1 µF between the VIN and the GND?