Arduino Forum

Using Arduino => Microcontrollers => Topic started by: batista742k2 on Jun 12, 2020, 12:12 am

Title: Standalone ATmega328p-pu
Post by: batista742k2 on Jun 12, 2020, 12:12 am
Hi.

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.  :D


Thanks in advance.   ;)


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)
(https://forum.arduino.cc/index.php?action=dlattach;topic=689876.0;attach=368087)
Title: Re: Standalone ATmega328p-pu
Post by: CrossRoads on Jun 12, 2020, 12:19 am
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.
(https://forum.arduino.cc/index.php?action=dlattach;topic=689876.0;attach=368080)

And your code is too big, so that'll have to stay as an attachment.
Title: Re: Standalone ATmega328p-pu
Post by: CrossRoads on Jun 12, 2020, 12:34 am
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.
Title: Re: Standalone ATmega328p-pu
Post by: batista742k2 on Jun 12, 2020, 12:44 am
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.

Title: Re: Standalone ATmega328p-pu
Post by: CrossRoads on Jun 12, 2020, 12:48 am
Good luck. The additional caps should help.
Title: Re: Standalone ATmega328p-pu
Post by: larryd on Jun 12, 2020, 03:02 am
Appears your reset pin on the breadboard goes to a resistor but then 'not' to 5v.




Title: Re: Standalone ATmega328p-pu
Post by: batista742k2 on Jun 12, 2020, 09:57 am
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
Title: Re: Standalone ATmega328p-pu
Post by: pert on Jun 13, 2020, 05:27 pm
@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:
https://forum.arduino.cc/index.php?topic=689880 (https://forum.arduino.cc/index.php?topic=689880)