That seems to be a bit stupid to myself but I can't figure out to get to know when my button is pushed (closed) or released (open).

You must know that this not just a simple push button. Actually it is more of a complex button with multiples output (Y, G, 0V, COM, NO, NC, HORM, 12V). With a multimeter i've been able to locale witch output are closed when the button is pressed. These are HORM (that is the name for two outputs -?!-) and on the other side COM and NO.

I've tried to plug that to my arduino Mega, on PIN 7, and getting the value with Digital.Read. Tho when i try to display it on the Serial, it doesn't work and return an error. (It did the same for HORM and COM/NO)

I also noticed something strange. When the button is pressed, Arduino seems to notice it because my "ON" led turns off and then turns back on. Like if the arduino was crashing. The 13th pin LED stay HIGH after the arduino goes back on.

Please, have a look at my code.

int ledPin = 13; // choose the pin for the LED
int inPin = 7;   // choose the input pin (for a pushbutton)
int val = 0;     // variable for reading the pin status

void setup() {
  pinMode(ledPin, OUTPUT);  // declare LED as output
  pinMode(inPin, INPUT);    // declare pushbutton as input

void loop(){
  val = digitalRead(inPin);  // read input value
  if (val == HIGH) {         // check if the input is HIGH (button released)
    digitalWrite(ledPin, LOW);  // turn LED OFF
  } else {
    digitalWrite(ledPin, HIGH);  // turn LED ON


Do you guys have any advice ?

Thank you very much in advance.

Also please have a look at the circuit. The only difference is that instead of having this kind of simple pushbutton, i've got my NO and COM plugged the same way.

enter image description here

  • Please show your wiring
    – Majenko
    Apr 10, 2017 at 7:51
  • @Majenko Added something to illustrate. Just the button is different, but the plugs are the same
    – B.T
    Apr 10, 2017 at 8:01
  • 1
    If the LED is OFF and ON on the Arduino means, there is a chance you shortcut VCC and GND somewhere during the button push!
    – Sener
    Apr 10, 2017 at 8:10
  • @Sener And what could that come from ?
    – B.T
    Apr 10, 2017 at 8:12
  • 1
    Oh, and if it is you that plugged an LED in like that then remove it immediately. If you are following a tutorial that has the LED plugged in like that then comment on the tutorial to tell the author they know nothing and use a better tutorial.
    – Majenko
    Apr 10, 2017 at 8:19

1 Answer 1


Ok then.

I just tried that again and it simply seems that the wiring shown on the tutorial is not good at all. I made another wiring that worked exactly fine.

Your Answer

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

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