Unexpected reset in watering / lighting system

Hi. I've been working on this project of a system that takes care of a plant: its water and light. I'm having an issue: the system resets itself each certain time. Sometimes I've catched the reset and what happens is that the LCD is cleared, then it starts filling up with complete dark characters until the reset as such happens and the program starts again. I don't know if this issue is due to a hardware failure / miss connection or due to a software bug. I first wanted to generally ask like under which circunstances a reset would occur. I'm not sure how to procede in these kind of bugs. I thought about sharing the circuit diagram, to check in case I have connected something wrong. If the connections are ok then I'd procede to post the code. I'm also looking forward debugging the code, it would be my first time for Arduino and would use Visual Code + Arduino extension.

The program / system already works with some features like: sensors, automatic or manual control for light and plump (their relay), access using push buttons and LCD, access through ethernet and it shows the time/date in the main screen.

Part list:

Arduino Mega 2560
Ethernet shield W5100
LCD 4x20
Soil Moisture Sensor FC-28
Temperature and humidity sensor DHT22
2 Channel 5V Relay Module
Real time clock RTC DS1302
LM7805 voltage regulator
3 push buttons

EDIT, the whole system working drains about 400 mA. I'm powering everything with a 9v 1A AC/DC adapter: The board through its power jack and other parts through a LM7805 voltage regulator. The NO/NC relay pins are not connected yet. JD-Vcc jumper is ON (the idea is to switch on/off an AC 110v lamp).

EDIT. Here the schematic by sugestion of PaulRB:

I'm sorry if there are any typos, I'm from Colombia. Thanks a lot for the help.

EDIT. I forgot to mention that long time ago I had experienced issues connecting the board to the IDE programmer due to the ethernet shield. The solution at that time was to bend the ethernet shield's reset pin so it wouldn't be wired to the Arduino one and to do the same with ICSP reset pin as well. I wonder if this pin manipulation could be causing somehow the unwanted resets.

The reason you get brownout is the power supply mostly is insufficient capacity.
Cannot see where the Arduino gets power.

Thanks. I will try powering from another power supply and will update with results. Arduino gets the power from the same AC/DC 9v 1A adapter. I just split the voltage into two (paralely): one for the board and another one for the rest. I measured the current as a whole and it consumes 400 mA, so I thought that 1Amp would be enough, but I'm not sure if I should use a separated power supply for the board.

I cannot see any errors in your wiring. However, some parts of the diagram are confused and unclear. A schematic would be so much better than this diagram. Fritzing has a schematic view, so please use that. In the schematic view, use plenty of "power supply" (5V, 9V, GND) symbols to remove any crossing wires or wires passing in front of other components.

That seems like a lot. I recommend you spend some time finding out where all that current is going. How much is going to the Arduino+shield? What if you remove the shield? How much is going to each of the other components? Resets can often be caused by power supply issues, so this knowledge may reveal something important.

Also please explain the purpose of the Ethernet shield, and why the RTC is also needed. If a project can get time time from the internet, an RTC is not usually needed.

It is enough, in terms of the 9V PSU. But your circuit is a 5V circuit. I don't see any components that actually need to use 9V. All that 9V power has to be converted into 5V power. This wastes almost half of that power. That wasted power gets turned into heat in your 7805 regulator and the regulator built in to the Arduino. These regulators are also part of the "power supply" in your circuit. Perhaps one of them is overloaded and causing the resets.

I would add a heatsink to the 7805. 400 mA * 4 volt to drop is likely too much for a naked 7805.

Hi, thanks. I forgot to mention that it does have a heatsink. I noted that the regulator was getting too warm so I added one.

Good. Then the search continues.

(I wonder how to answer to each comment in a way that my comment appears in its below and not at the bottom of the topic, to keep the order. I will see in this one. I'm sorry I'm new to this forum and more yet to its new look)

I think the board needs like above 7v for proper working. Or could it be with 5v straight ahead?. I didn't thought about powering others parts with a 5v source, would this be a better idea? I do am aware all these parts run with 5v. I could feed the board with the 9v adaptor and to get a different 5v one for other parts. What would be the best way to power this? There was a project before this one lead by a mate, he used a computer power supply. But I thought it was bulky and somehow complex to implement.

I will use the schematic and share it here. Thanks for the advice.

Alright. I will make these different measures. Cool thanks.

The purpose of the Ethernet shield is for the user to be able to access the system without having to physically be there. The system would be next to the cultive and the user could access from its cellphone, laptop, etc. Initially within a private network but later I'd like to open the ports in the router to try it from the internet. I also thought about getting the time from the Internet, but in a later version. The implementation of the RTC came before the ethernet shield, as a need for knowing time and date for the photoperiod.

Mega is a 5V board. It needs 5V.

In case there is no 5V supply available, it also has a built-in regulator which can make 5V from 7~12V. This regulator is inefficient and can easily overheat and fail if pushed too hard. It is a linear regulator. They create the desired output voltage by simply burning off any unrequired voltage as heat.

The solution to your problems may be to provide a 5V supply. But I am still curious why your circuit draws 400mA. I suspect the Ethernet board is the culprit. I have heard that they are very "thirsty". Please let us know what you find.

This datasheet claims 183mA + 145mA for 2 relay coils = 328mA * (9V - 5V), 4V = 1.313 Watts, enough to overheat the regulator and cause it to shutdown. What are the relays switching?

("Post can't be empty" !?!)

And that breadboard how much power can it supply through its tiny connection points? Not a lot.

Thanks. uhm I don't think this would be an issue, those can hold more than 1 amp.

Thanks. The ethernet shield indeed consumes about 171 mA. But the relays are powered from the breadboard through a LM7805 regulator. The Arduino board regulator would hold 245mA * (9V - 5V) = aprox. 1 Watt

Here I will quote a post from another topic pretty related to this one:


you'll want to try to keep the power to no more than 1 watt...

Max Current You Can Draw = 1(watt) / (Supply Voltage - 5v)

So, 1w / (9v-5v) = 1w / 4v = 250mA

You might want to look at a DC-DC (Buck) Converter - this would be more efficient than the built in linear converter and allow you to draw more current. (by Ken)

1st relay an AC 110V lamp and 2nd relay a 12v plump.

Thanks for the explanation. I made the current measures:

Board alone = 74mA
Ethernet shield = 171mA
Board + shield = 245mA
Other components alone = 100mA
Other components + 2 relays = 150mA
Whole system = aprox. 400mA

So what should I do now? Is it trustable to feed the board through the 5V line? I readed that just with > 5.5V would damage the board. Which power supply would be steady enough to give 5V always? Is is ok to power both board + shield AND other components from the same source or should I try to split it into two power supplies?.

I make that 740mA ! 9v - 5v = 4 v *0.74 = 2.96W of HOT!

uhm 740mA, where from? I mentioned that the whole system consumes about 400mA. I've measured it by putting the multimeter right after the main power supply.

I'm sorry I may have made the current consumption list like visually confusing so I'm going to rewrite it here:

Arduino Board alone = 74mA
Arduino Board + Ethernet shield = 245mA
Ethernet shield alone = 245mA - 74mA = 171mA

Other components alone = 100mA
Other components + 2 relays = 100mA + 50mA = 150mA

Total current = (Board + shield ) + (Other components + 2 relays)
Total current = 245mA + 150mA
Total current = 400mA aprox.

I've added the schematic to the first post!!

Thanks, much clearer. I noticed you have no pot to adjust the LCD contrast?

I would recommend a single 5V regulated or switch-mode power supply with at least 600mA current. This would give a safe and efficient way to power the mega and shield through its 5V pin, and all other components also.

In case any of these ideas are of interest to you, this is how I would have approached your project:
Wemos Mini rather than Mega+Ethernet shield (maybe you can't use wi-fi)?
I2c backpack for the LCD screen
Remove RTC, get time from NTP server.
Maybe replace DHT22 with SHT21 or similar which can share i2c pins
Maybe add pcf8574 chip to control relays and read pushbuttons

Yes sir. I used the potenciometer for a while always to its min resistance to keep a nice contrast. So I searched over the Internet and saw a diagram with this contrast pin straight to ground to just keep the contrast to the max. I did the same and it looks nice.

Hi. Thanks. I bought a 5V 1A adapter. I powered only the Arduino board but I forgot to connect it to the 5V pin and instead I connected it to the Jack. It worked fine. I noted a weird response in the LCD when I switched the relays ON and OFF (edit. relays powered by different 9v adaptor). So I took out the relay module and I have to say that the system shows itself very steady since then, since yesterday. So right now its working without the ethernet shield and the relay module.

I tried to connect the new 5V 1A adapter straight to the 5V board pin but it did not work, I quickly disconnected it and I could see the gray smoke of death coming out of the board ... fortunatly it seems nothing was burned, but it was not nice to watch ... I'm pretty sure I connect it rightly.

Right now its working with the 9V 1A adapter again powering both the Arduino board and the breadboard. No ethernet or relay module connected yet. I suspect that the relay module has a faiure. I will post updates of the tests.

Thanks a lot for the sugestions. Honestly this set up I'm running with was a donation from a Spanish guy who came up with the first idea. That was some years ago so the board / modules are somehow out of date now. What you suggest would be a pretty nice, smart, updated design and interestingly cheap. Thanks again.