Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

Strange Unknown problem. Arduino stops responding after few
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Strange Unknown problem. Arduino stops responding after few

by sids2000 on Mon Jan 11, 2016 4:49 pm

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 patricular timings 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 my code that I have stitched together using other references from the web. And a link to the schematic of my circuit along with a picture of a tiny rtc module.

Schematic: http://i.stack.imgur.com/xrGPd.jpg
Tiny rtc : http://i.stack.imgur.com/kgoou.jpg

CODE IS AS BELOW. ANY ADVICE WOULD BE APPRECIATED.

' // CODE STARTS HERE
Code: Select all | TOGGLE FULL SIZE
                #include "Wire.h"
                #define DS1307_ADDRESS 0x68
                #define RELAY_PIN 2
                #define Feed_PIN 4
                #define led13 13


                void setup() {

                  Wire.begin();

                  Serial.begin(9600);

                  pinMode(RELAY_PIN, OUTPUT);

                  pinMode(Feed_PIN, OUTPUT);

                   pinMode(led13, OUTPUT);

                }


                void loop() {
 
                  printDate();
                 // digitalWrite(led13, HIGH);
                  //delay(500);
                  //delay(500);
                 //digitalWrite(led13, LOW);
                  // byte zero = 0x00;
                  ///Wire.write(zero);

                }


                byte bcdToDec(byte val)  {

                  // Convert binary coded decimal to normal decimal numbers

                  return ( (val / 16 * 10) + (val % 16) );

                }


                void printDate() {


                  // Reset the register pointer

                  Wire.beginTransmission(DS1307_ADDRESS);
                  byte zero = 0x00;
                  Wire.write(zero);
                  Wire.endTransmission();
                  Wire.requestFrom(DS1307_ADDRESS, 7);
                  int second = bcdToDec(Wire.read());
                  int minute = bcdToDec(Wire.read());
                  int hour = bcdToDec(Wire.read() & 0b111111); //24 hour time
                  int weekDay = bcdToDec(Wire.read()); //0-6 -> sun-sat     
                  int monthDay = bcdToDec(Wire.read());
                  int month = bcdToDec(Wire.read());
                  int year = bcdToDec(Wire.read());
                  //print the date EG   3/1/11 23:59:59
                  Serial.print(month);
                  Serial.print("/");
                  Serial.print(monthDay);
                  Serial.print("/");
                  Serial.print(year);
                  Serial.print(" ");
                  Serial.print(hour);
                  Serial.print(":");
                  Serial.print(minute);
                  Serial.print(":");
                  Serial.println(second);
                  if ( (hour == 9 && (minute >= 00 && minute <= 20)) ||
                      (hour == 12 && (minute >= 20 && minute <= 40)) ||
                       (hour == 15 && (minute >= 40 && minute <= 59)) ||
                       (hour == 18 && (minute >= 00 && minute <= 20)) ||
                       (hour == 20 && (minute >= 20 && minute <= 40)) ||
                       (hour == 22 && (minute >= 40 && minute <= 59)) ||
                       (hour == 1 && (minute >= 00 && minute <= 20)) ||
                       (hour == 3 && (minute >= 20 && minute <= 40)) ||
                       (hour == 5 && (minute >= 40 && minute <= 59))) 

                {

                  Serial.print(month);
                    Serial.print("/");
                    Serial.print(monthDay);
                    Serial.print("/");
                    Serial.print(year);
                    Serial.print(" ");
                    Serial.print(hour);
                    Serial.print(":");
                    Serial.print(minute);
                    Serial.print(":");
                    Serial.println(second);
                    Serial.print(':');
                    Serial.print(':');
                    Serial.println(", pump off!");
                    digitalWrite(RELAY_PIN, HIGH);

 
                }


                  else {
                  digitalWrite(RELAY_PIN, LOW);
 
                }



                  if ((hour == 2 && minute == 43 && second >= 52) ||
                      (hour == 10 && minute == 00 && second >= 52) ||
                      (hour == 13 && minute == 00 && second >= 52) ||
                      (hour == 16 && minute == 00 && second >= 52))
 
                 {

                    digitalWrite(Feed_PIN, HIGH);
                    Serial.println("feeding fish.....");

                  }
                } // CODE ENDS HERE
'

sids2000
 
Posts: 6
Joined: Mon Jan 11, 2016 4:38 pm

Re: Strange Unknown problem. Arduino stops responding after

by adafruit_support_bill on Mon Jan 11, 2016 5:32 pm

There is nothing there that looks like it might leak memory. What do you see in the serial monitor when this happens?

What is the current draw of the relay coil? (your diagram shows a motor). How are you powering the Arduino?

adafruit_support_bill
 
Posts: 77925
Joined: Sat Feb 07, 2009 10:11 am

Re: Strange Unknown problem. Arduino stops responding after

by sids2000 on Mon Jan 11, 2016 6:03 pm

this is the output of my serial monitor when the conditions of the if loop are met.

1/12/16 3:26:16
1/12/16 3:26:16
::, pump off!
1/12/16 3:26:16
1/12/16 3:26:16
::, pump off!
1/12/16 3:26:16
1/12/16 3:26:16
::, pump off!
1/12/16 3:26:16
1/12/16 3:26:16
::, pump off!
1/12/16 3:26:16
1/12/16 3:26:16
::, pump off!
1/12/16 3:26:17
1/12/16 3:26:17
::, pump off!
1/12/16 3:26:17
1/12/16 3:26:17
::, pump off!
1/12/16 3:26:17
1/12/16 3:26:17
::, pump off!
1/12/16 3:26:17
1/12/16 3:26:17
::, pump off!
1/12/16 3:26:17
1/12/16 3:26:17
::, pump off!


like i said the whole system works perfectly fine when the arduino is reset.
only after maybe an hour or two the whole system spazzes.

i don't know the current draw of the relay coil , but its a 4 relay module that is rated to work with the arduino directly
the arduino is being powered with a 12v 1a power supply . the motor is a small 5v dc motor that works normally (without the arduino) on a single 1.5v aa battery.

sids2000
 
Posts: 6
Joined: Mon Jan 11, 2016 4:38 pm

Re: Strange Unknown problem. Arduino stops responding after

by adafruit_support_bill on Mon Jan 11, 2016 6:13 pm

this is the output of my serial monitor when the conditions of the if loop are met.

But what is the last output before it fails? Does it coincide perhaps with your feed cycle?

the arduino is being powered with a 12v 1a power supply . the motor is a small 5v dc motor

Running a DC motor from the 5v pin of an Arduino that is being powered by 12v is a bad idea.

With 12v input, the Arduino voltage regulator is only about 40% efficient. It needs to burn the rest off as heat.
A DC motor starting is essentially equivalent to a stall condition until the motor can start moving. This puts a tremendous strain on the voltage regulator.

adafruit_support_bill
 
Posts: 77925
Joined: Sat Feb 07, 2009 10:11 am

Re: Strange Unknown problem. Arduino stops responding after

by sids2000 on Mon Jan 11, 2016 6:15 pm

this is the output at 3:40,(when the if loop condition is not met...thus the else loop executed)

1/12/16 3:41:10
1/12/16 3:41:10
1/12/16 3:41:10
1/12/16 3:41:10
1/12/16 3:41:10
1/12/16 3:41:10
1/12/16 3:41:11
1/12/16 3:41:11
1/12/16 3:41:11
1/12/16 3:41:11
1/12/16 3:41:11
1/12/16 3:41:11
1/12/16 3:41:12
1/12/16 3:41:12
1/12/16 3:41:12
1/12/16 3:41:12
1/12/16 3:41:12
1/12/16 3:41:12

sids2000
 
Posts: 6
Joined: Mon Jan 11, 2016 4:38 pm

Re: Strange Unknown problem. Arduino stops responding after

by adafruit_support_bill on Mon Jan 11, 2016 6:16 pm

At some point it stops responding. What is the last output before it fails?

adafruit_support_bill
 
Posts: 77925
Joined: Sat Feb 07, 2009 10:11 am

Re: Strange Unknown problem. Arduino stops responding after

by sids2000 on Mon Jan 11, 2016 6:18 pm

the last output before it fails is nothing.
basically the serail monitor stops too.

yes im using a 12 v supply , coz i have built my own arduino standalone with a 7805 regulator.
ive checked the votage to the atmega chip is aroun 4.98 volts

sids2000
 
Posts: 6
Joined: Mon Jan 11, 2016 4:38 pm

Re: Strange Unknown problem. Arduino stops responding after

by sids2000 on Mon Jan 11, 2016 6:30 pm

also when im trouble shooting i use an arduino uno which is a seperate board powered via usb,

in both scenarios the problem is the same.
thus i think its not a power issuie :(

sids2000
 
Posts: 6
Joined: Mon Jan 11, 2016 4:38 pm

Re: Strange Unknown problem. Arduino stops responding after

by adafruit_support_bill on Mon Jan 11, 2016 7:45 pm

the last output before it fails is nothing.
basically the serail monitor stops too.

But what is the last output before it stops? That is your best clue as to why it stopped.

adafruit_support_bill
 
Posts: 77925
Joined: Sat Feb 07, 2009 10:11 am

Re: Strange Unknown problem. Arduino stops responding after

by sids2000 on Mon Jan 11, 2016 7:53 pm

yes i know but it stops randomly after some time thats passed depending on what its last state was , that is what the serial output stops at.

for instance if system spazzes at say a cycle time 3:30, then it would say pump off there. that would be my last serial output.
but say if system stops at 3:55, then my last serial output would be just the time for eg= 3:55:01

so what is my clue here, it happens at random points. sometimes in the middle of a pump on cycle or sometimes at the pump off cycle

sids2000
 
Posts: 6
Joined: Mon Jan 11, 2016 4:38 pm

Re: Strange Unknown problem. Arduino stops responding after

by adafruit_support_bill on Mon Jan 11, 2016 8:01 pm

Not much evidence to go on. But based on your schematic and your 12v power supply, power would be the chief suspect.

adafruit_support_bill
 
Posts: 77925
Joined: Sat Feb 07, 2009 10:11 am

Re: Strange Unknown problem. Arduino stops responding after

by phild13 on Thu Jan 21, 2016 8:32 am

Based on what is drawn on the breadboard, power is the issue.
It is also a really bad idea to try to power the motor from the uno supplied 5 volts. The motor takes much more to start and at 5 volts likely takes to much power to run and the uno regulator is shutting down on overheat. Small motors such as depicted can draw anywhere from 250mA to over 1000mA while running unloaded. Startup current is about 4 times that value.
A single alkaline AA battery can actually supply about 2 amps, which is more than enough to start the motor and is why it runs fine on the battery.
There could also be enough electrical noise from the motor to cause issues with the processor also.
Another issue is the current draw from the motor could cause a large droop in the voltage and could cause the processor on the uno to shut down.

The regulator on board the uno can only supply about 1 watt max without overheating as the board provides limited heat sinking.
You are supplying 12 vdc as input power and supplying the 5 volts from the 5 volt pin on the socket of the uno to the entire circuit including the motor. Power requirements of the uno are about 30mA with the rest of the circuit realistically probably needing several hundred mA mostly for the motor.

You can figure power as: (vin - vout)*A = power so if you have an input of 12 volts and an regulated output of 5 volts then you you will only be able to use about 144mA total without risk of overheating the regulator on the uno. Since the uno needs about 30 mA that only leaves about 114 mA to work with. (12 - 5)*.144 = 1.008 or about 1 watt dissipation. You would need to supply the uno with 7 volts to get 500mA of power available at 1 watt dissipation.

I would redo the circuit adding a separate power rail from a separate regulator supplying power for the motor and to the relay board since it appears the pump power may be sent through there.

The uno then only does control (that is it turns the motor transistor on/off and also only turns the relays on/off and doesn't attempt to supply any power to power hungry components and can be supplied from the 12 volts without concern of overheating.

phild13
 
Posts: 247
Joined: Mon Sep 10, 2012 1:05 pm

Please be positive and constructive with your questions and comments.


cron