Pages: [1] 2   Go Down
Author Topic: Serial input from button  (Read 1459 times)
0 Members and 1 Guest are viewing this topic.
Stockholm, Sweden
Offline Offline
Newbie
*
Karma: 0
Posts: 30
MIDI
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

Left Coast, CA (USA)
Online Online
Brattain Member
*****
Karma: 361
Posts: 17302
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: February 16, 2011, 10:38:05 am by retrolefty » Logged

Stockholm, Sweden
Offline Offline
Newbie
*
Karma: 0
Posts: 30
MIDI
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!



* schematic.gif (88.3 KB, 1469x2180 - viewed 11 times.)
« Last Edit: February 16, 2011, 12:08:23 pm by TNDR » Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 634
Posts: 34567
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Stockholm, Sweden
Offline Offline
Newbie
*
Karma: 0
Posts: 30
MIDI
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hm... Okey...  smiley 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...
« Last Edit: February 16, 2011, 03:52:28 pm by TNDR » Logged

Stockholm, Sweden
Offline Offline
Newbie
*
Karma: 0
Posts: 30
MIDI
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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


* Skärmavbild 2011-02-16 kl. 22.01.49.jpg (36.05 KB, 820x368 - viewed 12 times.)
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 634
Posts: 34567
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Stockholm, Sweden
Offline Offline
Newbie
*
Karma: 0
Posts: 30
MIDI
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hm... okey... So... maybe... like THIS?  smiley-grin smiley-small



* test.gif (101.06 KB, 842x595 - viewed 7 times.)
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 634
Posts: 34567
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Stockholm, Sweden
Offline Offline
Newbie
*
Karma: 0
Posts: 30
MIDI
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Whops! Newbie misstake! Those are bright LEDs.

The short leg to GND smiley

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


* test.gif (100.99 KB, 842x595 - viewed 13 times.)
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 634
Posts: 34567
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Fine.
http://www.arduino.cc/en/Tutorial/Potentiometer
Logged

Stockholm, Sweden
Offline Offline
Newbie
*
Karma: 0
Posts: 30
MIDI
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You are very kind and helpful!

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

Big thanks to you!
Logged

Stockholm, Sweden
Offline Offline
Newbie
*
Karma: 0
Posts: 30
MIDI
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
« Last Edit: February 17, 2011, 04:16:39 pm by TNDR » Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 634
Posts: 34567
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Stockholm, Sweden
Offline Offline
Newbie
*
Karma: 0
Posts: 30
MIDI
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.45 KB - downloaded 4 times.)
« Last Edit: February 17, 2011, 04:35:06 pm by TNDR » Logged

Pages: [1] 2   Go Up
Jump to: