Serial input from button

Hi!

I got a Arduino Mega 2560 (the new one) and I use it with JunXion.

I will use it with JunXion to convert the serial signals from the Arduino i MIDI.

The problem is, when I connect a regular push button to GND and PIN22 (which is configured in the sketch)
the value in JunXion flickers. 0.00, 127, 0.00, 127... and so on. But when I push the button, the value
stays on 0.00 until I release again. Then it starts flickering again.

I've also tested to connect a 1k resistor between button and GND, but that didn't work! The same thing happens!

I'm a complete Arduino newbie. But I have some knowledge in electronics...

I would be so glad if you can point me in the correct direction!

Have a nice day!

/ Oskar

What you have is called a 'floating input' pin when you are not pressing the button, it just reads noise as there is no valid logic high voltage being applied to the pin when the switch is released.

If you wire your 1k resistor from the input pin to +5vdc, I think you will see it will work. One can also instead enable an internal software enabled pull-up resistor for the input pin by doing a digitalWrite(pin#,HIGH); right after the mode command setting the pin to input mode.

Lefty

Oh, okey! Thanks!

It isn't flickering anymore... I've connected the resistor to 5V and to PIN22.. and a push button between PIN22 and GND...

When the button isn't pushed, the value is 127. When I push it, it sais 0.00.

But why on earth does the Arduino need this extra resistor?

What happens when I will connect a LED to this circuit?
Like, if I want a LED that lights up when the button is pushed, AND the serial is sent.

See attached schematic. That's how I want it... Will that work with the extra resistor (they are not in the schematic by now). This schematic is for an old circuit that I made with a regular gamepad pcb. But now I want to make this with the Arduino instead!

But why on earth does the Arduino need this extra resistor?

All electronics do, read this for why:-
http://www.thebox.myzen.co.uk/Tutorial/Inputs.html

You will need pull down resistors on that circuit on the sensing lines so that normally the input is connected to ground (through the resistor) and pushing the button connects it to +5.

Hm... Okey... :slight_smile: :roll_eyes:

How do you mean that I should connect it different? I don't get it... :disappointed_relieved:

EDIT: The right line is 5V, blue is signal, and black is GND...

I made this schematic now... Would this work?
The only resistor now is the 3K. Will I need another one for the LED?

No the pull down resistor goes from the arduino pin to ground. You still need a resistor to limit the LED current but that is much smaller.

For a switch and LED combination see my project:-
http://www.thebox.myzen.co.uk/Hardware/Pendulum.html

Hm... okey... So... maybe... like THIS? :smiley: :.

Are they diodes or LEDs? If they are diodes then you don't need them. If they are LEDs then they are the wrong way round.

Whops! Newbie misstake! Those are bright LEDs.

The short leg to GND :slight_smile:

So I got everything correct now? See new image.

Would you please.... please... show me how to connect a potentiometer to one of the analog pins too? Without a LED this time...

Fine.

You are very kind and helpful!

With the information you provided, I can go forward with my project!

Big thanks to you!

Thanks for your time!

I have done some testing with above schemativ.

The button send the serial signal correctly... But the problem is that the LED is on when the button is release, and dimmed when the button is pushed... I guess that it is this way because PIN22 is connected to 5V through the pull down resistor.

How do I solve this?

What code are you running? You need to define your pins as inputs. What value of pull down are you using. It should not happen like this.

Please see attached Arduino sketch...

I guess they are configured as inputs?

In JunXion my input shows value 127 when not pushed, and 0 when pushed... If that tells us something.

And I use a 1K resistor for the pull down...

junXion_ArduinoMega.pde (14.4 KB)

I am a bit confused now, that is a lot of code to do so little. I can't find any pin definition. What value is your pull down resistors?
Is it wired up just like the last post? You must have something wrong. Any chance of a photo?

That code makes my Arduino work with JunXion... Don't know why it is so big. Doesn't the pin definitions begin at row 40?

I will hook you up with a picture in a minute!

hm... I think I lied to you...

Correct fact:

When button is released: The LED is dimmed
When button is pushed: The LED gets brigther

BUT. When I connect it like this. JunXion doesn't get any signals...

BUT. When I remove the 5V from the other connection (not the 5v from pull down). It DOES get signals..

Don't know why though.

Got any suggestion on what I have done wrong?