I am doing a Solar water heating contrôler with arduino. I have had a freeze of the AdC value read (ntc probe that read Solar panels) that remained at -1.75degc. this was confirmed by the serial data sent an recorded (using raspberry and Time series database) but also the direct Reading on the LCD (16x2). After rebooting Arduino everything get back normally. Additionnel strange thing is that the water tank ds18b20 temperature sensor serial data value showed a huge spike 1e4... That lasts less than 1 second (which Can not happen as the sensor max value is 125 deg c from this numerical sensor.). After that spike, the adc recorded value remained Frozen. The other ds28b20 and LCD menu navigation and display were ok...

Could that be related to EMI?

To SRAM overflow? Even if the rest of the program seems to work?

What could enables me to discriminates between those issues?

It seems it happened arround 2 days after the Arduino was rebooted.

Description of set up: I am using a standalone atmega 328 with polulu programmer. 8mhz internal crystal. Everything places on veroboard (main). Then a child veroboard holds the various resistors (Pullup, pulldown) for the input signals. Another child veroboard holds the outputs (pwm pump speed driver), optocoupler for pump Relay. The supply is a meanwell din rail 5v ac-dc concerter. I places decoupling caps arround atmega 328, diode+ pull up resistor + cap on reset Line as i had resets regularly (they are gone now). The pump Relay is on a separate 24v supply. Grounds are separrated from Arduino with this 24v circuit (that incluses flyback diode). But grounds are common to main and 2 children veroboards. The ntc Solar panel probe wire is twisted rj45 cat6. It is shielded and shielding is connected to the atmega grounds.

My program is non blocking type with use of millis and state machines. During developpent I checked the Time operation of the program that was running fast (no delay). The main structure is quite straightsforward. See bellow commented:

//Get Button state and debounce

//Menu(uses menubackend library)
menuNavigationBehavior(); // ie detect action from button pressed.Should be executed very rapidely... (less than 10 ms).
EditingVarInMenu(); // changing variables in Menu requiring speed loop (set parameters for example)

//Getting Temperature from panel1, 5 for 5 averaged values 
//every 20 ms ie 20 * 5 we have a temperatuure every 100 ms.

//Getting Temperature from one wire. Time between fetch and return of 100 ms.
getOneWireTemp (); 

//System Control Logic updated at Time loop
// Controller logic state machine execution
switch (ControllerMainState)
        case CONTROL_MANUAL:

        case CONTROL_AUTO:

        case CONTROL_ERROR:

    //MENU DISPLAY_____________________________

    if( millis() - timer_50_ms > 200) // 
              timer_50_ms = timer_50_ms+200;
              displayMenu(); // change the display. Can be done less often ie every 200 ms
  • Code, wiring, model/part numbers, etc. – timemage Nov 28 '20 at 21:34
  • Thanks for your comment. I am using a standalone atmega 328 places on veroboard. The ntc probe is in the panel. Using a simple voltage diviser to read it. 10k resistor in parrallel. How to be sure and distinguish between a program issue or an EMI issue? – Nikito Nov 28 '20 at 22:04
  • See additionnal détails now in the description. Hope this helps. – Nikito Nov 28 '20 at 22:38
  • It is likely that this thing and its code will need to be seen for anyone to be of much help. That said, you have a lot of going on in the "question". You're probably going to have to spend a lot of time isolating the problem to a particular part of the your project before anyone will be able to provide anything looking like an "answer". The only advice I have for you now is that if you think it's an EMI problem, you could modify your setup to exacerbate your problem. If you think kicking a pump on and off causes it to lock up, do that frequently to shorten your debug cycle. – timemage Nov 28 '20 at 22:43
  • 1
    Thanks timemage for your answer. And yes you are write. But i need to start from somewhere and your comments are valuable for me. The code is Big and that would make also difficult to have some answers. I had no issue to make the system work. When the freezing happened nothing was running in the system. Just measuring... – Nikito Nov 28 '20 at 22:54

You appear to have a difficult problem. One of the rules I use is never power the arduino with 5V power, always use the barrel connector and go with about 8 volts. The additional filtering etc the on board power supply does is amazing. The external 5V is ok for most of the other devices. Another option would go to the local electrical store and purchase a metal junction box and mount the electronics in that complete with a metal cover. Be sure it is grounded to earth. The reason for this is your prototype assembly has a lot of antennas that will pick up just about all of the electrical noise in the area. Remember all grounds must be connected. Arduinos are not hardened for industrial or commercial controller applications.

  • Thank you Gil for your answer. As mentionned, I am not using arduino but atmega 328. There is no additionnal filtering. Do you think this is a must have? – Nikito Dec 2 '20 at 10:09
  • Filtering is always a must have and extra does not hurt anything. You need both bulk and high frequency. Tantalum would be great but they can in rare cases explode. If you use aluminium use at least two. Look at the tolerance and use the lower value. Example, if it is 100uF +- 20% use 80uF as your value. Assuming your calculations come out you need 70uF use two of the 100's. I am switching to SMD and use the MMLC devices they are a lot better. Also the caps need to be mounted within 4 mm of where the regulator leads enter the board. Hopefully this helps. – Gil Dec 2 '20 at 21:50
  • 3 days without issues 😀. I cross my fingers. I removed only the main state machine execution so far. I am still reading all the sensors values and recording through serial connection... If this is software only issue I hope troubleshoot will be easier. – Nikito Dec 3 '20 at 18:56
  • What is bulk and high fréquence. I put a discoupling per recommandation from here :gammon.com.au/breadboard – Nikito Dec 4 '20 at 6:58
  • Try this link, it gives you Analog Devices MT-101 tutorial explaining Decoupling Techniques and why. analog.com/media/en/training-seminars/tutorials/MT-101.pdf This was my second hit on a google search "circuit design bulk and decoupling capacitance". There is a lot of data available. The MT-101 is only 14 pages. – Gil Dec 4 '20 at 21:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.