Author Topic: Button input problem  (Read 1945 times)

0 Members and 1 Guest are viewing this topic.

Offline RajTopic starter

  • Frequent Contributor
  • **
  • Posts: 699
  • Country: in
  • Self taught, experimenter, noob(ish)
Button input problem
« on: July 31, 2019, 06:19:35 pm »
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 button

I'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-1000

Atleast that's all what I think is happening.

Note: i've already made the housing and thus can't replace switches with dpdt kind
« Last Edit: July 31, 2019, 06:41:47 pm by Raj »
 

Offline sokoloff

  • Super Contributor
  • ***
  • Posts: 1799
  • Country: us
Re: Button input problem
« Reply #1 on: July 31, 2019, 06:36:16 pm »
Do you have the inputs configured as INPUT or INPUT_PULLUP?

If you haven’t tried INPUT_PULLUP, that’s worth a shot.
 

Offline RajTopic starter

  • Frequent Contributor
  • **
  • Posts: 699
  • Country: in
  • Self taught, experimenter, noob(ish)
Re: Button input problem
« Reply #2 on: July 31, 2019, 06:40:41 pm »
It is pulled high, but it won't help, since pressing the button is essentially sending the pin to -0.5v
 

Offline sokoloff

  • Super Contributor
  • ***
  • Posts: 1799
  • Country: us
Re: Button input problem
« Reply #3 on: July 31, 2019, 06:44:42 pm »
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.
 
The following users thanked this post: Raj

Online MarkF

  • Super Contributor
  • ***
  • Posts: 2644
  • Country: us
Re: Button input problem
« Reply #4 on: July 31, 2019, 08:24:01 pm »
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/
 

Offline Nusa

  • Super Contributor
  • ***
  • Posts: 2417
  • Country: us
Re: Button input problem
« Reply #5 on: July 31, 2019, 09:17:44 pm »
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/
 
The following users thanked this post: Raj

Offline KL27x

  • Super Contributor
  • ***
  • Posts: 4108
  • Country: us
Re: Button input problem
« Reply #6 on: July 31, 2019, 10:35:02 pm »
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.


« Last Edit: August 01, 2019, 12:00:32 am by KL27x »
 

Offline RajTopic starter

  • Frequent Contributor
  • **
  • Posts: 699
  • Country: in
  • Self taught, experimenter, noob(ish)
Re: Button input problem
« Reply #7 on: August 01, 2019, 03:55:02 am »
...

I 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.

...

I 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.
« Last Edit: August 01, 2019, 04:11:57 am by Raj »
 

Offline KL27x

  • Super Contributor
  • ***
  • Posts: 4108
  • Country: us
Re: Button input problem
« Reply #8 on: August 01, 2019, 04:14:10 am »
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?
« Last Edit: August 01, 2019, 04:28:25 am by KL27x »
 

Offline RajTopic starter

  • Frequent Contributor
  • **
  • Posts: 699
  • Country: in
  • Self taught, experimenter, noob(ish)
Re: Button input problem
« Reply #9 on: August 01, 2019, 04:27:10 am »
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.1 :-DD

I'll have to go out in the rain to get more (3) diodes  :palm:
« Last Edit: August 01, 2019, 04:35:59 am by Raj »
 

Offline KL27x

  • Super Contributor
  • ***
  • Posts: 4108
  • Country: us
Re: Button input problem
« Reply #10 on: August 01, 2019, 04:31:51 am »
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.
« Last Edit: August 01, 2019, 04:39:40 am by KL27x »
 
The following users thanked this post: Raj

Offline RajTopic starter

  • Frequent Contributor
  • **
  • Posts: 699
  • Country: in
  • Self taught, experimenter, noob(ish)
Re: Button input problem
« Reply #11 on: August 01, 2019, 04:34:27 am »
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
 

Offline RajTopic starter

  • Frequent Contributor
  • **
  • Posts: 699
  • Country: in
  • Self taught, experimenter, noob(ish)
Re: Button input problem
« Reply #12 on: August 01, 2019, 04:38:36 am »
figure 4 worked...case solved... :-+ :-/O
 

Offline KL27x

  • Super Contributor
  • ***
  • Posts: 4108
  • Country: us
Re: Button input problem
« Reply #13 on: August 01, 2019, 04:49:03 am »
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?

 |O
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.
« Last Edit: August 01, 2019, 05:19:03 am by KL27x »
 

Offline RajTopic starter

  • Frequent Contributor
  • **
  • Posts: 699
  • Country: in
  • Self taught, experimenter, noob(ish)
Re: Button input problem
« Reply #14 on: August 01, 2019, 05:28:00 am »
Being slow is ok .... It's better than getting kicked (kicked myself out) out of college like me :-DD
Got f in Hindi,Punjabi and maths
« Last Edit: August 01, 2019, 05:49:58 am by Raj »
 

Offline RajTopic starter

  • Frequent Contributor
  • **
  • Posts: 699
  • Country: in
  • Self taught, experimenter, noob(ish)
Re: Button input problem
« Reply #15 on: August 01, 2019, 06:12:23 am »
Here's the abomination you just helped create :p
 

Offline KL27x

  • Super Contributor
  • ***
  • Posts: 4108
  • Country: us
Re: Button input problem
« Reply #16 on: August 01, 2019, 06:41:30 am »
 :-DD :-DD :-DD
Yeah, I was picturing something a little different when you said the housing was already completed.
 

Offline tooki

  • Super Contributor
  • ***
  • Posts: 12496
  • Country: ch
Re: Button input problem
« Reply #17 on: August 02, 2019, 02:43:41 pm »
I suggest avoiding air travel with that contraption! :p
 

Offline RajTopic starter

  • Frequent Contributor
  • **
  • Posts: 699
  • Country: in
  • Self taught, experimenter, noob(ish)
Re: Button input problem
« Reply #18 on: August 13, 2019, 07:55:48 am »
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.
« Last Edit: August 13, 2019, 12:54:47 pm by Raj »
 

Offline Dabbot

  • Regular Contributor
  • *
  • Posts: 192
  • Country: au
Re: Button input problem
« Reply #19 on: August 13, 2019, 12:21:12 pm »
Art.
 

Offline RajTopic starter

  • Frequent Contributor
  • **
  • Posts: 699
  • Country: in
  • Self taught, experimenter, noob(ish)
Re: Button input problem
« Reply #20 on: August 13, 2019, 01:09:46 pm »
Funny, that I've taken a similar contraption with me, in a flight to Canada and back
It'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)
« Last Edit: August 13, 2019, 01:12:06 pm by Raj »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf