Arduino OPTA not able to use button, 12V logic

I am trying to connect connect an normally closed push button to my Arduino OPTA. I am using a 12V power supply which powers the OPTA and the push button. When I press the button, I want one of the inbuilt leds to light up. The

The problem that I am facing is that the OPTA does not react on button presses (continuity has been verified with voltmeter, so wiring is correct).

The code I am using is as follows:

const int buttonPin = 8;

void setup() {
  Serial.begin(9600);
  pinMode(LED_D0, OUTPUT);
  pinMode(buttonPin, INPUT_PULLUP);
  digitalWrite(LED_D0, HIGH);
}

void loop() {
  if (digitalRead(buttonPin) == HIGH) 
  {
    digitalWrite(LED_D0, LOW);
    Serial.println("Button not pressed");
  } else {
    digitalWrite(LED_D0, HIGH);
    Serial.println("Button pressed");
  }
  delay(1000);
}

I am wondering if the OPTA only reads high at 24 volts (?)

Appreciate the help I can get!


Setup

This is my setup:

your button should be wired PIN --- BUTTON --- GND

pin 18 will be LOW when the switch is closed

from top of memory, your input pin supports only 10V, you might have damaged it by sending 12V...

Thank you. I read somewhere that the range for the analog input input is between 0 and 10V, and for digital inputs its between 0 and 24V. Although not completely sure about this

OK - I don't own that equipment so that was just my recollection when I read the spec. finger crossed it is :slight_smile:

I hope I didn't ruin it :sweat_smile: Reffering to this article, I'm not the only one which is confused: Dig/An input range? - #7 by toddkrein

the datasheet comes to save you :slight_smile:

and you are right, 10V is for Analog input

Good stuff, thank you :grin: . Seems like I may need to upgrade my power supply to be able to use the digital inputs

why?

I don't see how I can lower the the threshold for what is read as a digital high. Any suggestions?

when you connect pin --- bouton --- GND and set the pin as INPUT_PULLUP, you let the MCU set the voltage for you.

that being said, 12V is the minimum for your power supply so you need a quality one.


@nachoherrera wrote that voltages over 5V are read as high, which makes me wonder why it does not work on my OPTA :thinking:

did you connect It the way I mentioned pin --- button -- GND ?
did you wire your button correctly?

i did try that, yes :confused:

@mbanzi do you have any input on this? :slight_smile:

then my bet is that it does not have pull-up resistors integrated into their GPIO pins.

try adding one externally...

That seems plausible, yes. Honestly been missing some more examples for this product, should not be too hard to provide :confused:

worth trying :slight_smile:

I managed to test an analog between 0 and 10 volts. Digital inputs however, remain a mystery. I tested with 12V to see if the DI went high, with still no luck. I think I will try a higher voltage, however @nachoherrera quote about "everything above 5V is seen as high" still puzzles me... :thinking:

Dear @simostor,

I think that you are using an incorrect pin mapping. As stated in Opta's User Manual, Opta's terminal I8 is mapped either as A7 or PIN_A7, you are using 8 in your code. So, the following line of code:

pinMode(buttonPin, INPUT_PULLUP);

Should change to the following:

pinMode(A7, INPUT) or pinMode(PIN_A7, INPUT)

Let me know if this solves your problem.