Standalone ATmega328p-pu


I have built an electronic circuit that measures gases (natural gas, carbon monoxide, etc), just like the temperature and the humidity. This circuit shows the data on an "OLED 128x64 I2C" and sends it via Wifi for a mobile app and an SMS when the values get high. It has an alarm system as well, that consists of a buzzer and a led blinking.

Turns out that I have many thinks turned on in a (7.4v / 2.2A) battery, and I would like to know if my wiring is fine or if it is something that I may change.

I'm asking because sometimes, very rarely, I experience some crashes on the microcontroller, it may be a memory leak, so I'm letting the programme here too. But as I mentioned, with so many think turned on, it may be some kind of overload, I don't understand electronic that much, to be honest, just a beginner, have to study more. :smiley:

Thanks in advance. :wink:

Photo of the circuit: circuit.jpg (on the attachments)

Print of the schematics: schematics.png (on the attachments)

The code: (.ino) 382 lines (on the attachments)

vc_atmega328p-pu.ino (10.6 KB)

Your .jpg is not attached.
For reasons I cannot explain, your .png cannot be posted with code tags, I'll try to recapture it as a .jpg and attach it.

And your code is too big, so that'll have to stay as an attachment.

Regarding the 328P crashing, I don't see any 0.1uF caps in your schematic.
You need one on each VCC and AVCC pin, located next to the pin and connecting to a nearby Gnd.
And a third separately from Aref to Gnd, not connected to 5V. That connection is made internally.
All the caps (decoupling capacitors) help to provide small bursts of surge current to the transistor switching that goes on inside the device.

Caps on the voltage regulators would help also. LM7805CT datasheet recommends caps on both input and output, 0.2nF I would say is woefully inadequate. I generally use 10uF on the input and 1uF on the output, mostly because I have them handy but also because I know that works well.

Your other sensors and devices would also benefit from caps on their power lines.

Regarding the 328P crashing, I don't see any 0.1uF caps in your schematic.

Yes, you're right, my schematic is a little bit confusing and it's not completed, I made it this afternoon, sorry.

Thank you soo much, I'm seeing what you're saying, I was wondering about the capacitors too, as I add a 1000uF capacitor on the ESP8266 and a 2000uF capacitor on the SIM800L because I was experiencing some unexpected restarts due to power surges.

I will follow your suggestions and reply tomorrow, thanks again for your help and the speedy and clear response.

Good luck. The additional caps should help.

Appears your reset pin on the breadboard goes to a resistor but then ‘not’ to 5v.

Appears your reset pin on the breadboard goes to a resistor but then ‘not’ to 5v.

You're right, I have taken it off accidentally. Thank you

@batista742k2 opened another topic to discuss this issue as it might relate to issues in the code, but that is ending up also being about hardware, so it's probably best to just continue any discussion on either subject in that thread: