I'm trying to put together a momentary switch circuit to use with my Arduino for a project. Essentially what I'm trying to do is use one pin on the Arduino for an analog read and another for an interrupt. I'll probably end up using six switches so my plan was to make a voltage divider using some resistors at each switch to make a different voltage value to be read by the analogRead pin.
My problem is with the interrupt pin - for voltage values above 2.5 (digital high) it will trigger the interrupt, but when I have a voltage divider value that is below 2.5 it will read low and be unable to trigger the interrupt.
So my next thought was to use a transistor as a switch and have the voltage divider node connected to the base of the transistor and the collector attached to 5v and the emitter attached to the interrupt pin so that way it would just pass the digital high regardless of the voltage value at each of the voltage dividers.
This is the step I'm having some trouble with as my whole understanding of transistors isn't all that great. I've been testing out some values in Multisim but the circuit doesn't seem to be working as intended. Any advice or general knowledge would be awesome!
p.s. I know I can use a shift register to accomplish the same thing I am attempting here but I wanted to try something different and learn something new
I'll probably end up using six switches so my plan was to make a voltage divider using some resistors at each switch to make a different voltage value to be read by the analogRead pin.
Why? Why can't you use 6 inputs?
You're trying to read digital states as analog values, and that's usually a bad idea. There's a good reason that computers & logic circuits use digital circuitry.
If you MUST use one input to read multiple digital values/states, look into multiplexer chips.
I can use six inputs, but I don't want to. I actually want to learn to do something new.
You're trying to read digital states as analog values, and that's usually a bad idea.
This is NOT what I'm trying to do. I am trying to use the interrupt pin to detect any changes in voltage so I can press these switches anywhere within the sketch. Unfortunately the only options for the interrupt pin are LOW, CHANGE, RISING and FALLING so it can't do this for voltage values <2.5. What I am trying to do instead is when a switch is pressed have it take the detected voltage (regardless of logic level) from the voltage divider to the base of the transistor switch allowing the 5v to pass to a digital pin pass simulating a digital high for any sort of voltage regardless of whether it is >2.5V.
If you MUST use one input to read multiple digital values/states, look into multiplexer chips.
Look, DVDdoug, I thank you for your post. But I TOLD you I don't want to do it this way. I don't want to use any shift registers/multiplexers or anything of the sort. What I'm trying to do here isn't rocket science and I'm sure some genius here knows a way to accomplish what I'm trying to do using basic circuitry.
I am sure there are many of us that can easily suggest to you a circuit that will generate an interrupt on a single pin, when one of a number of switches is pressed, then read the voltage that you want to present to it. But unless we can see what that will achieve or why you want to do it, its a bit of an ask.
yendis:
I am sure there are many of us that can easily suggest to you a circuit that will generate an interrupt on a single pin, when one of a number of switches is pressed, then read the voltage that you want to present to it. But unless we can see what that will achieve or why you want to do it, its a bit of an ask.
Is this an XY problem?
I don't think so. OP definitely said it was just a learning project. But there isn't much to learn if someone just posts a circuit.
There is something to be learned from designing something, and then realizing how many more parts it uses, compared with another, more standard approach. But hopefully before it's built.
For example, there is no need for interrupts to read something as slow as a key. That is pretty well universally accepted wisdom.
I am sure there are many of us that can easily suggest to you a circuit that will generate an interrupt on a single pin, when one of a number of switches is pressed, then read the voltage that you want to present to it. But unless we can see what that will achieve or why you want to do it, its a bit of an ask.
Is this an XY problem?
Christ. I don't think it's THAT much work to make some suggestion for a small circuit. If you must know, I made a project for my family/dog that has multiple navigate-able menus on an LCD (bathroom, treats, meals, etc...) along with some LED outputs for meals. The problem is my dad is lazy and doesn't understand homemade electronics projects so well even after explaining it to him. So what I want to do is have it so that all he has to do is press some buttons for some things regardless of where the program is in the sketch on any of these menus.
I realize there are other ways to go about this without using interrupts - ex. including digital read code for every switch on each menu or having a timeout for if the program is on a menu too long to go back to the main menu where it would be digital reading for these switches. I also realize that part of this would be easy to accomplish with a shift register or a multiplexer. But this is the way I would like to do it.
Maybe if I re-explain the problem it may be easier to come up with a solution. Each of my switches is a voltage divider - ex. 4.5 volts is switch one, 4 volts is switch 2 etc.. In order to read these voltage values anywhere in the program I would like to use an interrupt so the voltage divider nodes on each of these is connected to an analogRead pin (A0) and an interrupt pin (2). Now this is where I am having issues, for any values below 2.5V it will not be read as a digital high so what I want to do instead is have it so that any of these voltages regardless of logic level to be connected to a transistor to act as a switch passing 5V to my interrupt pin.
All in all regardless of how silly the way I am doing this is. The main thing I am genuinely curious about is how I can take a low voltage level between say .5-2 volts and use that to close a transistor switch passing 5V to another pin.
All in all the main thing I am genuinely curious about is how I can take a low voltage level between say .5-2 volts and use that to close a transistor switch passing 5V to another pin.
You could use a LM339 voltage comparator configuration set to .5V with its power supply at 5 volts.
jaeryl:
The main thing I am genuinely curious about is how I can take a low voltage level between say .5-2 volts and use that to close a transistor switch passing 5V to another pin.
If I absolutely had to do what you want... I think you could put a PNP transistor emitter-base between VCC and R1. Eliminate Q1. The collector to a load resistor connected to ground. The collector-R junction goes to the interrupt input port. Sufficient current in the resistor matrix would saturate the transistor and pull the interrupt pin from low to high. You only lose about 0.7 volts, a junction drop to feed the switch matrix with 5-0.7 = 4.3V. So the input values will be a little lower.
Ok, if I understand what you are trying to do, this circuit attached, will generate a low (0V) interrupt signal when a button is pressed, and while the button is held down a voltage will be present on another pin, depending on the values you set for the resistors.
The circuit comprises basically a diode OR gate, combined with a switchable potential divider.
LarryD:
You could use a LM339 voltage comparator configuration set to .5V with its power supply at 5 volts.
A friend actually recommended this to me last night and I tried it out in simulation software and it worked beautifully! Thank you.
outsider:
You could connect a diode from each button to the interrupt pin, any button would trigger the interrupt but not affect the others.
pegwatcher:
That sounds like the simplest & best solution.
The only problem with this is that for values below the 2.5V it still would not trigger a digital high on the interrupt pin.
yendis:
Ok, if I understand what you are trying to do, this circuit attached, will generate a low (0V) interrupt signal when a button is pressed, and while the button is held down a voltage will be present on another pin, depending on the values you set for the resistors.
The circuit comprises basically a diode OR gate, combined with a switchable potential divider.
Is that what you wanted?
Thanks, Yendis. Even though I already found a solution I'll definitely give this a shot as well since you took the time to post it.