2

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.

enter image description here

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.

4
  • What is the role of the 555 chip in that circuit?
    – chrisl
    Oct 7, 2020 at 11:44
  • 1
    The 555 chip is being used to generate 3 waves. Oct 7, 2020 at 11:53
  • 1
    Does this answer your question? Multiple Push buttons to one input
    – Juraj
    Oct 7, 2020 at 13:36
  • 1
    I 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. Oct 9, 2020 at 9:43

2 Answers 2

3

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.

enter image description here

Try it out, you should be able to get well spaced out values for different push buttons!

6
  • R1 ... R5 can have different values, which might spread the ranges per button more evenly Oct 7, 2020 at 12:37
  • 2
    Re “1M”: Note that, on the Uno, the ADC is specified for a source output impedance no larger than 10 kΩ. 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
    Oct 7, 2020 at 15:09
  • 1
    @Majenko: “nothing” is a valid reading. 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
    Oct 7, 2020 at 15:27
1

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);
}
2
  • 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. 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. Oct 10, 2020 at 10:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.