I am trying to setup an automated relay for my aquarium. The arduino should switch off the pump every 3 hours for 20 minutes, and feed at every off cycle during the day. The code works fine for the first two on/off cycles. However after that the system stops responding.
I have tried many ways to solve the issue, I am led to believe that the issue could be a memory leak, but i have tried to fix that with watchdogtimer reset, tried to reset the arduino as well but it doesn't work after the first reset.
I am still not sure what the problem could be any information would be appreciated.
I have included 2 codes that I have stitched together using other references from the web.
I am still not sure what the problem could be any information would be appreciated.
It is clear that the commented out code is NOT the problem. So, why did you post it? DELETE IT!
Your indenting is atrocious. Use Tools + Auto Format to fix it.
int hourday[] = {6,9,12,15,16,18};
int hournight[] = {20,22,23,1,3,5};
int minday[]= {0,20,40} ;
How many of those values need to be stored in ints?
Why are these arrays even defined? They are never used.
printDate() should do EXACTLY that. NOTHING in the name suggests that it will also feed the fish. So, it should NOT be feeding the fish.
What, exactly, happens when the "system stops responding"? Does the serial output stop? Add an LED, and toggle its state on every pass through loop. Does the LED keep blinking?
the tiny rtc module is connected to scl and sda pins a5 and a4,
signal for relays comes from digitalpin 2,
and a small dc motor runs off from digital pin 4.
Sounds like something electrical. Do you have a pull-up resistor on each of SDA and SCL? The motor may be consuming too much power. What is the motor rated at? How is everything wired up?
I am curious. If you disconnect the motors etc. and just run the code without them, whether the code will be stuck again. Also what ia the voltage of your rtc backup battery?
not used any pull ups. In what configuration do i need to have pull ups?
here's the schematic.
the tiny rtc module has a 3v (cr2032) lithium battery on it.
External pullup resistors should not be needed when using the 10K resistors on the I/O. The rise time spec of the DS1307 I2C line is 1 microsecond max. This allows loading on the line of around 50pf which is fine for most lines. You can try adding external resistors but I would be surprised if they make a difference. They never have for me.
That's not a schematic, that's view of how the wires are connected.
A schematic would indicate which to the "N" pins are the base, collector, emitter for example.
4.7K pullups work much better than the 30-50K internal pullup.
How much current does the pump require? You may be causing a processor re-start with large current surges caused by the motor turning on and dragging down the 5V line.
I don't see that your code ever does a write to the RTC to set the time, or to turn on the clock to allow time to start advancing (bit 7 of the seconds register I believe).
You can run a separate sketch to do that once, then load this sketch to read the time.
The base is connected to pin 4 on the arduino via a 3.3k resistor
The emitter is grounded
And collector goes to the motor.
the motor is a small dc motor which is inside my fish feeder mechanism. which normally without an arduino, works on a small 1.5v AA battery. So what I did was connected the terminals of the motor to the arduino via the bc547 collector (1st terminal of the motor) and Vcc (2nd terminal of the motor)
Ive also added a diode between the two motor terminals for motor surges caused by motor turning on.
also ive already got the module to set the time using another sketch before uploading this one.
please note that I'm trying to trigger a relay via pin 2. the PUMP is connected to this relay's coil.
do i need some sort of passive circuitry on that line (between pin2 and relay module)??
like i said the sketch works perfectly fine for the first time after the arduino is reset,,,but after say an hour or two it spazzes out
and when everything fails the last output is nothing at all
basically the serial output stops too.
the serial monitor has already stopped scrolling at that instant when everything spazzes
Make up your mind where you want answers from. I can lock this thread if you like.
It would be courteous to mention that you have asked the question on another site. At least then you don't annoy the hell out of people who happen to visit both sites.
hi sorry Mr. Nick.
I'm new to the world of forums and i posted first here and then tried looking for help on others,
sorry i din't mean to offend anyone, just thought of getting help from as many people as possible.
appologies again.
i have tried with everything disconnected, same issue.