Home        Store        Learn        Blog

Arduino Mega hangs

I use a fairly simple sketch to run a pump through a controller and while it is running I take sensor readings from a BR Bar30 and temperature sensor. I enter through the monitor the run time (short bursts of few seconds), speed and pumping direction. This usually functions as intended a few times and then hangs. Attaching a printscreen of the serial monitor with both successful runs and hangs. By commenting out sections of the sketch I ran both the pump and each of the sensors alone for quite a while, this way everything functions properly. You can see in the monitor log that when the full sketch is used the sensors send a lot of garbage, when used without the pump this doesn’t happen either.
Any ideas?

Hi @yk101 ,

My first guess is that the pump is generating a lot of electrical noise that is interfering with the i²c lines. Can you share a schematic of how everything is connected?

Hi William.
Talking to a friend about my problem this morning, he suggested that I significantly raise the monitor baud rate. I was using a rate of 9600 (which was used in the sensors’ examples), I tried to change it to 57600 but that produced some garbage at the beginning of the run (where there was no text) so I elevated it to 115200. After working with the setup the whole day it didn’t hang once. So I guess my friend nailed it. If you have a guess as to the reason behind this I’d be glad to hear it.