The following circuit is a simplified version of a more complex system. For testing purposes, the 555 Timer was added to serve as a test signal source with frequencies set by the resistors in series. Each arbitrary signal is indicated by a push button and the Arduino needs to be able to distinguish what button has been pushed. Unfortunately, there can only be 3 buttons and more cannot be added. This is where the problem occurs. How can you reliably indicate which push button has been pressed without interfering with the arbitrary waveform?
At first, my original thought was to have the Arduino sample the signal based on that sample the Arduino would be able to tell which button is pressed.
When button 1 in the pink is pushed the Arduino receives a takes the following sample of the signal.
843
848
849
849
849
849
// Time 0 when button is pushed
532
414
500
373
463
346
425
370
386
476
346
442
642
788
Moving the input enter image description here
// At t = 0 the Serial Monitor reads zero
998
998
998
998
998
0
0
0
0
0
998
0
0
0
0
0
0
0
0
0
998
0
0
0
0
998
0
0
0
998
998
998
0
998
0
0
0
998
0
0
0
0
Moving the analog input does not make it any easier to distinguish which button was being pushed. Which is why I decided to ask the community on how to deal with this. I have tried using a relay and simply hard coding all of the cases but the result is a system is not very robust and is vulnerable to easily break over time.
-
What is the role of the 555 chip in that circuit?chrisl– chrisl2020年10月07日 11:44:52 +00:00Commented Oct 7, 2020 at 11:44
-
1The 555 chip is being used to generate 3 waves.David Wisniewski– David Wisniewski2020年10月07日 11:53:50 +00:00Commented Oct 7, 2020 at 11:53
-
1Does this answer your question? Multiple Push buttons to one inputJuraj– Juraj ♦2020年10月07日 13:36:21 +00:00Commented Oct 7, 2020 at 13:36
-
1I need to apologize for the previous wording of my question I believe I made it difficult to understand. I am still relatively new to electronics in the future I will work to improve this.David Wisniewski– David Wisniewski2020年10月09日 09:43:20 +00:00Commented Oct 9, 2020 at 9:43
2 Answers 2
There's an easy way to achieve reading multiple pushbuttons using single analog input.
All you need to do is create some voltage dividers at different voltages which can be read using analogRead. The last resistor,R6, in the diagram below ensures that the pin reads 0 when no push-button is pressed (i.e pull-down resistor). In the diagram below, connect Vcc to 5V on the Arduino.
Try it out, you should be able to get well spaced out values for different push buttons!
-
R1 ... R5 can have different values, which might spread the ranges per button more evenlyDataFiddler– DataFiddler2020年10月07日 12:37:27 +00:00Commented Oct 7, 2020 at 12:37
-
2Re "1M": Note that, on the Uno, the ADC is specified for a source output impedance no larger than 10 kΩ.Edgar Bonet– Edgar Bonet2020年10月07日 12:46:23 +00:00Commented Oct 7, 2020 at 12:46
-
2@EdgarBonet The 1M is just a float-prevention pulldown. By having it so high it prevents the input floating with no buttons pressed and at the same time has little effect on the readings. Worst case the output impedance with Button 1 pressed would be 799.36Ω. With nothing pressed there's no output to have an impedance. Just ground through a resistor. Yes, it may slow down the transition from a valid reading to nothing, but that's not a problem.Majenko– Majenko2020年10月07日 15:09:12 +00:00Commented Oct 7, 2020 at 15:09
-
1@Majenko: "nothing" is a valid reading.Edgar Bonet– Edgar Bonet2020年10月07日 15:14:32 +00:00Commented Oct 7, 2020 at 15:14
-
Yes, but it's not an actively valid reading that is being driven by the rest of the circuit - just a "stop it floating" nothingness.Majenko– Majenko2020年10月07日 15:27:57 +00:00Commented Oct 7, 2020 at 15:27
After a day or two of working on this problem, I have found that it is best to avoid using the analog pins and stay away from directly interfacing with the 555 Timer. This is a simplified version of a more complex circuit and the 555 Timer represents some arbitrary signal source. For example, on mobile radio, you push a button to send out a certain frequency. That is the concept here only the frequencies cannot be adjusted yet. Now that it has been clarified that the 555 Timer has been placed in the circuit for debugging purposes here is the best solution I have found to this problem. First, I have found that it is doable to read in from the analog pin on the Arduino but not easy. This leaves a lot of room for error being that the waveform is arbitrary with some random frequency. Therefore, I have opted to use the digital pins on the Arduino. Revised Circuit by using the digital pins I have now only have to worry about whether the button is high or low. Then NPN transistors were used to act as switches once the button is pushed. The diodes then were added to maintain a steady voltage across the base of the transistor. For testing purposes, the LCD was removed and replaced by an LED. As far as the code is concerned it is nothing extraordinary or complex as shown below. Therefore, I believe this may be the best way to go about solving this problem.
const int D_pin10 = 10;
const int D_pin9 = 9;
const int D_pin8 = 8;
int led = 13;
void setup()
{
pinMode(D_pin10 , INPUT); // pin 10 is an input
pinMode(D_pin9 , INPUT); // pin 10 is an input
pinMode(D_pin8, INPUT); // pin 10 is an input
pinMode(led, OUTPUT);
}
void loop()
{
int High_Low10 =0;
int High_Low9 =0;
int High_Low8 =0;
High_Low10 = digitalRead(D_pin10);
High_Low9 = digitalRead(D_pin9);
High_Low8 = digitalRead(D_pin8);
if(High_Low10 == HIGH)
{
digitalWrite(led, HIGH);
}
else if(High_Low9 == HIGH)
{
digitalWrite(led, HIGH);
}
else if(High_Low8 == HIGH)
{
digitalWrite(led, HIGH);
}
else
{
digitalWrite(led, LOW);
}
delay(1000);
}
-
If your aim is to detect button presses accurately, and use one pin per button, you don't need transistors, diodes or any other hardware apart from pushButtons. You can directly connect to pushbutton via an internal pull-up resistor and accurately read button states.Siddharth Kothari– Siddharth Kothari2020年10月10日 10:29:16 +00:00Commented Oct 10, 2020 at 10:29
-
The goal is to control the astable 555 Timer with the pushbuttons. The diodes and transistors are functioning as a switch.David Wisniewski– David Wisniewski2020年10月10日 10:31:56 +00:00Commented Oct 10, 2020 at 10:31
Explore related questions
See similar questions with these tags.