Go Down

Topic: Serial input from button (Read 1 time) previous topic - next topic

TNDR

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


retrolefty

#1
Feb 16, 2011, 04:36 pm Last Edit: Feb 16, 2011, 04:38 pm by retrolefty Reason: 1
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

TNDR

#2
Feb 16, 2011, 06:05 pm Last Edit: Feb 16, 2011, 06:08 pm by TNDR Reason: 1
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!


Grumpy_Mike

Quote
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.

TNDR

#4
Feb 16, 2011, 08:48 pm Last Edit: Feb 16, 2011, 09:52 pm by TNDR Reason: 1
Hm... Okey...  :) :smiley-roll:

How do you mean that I should connect it different? I don't get it...  :smiley-sad-blue:

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

TNDR

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

Grumpy_Mike

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

TNDR

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


Grumpy_Mike

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.

TNDR

Whops! Newbie misstake! Those are bright LEDs.

The short leg to GND :)

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...

Grumpy_Mike


TNDR

You are very kind and helpful!

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

Big thanks to you!

TNDR

#12
Feb 17, 2011, 10:10 pm Last Edit: Feb 17, 2011, 10:16 pm by TNDR Reason: 1
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?

Grumpy_Mike

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.

TNDR

#14
Feb 17, 2011, 10:32 pm Last Edit: Feb 17, 2011, 10:35 pm by TNDR Reason: 1
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...

Go Up