Button input problem - Page 1
Forum section: electronics / beginners

author: Raj
author_rank: Frequent Contributor
timestamp: July 31, 2019, 06:19:35 pm
content: So, I've been banging my head to the wall, thinking of a solution , of solving this problem...I wanted the button input to my micro-controller to also act as power switch in order to save battery...( I wanna design a TV remote cause the original is way to complicated for old folks at home)But the thing is, The diode I've used has too much voltage drop, which is messing the whole thing up. refer figure 1. The voltage on the pin being grounded goes to negative in reference to arduino's negative input/gnd, thus making the code run funny, like you press a button and it behaves as if you pressed 2.This problem goes away when the circuit is connected as in figure 2 but I loose the ability to turn the arduino with the input buttonI've also tried figure 3, but it refuses to turn off, since the ground is leaking into the transistor from zena diodes of arduino. The transistor being tip127, hfe min-1000Atleast that's all what I think is happening.Note: i've already made the housing and thus can't replace switches with dpdt kind

author: sokoloff
author_rank: Super Contributor
timestamp: July 31, 2019, 06:36:16 pm
content: Do you have the inputs configured as INPUT or INPUT_PULLUP?If you haven’t tried INPUT_PULLUP, that’s worth a shot.

author: Raj
author_rank: Frequent Contributor
timestamp: July 31, 2019, 06:40:41 pm
content: It is pulled high, but it won't help, since pressing the button is essentially sending the pin to -0.5v

author: sokoloff
author_rank: Super Contributor
timestamp: July 31, 2019, 06:44:42 pm
content: The question was just to ensure you were holding the other (non-pressed) buttons in a defined state as you report other button is getting read as closed.

author: MarkF
author_rank: Super Contributor
timestamp: July 31, 2019, 08:24:01 pm
content: Here is another thread on using a MCU pin to both control power ON/OFF and as an input:https://www.eevblog.com/forum/beginners/push-button-power-circuit-for-arduino-trying-to-modify-it-for-12v-input/

author: Nusa
author_rank: Super Contributor
timestamp: July 31, 2019, 09:17:44 pm
content: I'd suggest a different approach entirely. Rather than trying to control the power on the outside, forcing the hardware to cold-boot every time you try to turn it on, leave the power applied and keep the processor in very low power modes except when it has to do something. You may even be able to set up some or all of the required buttons to interrupts and have them wake the processor, rather than having to poll them.I'd also suggest that a 9V isn't the best choice for power. It's much higher than what the electronics need. In linear regulators, the energy lost is directly related to the voltage dropped. Plus eliminating the regulator isn't even an option.Not the only article on the subject, but a decent starting point:http://www.home-automation-community.com/arduino-low-power-how-to-run-atmega328p-for-a-year-on-coin-cell-battery/

author: KL27x
author_rank: Super Contributor
timestamp: July 31, 2019, 10:35:02 pm
content: I feel like the slow kid in class. What are all those diodes for?edit: Oh.. so you are trying to power the arduino by pressing ANY button?There's one major problem to watch out for. Depending on what you have connected to the other pins, it may not be possible for the AVR to actually disconnect from the ground rail, the way you have done pic1. The IC can ground itself through any other I/O pin that is grounded, because of the ESD clamping diodes on each I/O pin.If that last sentence doesn't make sense: draw a diode between each I/O pin and the micro Vss pin. Anode on the Vss pin, cathode on the I/O pin. This should look really, really familiar.* There's another diode between each I/O and the Vdd pin. Anode on the I/O pin, cathode on the Vdd pin. (preceeding part of this paragraph edited for cathode/anode dyslexia). When your Vdd and Vss pins are connected to a PSU, this means the voltage you put on a pin should be within rails plus an extra 0.3 is ok. When the ground rail of the micro is not connected, this means any pin that has a path to the battery ground will feed the ground rail minus a bit of voltage drop.*All those diodes you put in there are potentially redundant. They are already in the chip (very low voltage, low current, low Vfd shottky diodes, anyhow). So long as your current draw was very small, anyhow, you could do it without external ones. Provided there's no other path to battery ground in the rest of your circuitry. Basically w/e you made up with those rectifier diodes is already on EVERY I/O pin, not just where you put those external diodes. So plan (or abandon this plan), accordingly.In most modern micros, you can probably use sleep to reduce current draw to almost nothing, but can you can do it in Arduino sketch? And also if you must use the onboard regulator, that is going to have a quiescent draw all the time. So sleep may not be practical for OP.

author: Raj
author_rank: Frequent Contributor
timestamp: August 01, 2019, 03:55:02 am
content: Quote from: KL27x on July 31, 2019, 10:35:02 pmI don't mind, Arduino reading 2 buttons as closed, when user presses both of them... But pressing just one and it reading 2 buttons as presses (chosen by Arduino God at random) is disturbing.Quote from: Nusa on July 31, 2019, 09:17:44 pmI guess,I need lower voltage battery, like 4.5v, also the voltage after it misbehaves...Also, instead of input button powering it up, since my circuit is gonna go inside of a gun shaped housing, I'll put a tilt switch and a grip safety on it.I guess, it'll also make using it easier since it'll take away input lag.But before I go about sawing away the housing, I should try and mod figure 3 circuit to solve problem.

author: KL27x
author_rank: Super Contributor
timestamp: August 01, 2019, 04:14:10 am
content: The reason (slightly negative voltage on input pin) you think it may be doing this (reading 2 pins as pressed) is not likely, IMO.Also, the 9V battery is not likely the problem. I mean that is just going to the regulator on the Arduino PCB and dropping to 5V. And that is fine. Since you are grounding it through a diode (not the one you put on there, BTW. The internal diode has lower VFD; your 4001's are doing nothing), you are already giving it a tad less than the 5V.Go back to the basics and troubleshoot step by step. Check and test your code. It may need some very small delays to make sure the rails are stable and that the pullups are enabled and active before a read is done.Post entire schematic if you are still having trouble. You also might want to do a little thought investigation concerning this "second button" being detected as input low, a bit. Which is it? Does it change, depending on which button is pressed? Does it have any relationship to the button being pressed?

author: Raj
author_rank: Frequent Contributor
timestamp: August 01, 2019, 04:27:10 am
content: Solved!Stupid me, I should read my own sentences out loud to know the answer to my problems (the words "from and to" are very important to know what's wrong in electronics)....bread board testing in 3.2.1I'll have to go out in the rain to get more (3) diodes

author: KL27x
author_rank: Super Contributor
timestamp: August 01, 2019, 04:31:51 am
content: Read my first post and watch Dave's video. You don't need to go out in the rain. Remove the diodes on the right side (the old ones) and use them for the left side (the new ones).Page 75 of the Atmega 328P manual shows these ESD diodes that are already in there.

author: Raj
author_rank: Frequent Contributor
timestamp: August 01, 2019, 04:34:27 am
content: actually, I need to properly ground the arduino for it and output phrephrals to work properly...I know the effects.... you can get the same effect by doing figure 5

author: Raj
author_rank: Frequent Contributor
timestamp: August 01, 2019, 04:38:36 am
content: figure 4 worked...case solved...

author: KL27x
author_rank: Super Contributor
timestamp: August 01, 2019, 04:49:03 am
content: Ok. It works because there is no short/leakage between the gate through the I/O pin esd diode and internal pullups to Vdd. Your diodes stops that.And there is no way for the Arduino to keep itself on, which apparently is fine because you only want it to remain on as long as you hold one or more buttons down.But why do you leave those diodes on the right? The old ones? Not only they are redundant to the esd diodes, but now I wonder what you think they are doing in the new pic4 schematic, with common ground rail between battery and MCU?Oh, nevermind. I'm slow. Yeah, you got all those pins and switches connected to the base on the PNP. I had glitches switching gears between the ground-thru-tac switch vs the high side PNP switching.Common ground with high side switch: You could probably ditch all those new diodes you added for a single zener of 4-5V on the base? Reduce the value of your base resistor, if needed. One diode vs 9.

author: Raj
author_rank: Frequent Contributor
timestamp: August 01, 2019, 05:28:00 am
content: Being slow is ok .... It's better than getting kicked (kicked myself out) out of college like meGot f in Hindi,Punjabi and maths

author: Raj
author_rank: Frequent Contributor
timestamp: August 01, 2019, 06:12:23 am
content: Here's the abomination you just helped create :p

author: KL27x
author_rank: Super Contributor
timestamp: August 01, 2019, 06:41:30 am
content: Yeah, I was picturing something a little different when you said the housing was already completed.

author: tooki
author_rank: Super Contributor
timestamp: August 02, 2019, 02:43:41 pm
content: I suggest avoiding air travel with that contraption! :p

author: Raj
author_rank: Frequent Contributor
timestamp: August 13, 2019, 07:55:48 am
content: Here's it completed... With forested acrylic at the front and end cap for battery door. Funny enough, since it's useless without the TV, and the tv is crt, I won't even thinking of taking it in an airplane.

author: Dabbot
author_rank: Regular Contributor
timestamp: August 13, 2019, 12:21:12 pm
content: Art.

author: Raj
author_rank: Frequent Contributor
timestamp: August 13, 2019, 01:09:46 pm
content: Funny, that I've taken a similar contraption with me, in a flight to Canada and backIt's basically a video camera CRT in sever pipe and a torch in a sever pipe (good that I wasn't stupid enough to leave the 18650 cell in the torch)