Latch + Arduino Wake Up Strangeness - Page 1
Forum section: electronics / beginners

author: stiener
author_rank: Newbie
timestamp: November 02, 2024, 01:51:45 am
content: I followed this ElectroNoobs tutorial to create a latching circuit that can be turned off by a microcontroller GPIO signal.Everything works fine if I power the Arduino with a USB connection, but when I go to use the circuit with Arduino powered through Vin via bench power supply...-The Arduino no longer turns off the latch circuit and keeps resetting after it has completed its program.-Desired Behavior: Press button, Red LED turns on. Green LED flashes three times and then Arduino turns off the entire circuit. Red and Green LED OFF.IRF4905 P MOSFET, and 2 S8050 BJT transistors. How do I get the Arduino to power off the latch and itself? I used code straight from the tutorial website:https://electronoobs.com/eng_circuitos_tut61.phpI bet y'all know what to do! TYVIDEO OF ISSUE -->

author: Peabody
author_rank: Super Contributor
timestamp: November 02, 2024, 02:48:15 am
content: I'm confused about what your setup is when powering through USB. You say it works fine when powered that way, but how are you shutting off power to the Arduino if USB is still connected. Could you post a diagram of how that's all set up?Also, what is the power IN voltage when powering from the bench supply.

author: stiener
author_rank: Newbie
timestamp: November 02, 2024, 03:05:06 am
content: Thank you for your reply.Here is the schematic that i am following. The Bench power supply is 5v (adjustable)I have two setups essentially.One where the Arduino Vin is not plugged into the circuit, but ground and D5 are connected to the circuit. I can power the circuit with my bench supply, press the button to activate the Red Led. Then i plug in my Arduino in via USB, and it correctly runs the Arduino program and shuts the latch circuit down with the D5 signal to the gate of a BJT. The Arduino is still powered and The problem is now Im connected to a computer via usb.Supposed Correct Setup.Arduino Vin, ground, and D5 are connected to the circuit like in the schematic. With this setup, Red Led will illuminate, but the Arduino program with the D5 signal doesn't shut the latch circuit off. Also the Arduino should blink 3 times and the program should end. It keeps blinking forever.My video in the top of this post shows these two setups and my goal is to have the red light turn off as well as the Arduino at the end of the program.must be something power? or i need extra wiring or something?

author: Peabody
author_rank: Super Contributor
timestamp: November 02, 2024, 02:35:15 pm
content: I'll be referring to the attached schematic from the electronoobs site. It has the parts numbered.First, before I forget, if you are using a 5V Arduino, like the Uno or Nano, Vin is the input to the 5V regulator on the board. It should be fed with at least 7V to produce the 5V needed. The "5V" pin is the output of that regulator, or it could be an input if the bench supply provides a regulated 5V. So a bench 5V supply should go to the 5V pin. If you are using a 3.3V Arduino, then 5V at Vin would be correct.Looking at the "supposedly correct" version first, this circuit has the Arduino controlling its own power. When D5 goes high to shut off the power, that turns on Q4, which in turn turns off Q5, and the mosfet gradually turns off as its gate voltage rises through the 100K R6. Then as the output voltage drops, at some point around 2.5V the Arduino shuts down, which means all its GPIO pins stop outputting anything. So that means Q4 turns off. If at that point there is enough voltage left on the Ouput, then current will flow through R5 into the base of Q5, turning it back on. The capacitor is supposed to prevent that, but the base of Q5 only has to get up above 0.6V to turn it on, and apparently it does get that high. Then power comes back up and the Arduino starts over doing its flashing. So power is being turned off partially, enough to reset the Arduino, but then comes back up.With USB connected, the Arduino's power is never turned off, so it continues to output 5V on D5 until the power is turned off completely.I don't think the circuit design is good. The Arduino needs to shut off its own power by raising D5 to 5V, but can't keep doing that as its own power shuts down. That's not a reliable way to shut down. And the only reason for doing it that way, as he explains at the beginning of the video, is because of concern than the button press will be too brief to actually turn on the Arduino. If you weren't concerned about that, then instead of the latch, you could use a high output on D5 to keep the power *on*. As a practical matter, if you aren't connected to USB, the Arduino will power up very fast. I think you would have trouble pressing the button briefly enough that the Arduino wouldn't power up. But if that's a concern, you could have the Arduino blink an LED when it's safe to release the button.I've attached a hand-drawn schematic of a much simpler, and more reliable, way to do this. The button grounds the mosfet gate, and then the Arduino, in its first official act in setup(), makes D5 OUTPUT, HIGH, which continues to ground the gate after the button is released. Then when you're ready to shut down, you just bring D5 LOW, and the power shuts down. At some point in the shutdown, D5 will become tristate, but that still leaves the NPN off because there is no base current. So power won't rebound.

author: stiener
author_rank: Newbie
timestamp: November 02, 2024, 03:02:53 pm
content: Thank you! It will take me a little while to unpack this information... What you have said makes total sense now. Ill do some testing tonight on it

author: stiener
author_rank: Newbie
timestamp: November 03, 2024, 01:02:50 am
content: Yes! Your simplified circuit works well, and I can actually understand it. Its like you have two options to turn on the P mosfet, switch or Arduino pin. Makes total sense.I did notice it takes a little bit to get the Arduino going, hence hold the button down for a few seconds, which is fine for my application.However, to finish our conversation, any thoughts on getting that instant button working? If its all complicated, dont worry about it.The instant button is NOT needed, I am just curious nowThank You!for the working circuit and some explanation of that originalps. My Solution was to use atTiny85 so it boots really quickly

author: Ian.M
author_rank: Super Contributor
timestamp: November 03, 2024, 09:41:07 am
content: For some different takes on this common problem, seeand the topic:https://www.eevblog.com/forum/beginners/push-button-power-circuit-for-arduino-trying-to-modify-it-for-12v-input/

author: Peabody
author_rank: Super Contributor
timestamp: November 03, 2024, 04:13:05 pm
content: Glad you got it working. I'm not sure what would make the original circuit work. Possibly higher values for R5 and/or C3. Or you might insert a regular diode, or even a red LED, in series just below R5. That would raise the effective turn-on voltage of Q5. Or I guess changing Q5 to an N-channel mosfet with a 1Meg pulldown would make it harder to stay on - because the Vgs threshold voltage would be higher than the 0.6V of the NPN. You would have to play with it. It's still not clear why electronoobs' circuit worked for him. Maybe he had changed the brownout detection point on his Arduino.The video shows some alternatives that let you also use the push button as an input after the Arduino is running. That can be handy.