Hi,
i am currently trying to restore/modify an aircraft altimeter, and have run into the following problem. The altimeter has two Pushbuttons (Honeywell 21SX39-T) i would like to wire up to an Arduino Nano. One of these buttons is set up in a way that, when not depressed, its circutry is closed, and opened when depressed, opposite to a regular push button.
For interfacing with a flight simulator, i need the input to be inverted. I tried doing this with both the INPUT_PULLUP pinMode, and an external pullup resistor. Both did not work, and i have no idea why.
Any Tips?
you can use INPUT_PULLUP and wire like this PIN - BUTTON - GND
- when you read HIGH, the button is pressed
- when you read LOW, the button is not pressed
Other way around.
no because his button is normally closed
(using the code from this guide Arduino INPUT_PULLUP Explained (pinMode) - The Robotics Back-End)
how did you wire it ?
and as long as you have a consistent value when pressed and unpressed, you should be good to go...
(seems it's not NC)
The line in the loop() function is doing two things in one line:
- Reading a digital input
- Writing something to the serial monitor
Serial.println(digitalRead(BUTTON_PIN));
It is okay to split that over two lines. In many cases it is better that each line is doing its own thing.
For example:
const int buttonPin = 11;
void setup()
{
Serial.begin(115200);
pinMode(buttonPin, INPUT_PULLUP);
}
void loop()
{
int value = digitalRead(buttonPin);
if (value == HIGH)
{
Serial.println("The button is being pressed.");
}
else
{
Serial.println("The button is in released state.");
}
delay(250);
}
buttons are typically connected between the pin and ground, the pin configured as INPUT_PULLUP to use the internal pullup resistor which pulls the pin HIGH and when pressed, the button pulls the pin LOW.
Each Button has 3 Pins.
One is ground, which is shared between them (left)
The other two are the outputs (centre and right). One switch has the center wire connected, one has the right wire. Thus one is inverted and one is not. Resoldering isnt an option, since i cant dissassemble the altimeter any further
T̶h̶a̶t̶s̶ ̶n̶o̶t̶ ̶w̶h̶a̶t̶ ̶t̶h̶i̶s̶ ̶g̶u̶i̶d̶e̶ ̶h̶t̶t̶p̶s̶:̶/̶/̶r̶o̶b̶o̶t̶i̶c̶s̶b̶a̶c̶k̶e̶n̶d̶.̶c̶o̶m̶/̶a̶r̶d̶u̶i̶n̶o̶-̶i̶n̶p̶u̶t̶_̶p̶u̶l̶l̶u̶p̶-̶p̶i̶n̶m̶o̶d̶e̶/̶ ̶(̶a̶n̶d̶ ̶o̶t̶h̶e̶r̶s̶ ̶h̶t̶t̶p̶s̶:̶/̶/̶w̶w̶w̶.̶e̶l̶e̶c̶t̶r̶i̶c̶a̶l̶4̶u̶.̶c̶o̶m̶/̶p̶u̶l̶l̶-̶d̶o̶w̶n̶-̶r̶e̶s̶i̶s̶t̶o̶r̶/̶)̶ ̶s̶a̶y̶ ̶.̶
̶I̶ ̶t̶h̶i̶n̶k̶ ̶y̶o̶u̶r̶e̶ ̶r̶e̶f̶e̶r̶r̶i̶n̶g̶ ̶t̶o̶ ̶a̶ ̶P̶u̶l̶l̶ ̶d̶o̶w̶n̶ ̶r̶e̶s̶i̶s̶t̶o̶r̶
Please ignore this, i read your message wrong. Yes, that is the principle. But its not working in my case
Thanks, but that code is just for testing, and not the issue at hand. As with the previous test code, this shows the opposite if the wanted result. "The button is in released state." is displayed when its pressed, and vice versa
I like to solve a problem in software, rather than in hardware, so that's what I did.
You can connect the button to 5V with one leg and use a pulldown resistor.
Anything is possible in both hardware and software. I'm afraid that I don't see the problem
I think Post#5 illustrates the problem pretty good. I would also like to solve this in software, but using INPUT_PULLUP to invert the input isnt working. Is there any code you would recommend for inverting the input?
That's not what INPUT_PULLUP does. What it does is prevent the pin from floating when the button is not pressed (with push-to-make buttons) or when the button is pressed (with push-to-break buttons).
Your buttons are momentary SPDT (single-pole-double-throw) switches. One is wired as push-to-make and the other is wired as push-to-break.
Connect both buttons between an Arduino pin and ground. Set the mode to INPUT_PULLUP. With push-to-make buttons, the pin will be LOW when the button is pressed. With push-to-break buttons, the pin will be HIGH when the button is pressed.
It's a wind-up.
Right, but what do i do to have both buttons be HIGH when pressed?
With the push-to-break button, connect the button between the Arduino pin and ground and set the pin mode to INPUT_PULLUP.
With the push-to-make button, connect the button between Vcc and the Arduino pin and connect an external pull-down resistor between the Arduino pins and ground. Set the pin mode to INPUT.
But the disadvantage of this is that there is a danger of a damaging short-circuit if the wire from Vcc to the button, or the wire from the button to the Arduino pin comes detached and touches something connected to ground. Also, an extra component (the pull-down resistor) is required. So connecting the way I described in post #15 is preferred. Another reason for doing it that way is because you said
the above indicates that it is. the button is pulling the pin LOW when pressed. but because the pin is only configured as an INPUT, instead of INPUT_PULLUP, the input is indecisive when not pressed.
why not recognize that the digitalRead() returns a LOW when a button is pressed?
of course, you can add an external pull-down resistor and wire the buttons between the pin and VCC, then the pin will be HIGH when the button is pressed
Right, my mistake. Is there way to invert the signal from the push-to-break when pressed from high to low? or is a pull-down resistor the only way