Pages: [1]   Go Down
Author Topic: Potentiometer Confusion (SOLVED)  (Read 947 times)
0 Members and 1 Guest are viewing this topic.
Around St. Louis
Offline Offline
Jr. Member
**
Karma: 0
Posts: 73
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So, this is my first time messing with a potentiometer on the arduino. I have a simple script that checks each of the analog channels for values above 512, and the first (a0) just relays the mapped value to an led on pin 13 (softpwm). The confusing part is, after the pot gets a quarter or so the way through spinning, the led is at max brightness, and if I spin it further, the rest of the analog pins act as if switches have been turned on.

I can understand the pot going to full in only a quarter turn. It's just the wrong resistance level (10k pot), but what I don't get is why the rest of the analog pins are acting as if the switches are turned on. The only thing I can think of is they have a noise variance because I didn't feel like hooking up any resistors, but they shouldn't they always act like they are on? (Also, what size pot do I need to make a full turn = max on an arduino. I'm still fairly new to electronics, but shouldn't I need a smaller resistance pot? Like a 5k?)

I know it should be simple, and it's probably something that's my fault, but Can someone help me out a little?
« Last Edit: May 20, 2011, 03:47:40 pm by Caliber Mengsk » Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 360
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you have the pot hooked up correctly (as a voltage divider), all pots will give you the full range (or almost), from <= 10 to >= 1000. 

It should be +5v -> outer pin, analog input 0 to center pin, and GND to the other outer pin. 

As for the rest, if you don't have anything attached to them, they're just floating - their readings will be random, and should be ignored.
Logged

Around St. Louis
Offline Offline
Jr. Member
**
Karma: 0
Posts: 73
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What does it mean if I have the pot hooked up right and it's still only getting a quarter turn to be at max?
Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 360
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It means you don't have it hooked up right, or your code is wrong.  Please show a picture and also paste your code here.
Logged

Around St. Louis
Offline Offline
Jr. Member
**
Karma: 0
Posts: 73
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I forgot to mention I already used the map function to resize the input. (Why I didn't just divide by 4 instead of using the map function, I don't know though.)

As far as the code with respect to the quarter turn, I had this:
SoftPWMSet(13, floatMap(analogRead(0),0,1024,0,255));
//(Float map is the same as Map, but with floats instead. Better precision in many cases, IMO, especially when scaling up instead of down.)

and changing it to be the simpler math,
SoftPWMSet(13, analogRead(0)/4);

As for hooking it up, I have it like the "New" one in this image:
http://www.rahji.com/wordpress/wp-content/uploads/2007/09/joystick_pot.png

where pin three is going to A0, and +5v input is from the 5v rail of an Arduino Duemilonove (spelling wrong I'm sure... O-o I always get it wrong smiley-lol).
« Last Edit: May 19, 2011, 09:13:43 pm by Caliber Mengsk » Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 360
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Have you tried just printing out the output from the analogRead() method?  It would be helpful to know if the problem is in reading the analog pin or in converting it for softPWM.
Logged

Around St. Louis
Offline Offline
Jr. Member
**
Karma: 0
Posts: 73
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I found out what my problem was. I was doing the 255 max value for softPWM, and it's percentage based, 100 max. That's why I was off. Seems to be working well now though.

Thanks for the help, It's much appreciated.
Logged

Pages: [1]   Go Up
Jump to: