Best potentiometer to use?

Hey I was hoping someone could help me with this.

I’m trying to control the speed of some Charlieplexed LEDs. I’m using Millis() as a timer NOT dely(). The pot I’m using is a 100k ohm linear taper pot 250vdc .25w that I picked up at Radio Shack. I hooked it up exactly as shown on this page:

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

In fact if you look at my code you’ll see I even “borrowed” some of the code off that page :slight_smile:

With the pot turned all the way left and about and about 1/4" to the right is where I can control the speed of the LEDs. If I go any farther to the right the LEDs slow way down but then the pot stops effecting the speed of the LEDS. It starts working again after ten or fifteen seconds but only if I stay in that 1/4" zone at the top left… Have I chosen the wrong pot? My code is pretty basic so it can’t be that or can it? I’m still pretty new at this so I’m not 100% sure of what I’m doing :-}

I looked at pots on Mouser.com but they toss so much information at me that I don’t understand I didn’t know what to buy. I did get two pots from SparkFun. A 10k Ohm and a 4.7k Ohm. Unfortunately they both look EXACTLY the same and there are no markings on them. So I can’t tell which is which :-/ One of them works and the other doesn’t work at all. The one that works doesn’t work as well as the 100k ohm I got from Radio Shack :-/

I would like better control over the speed of the LEDs. What the heck am I doing wrong? My code is below…

int pin1 = 7;
int pin2 = 6;
int pin3 = 5;
int pin4 = 4;
int pin5 = 3;
int pin6 = 2;
int pinF = 8;
int pinE = 9;
int pinD = 10;
int pinC = 11;
int pinB = 12;
int pinA = 13;

long t;
int A;
int potPin = 2;    // select the input pin for the potentiometer

void setup() {

}


void loop() {

A = analogRead(potPin);    // read the value from the sensor

int ledarray[30][20]=
{
/*LED 1*/{OUTPUT,OUTPUT,INPUT,INPUT,INPUT,INPUT,OUTPUT,OUTPUT,INPUT,INPUT,INPUT,INPUT,HIGH,LOW,HIGH,LOW,pin1,pin2,pinA,pinB},
/*LED 2*/{OUTPUT,OUTPUT,INPUT,INPUT,INPUT,INPUT,OUTPUT,OUTPUT,INPUT,INPUT,INPUT,INPUT,LOW,HIGH,LOW,HIGH,pin2,pin1,pinB,pinA},
/*LED 3*/{INPUT,OUTPUT,OUTPUT,INPUT,INPUT,INPUT,INPUT,OUTPUT,OUTPUT,INPUT,INPUT,INPUT,HIGH,LOW,HIGH,LOW,pin2,pin3,pinB,pinC},
/*LED 4*/{INPUT,OUTPUT,OUTPUT,INPUT,INPUT,INPUT,INPUT,OUTPUT,OUTPUT,INPUT,INPUT,INPUT,HIGH,LOW,HIGH,LOW,pin3,pin2,pinC,pinB},
/*LED 5*/{INPUT,INPUT,OUTPUT,OUTPUT,INPUT,INPUT,INPUT,INPUT,OUTPUT,OUTPUT,INPUT,INPUT,HIGH,LOW,HIGH,LOW,pin3,pin4,pinC,pinD},
/*LED 6*/{INPUT,INPUT,OUTPUT,OUTPUT,INPUT,INPUT,INPUT,INPUT,OUTPUT,OUTPUT,INPUT,INPUT,HIGH,LOW,HIGH,LOW,pin4,pin3,pinD,pinC},
/*LED 7*/{INPUT,INPUT,INPUT,OUTPUT,OUTPUT,INPUT,INPUT,INPUT,INPUT,OUTPUT,OUTPUT,INPUT,HIGH,LOW,HIGH,LOW,pin4,pin5,pinD,pinE},
/*LED 8*/{INPUT,INPUT,INPUT,OUTPUT,OUTPUT,INPUT,INPUT,INPUT,INPUT,OUTPUT,OUTPUT,INPUT,HIGH,LOW,HIGH,LOW,pin5,pin4,pinE,pinD},
/*LED 9*/{INPUT,INPUT,INPUT,INPUT,OUTPUT,OUTPUT,INPUT,INPUT,INPUT,INPUT,OUTPUT,OUTPUT,HIGH,LOW,HIGH,LOW,pin5,pin6,pinE,pinF},
/*LED 10*/{INPUT,INPUT,INPUT,INPUT,OUTPUT,OUTPUT,INPUT,INPUT,INPUT,INPUT,OUTPUT,OUTPUT,HIGH,LOW,HIGH,LOW,pin6,pin5,pinF,pinE},
/*LED 11*/{OUTPUT,INPUT,OUTPUT,INPUT,INPUT,INPUT,OUTPUT,INPUT,OUTPUT,INPUT,INPUT,INPUT,HIGH,LOW,HIGH,LOW,pin1,pin3,pinA,pinC},
/*LED 12*/{OUTPUT,INPUT,OUTPUT,INPUT,INPUT,INPUT,OUTPUT,INPUT,OUTPUT,INPUT,INPUT,INPUT,HIGH,LOW,HIGH,LOW,pin3,pin1,pinC,pinA},
/*LED 13*/{INPUT,OUTPUT,INPUT,OUTPUT,INPUT,INPUT,INPUT,OUTPUT,INPUT,OUTPUT,INPUT,INPUT,HIGH,LOW,HIGH,LOW,pin2,pin4,pinB,pinD},
/*LED 14*/{INPUT,OUTPUT,INPUT,OUTPUT,INPUT,INPUT,INPUT,OUTPUT,INPUT,OUTPUT,INPUT,INPUT,HIGH,LOW,HIGH,LOW,pin4,pin2,pinD,pinB},
/*LED 15*/{INPUT,INPUT,OUTPUT,INPUT,OUTPUT,INPUT,INPUT,INPUT,OUTPUT,INPUT,OUTPUT,INPUT,HIGH,LOW,HIGH,LOW,pin3,pin5,pinC,pinE},
/*LED 16*/{INPUT,INPUT,OUTPUT,INPUT,OUTPUT,INPUT,INPUT,INPUT,OUTPUT,INPUT,OUTPUT,INPUT,HIGH,LOW,HIGH,LOW,pin5,pin3,pinE,pinC},
/*LED 17*/{INPUT,INPUT,INPUT,OUTPUT,INPUT,OUTPUT,INPUT,INPUT,INPUT,OUTPUT,INPUT,OUTPUT,HIGH,LOW,HIGH,LOW,pin4,pin6,pinD,pinF},
/*LED 18*/{INPUT,INPUT,INPUT,OUTPUT,INPUT,OUTPUT,INPUT,INPUT,INPUT,OUTPUT,INPUT,OUTPUT,HIGH,LOW,HIGH,LOW,pin6,pin4,pinF,pinD},
/*LED 19*/{OUTPUT,INPUT,INPUT,OUTPUT,INPUT,INPUT,OUTPUT,INPUT,INPUT,OUTPUT,INPUT,INPUT,HIGH,LOW,HIGH,LOW,pin1,pin4,pinA,pinD},
/*LED 20*/{OUTPUT,INPUT,INPUT,OUTPUT,INPUT,INPUT,OUTPUT,INPUT,INPUT,OUTPUT,INPUT,INPUT,HIGH,LOW,HIGH,LOW,pin4,pin1,pinD,pinA},
/*LED 21*/{INPUT,OUTPUT,INPUT,INPUT,OUTPUT,INPUT,INPUT,OUTPUT,INPUT,INPUT,OUTPUT,INPUT,HIGH,LOW,HIGH,LOW,pin2,pin5,pinB,pinE},
/*LED 22*/{INPUT,OUTPUT,INPUT,INPUT,OUTPUT,INPUT,INPUT,OUTPUT,INPUT,INPUT,OUTPUT,INPUT,HIGH,LOW,HIGH,LOW,pin5,pin2,pinE,pinB},
/*LED 23*/{INPUT,INPUT,OUTPUT,INPUT,INPUT,OUTPUT,INPUT,INPUT,OUTPUT,INPUT,INPUT,OUTPUT,HIGH,LOW,HIGH,LOW,pin3,pin6,pinC,pinF},
/*LED 24*/{INPUT,INPUT,OUTPUT,INPUT,INPUT,OUTPUT,INPUT,INPUT,OUTPUT,INPUT,INPUT,OUTPUT,HIGH,LOW,HIGH,LOW,pin6,pin3,pinF,pinC},
/*LED 25*/{OUTPUT,INPUT,INPUT,INPUT,OUTPUT,INPUT,OUTPUT,INPUT,INPUT,INPUT,OUTPUT,INPUT,HIGH,LOW,HIGH,LOW,pin1,pin5,pinA,pinE},
/*LED 26*/{OUTPUT,INPUT,INPUT,INPUT,OUTPUT,INPUT,OUTPUT,INPUT,INPUT,INPUT,OUTPUT,INPUT,HIGH,LOW,HIGH,LOW,pin5,pin1,pinE,pinA},
/*LED 27*/{INPUT,OUTPUT,INPUT,INPUT,INPUT,OUTPUT,INPUT,OUTPUT,INPUT,INPUT,INPUT,OUTPUT,HIGH,LOW,HIGH,LOW,pin2,pin6,pinB,pinF},
/*LED 28*/{INPUT,OUTPUT,INPUT,INPUT,INPUT,OUTPUT,INPUT,OUTPUT,INPUT,INPUT,INPUT,OUTPUT,HIGH,LOW,HIGH,LOW,pin6,pin2,pinF,pinB},
/*LED 29*/{OUTPUT,INPUT,INPUT,INPUT,INPUT,OUTPUT,OUTPUT,INPUT,INPUT,INPUT,INPUT,OUTPUT,HIGH,LOW,HIGH,LOW,pin1,pin6,pinA,pinF},
/*LED 30*/{OUTPUT,INPUT,INPUT,INPUT,INPUT,OUTPUT,OUTPUT,INPUT,INPUT,INPUT,INPUT,OUTPUT,HIGH,LOW,HIGH,LOW,pin6,pin1,pinF,pinA},
};



for(int led = 0; led < 30; led++ ){

   pinMode(pin1, ledarray[led][0]);
   pinMode(pin2, ledarray[led][1]);
   pinMode(pin3, ledarray[led][2]);
   pinMode(pin4, ledarray[led][3]);
   pinMode(pin5, ledarray[led][4]);
   pinMode(pin6, ledarray[led][5]);
   pinMode(pinA, ledarray[led][6]);
   pinMode(pinB, ledarray[led][7]);
   pinMode(pinC, ledarray[led][8]);
   pinMode(pinD, ledarray[led][9]);
   pinMode(pinE, ledarray[led][10]);
   pinMode(pinF, ledarray[led][11]);
   digitalWrite(ledarray[led][16], ledarray[led][12]);
   digitalWrite(ledarray[led][17], ledarray[led][13]);
   digitalWrite(ledarray[led][18], ledarray[led][14]);
   digitalWrite(ledarray[led][19], ledarray[led][15]);

   t = millis();
   while(t+A>millis());
}
}

Does it make a difference that I put my timer at the bottom of the loop?

How is your pot wired to the input pin?

OK, first you are using the pot to obtain a variable time delay for your sketch. What range of delay are you wishing to have. What you show there seems to give around a 0-1 second delay, it that what you want to have for a adjustable delay?

Lefty

@AWOL I hooked up the pot exactly as shown in the picture on this page:

Middle connection of pot to analog pin 2
Right outside connection to Gnd
Left outside connection to 5V

@Lefty Yes I am using the pot to define the variable for the time delay. I want to use the pot to slow down and speed up my LED pattern. Ideally I want much more then 0-1 seconds. I would like to be able to get a smooth change in the pattern from very slow to very fast over the whole range of the pot.

With things as they are now I do get a very slow speed, a very fast speed and speeds in between.

The problem is that I can really only control the speed in that upper 1/4" portion of the pot. So it goes from slow to fast over a very small range of the available turn of the pot.

If I "turn down" the pot below that 1/4" at the top the speed of the pattern slows way down but the pot stops having any effect over the speed.

I have to turn the pot back up to the top portion and wait for about 10 seconds before it has any effect on the speed again...

It's hard to describe. If it'll help I'll put up a youtube vid of the hardware in action so it makes more sense.

It's hard to describe

Numbers are easy to digest - print and post the analogue input values at 1/4 turn, half turn, 3/4 turn.

That code is very odd, why are you initialing the array every time round the loop?

Try printing out the values from the A/D but it looks to me like you spend so long in the loop doing things the long way that the time delay is insignificant compared to the loop time.
Also note by having the direct output of the analogue read as a delay you have a maximum delay of 1.023 seconds.

Have you seen the Charlieplexing library?

I'm doing it this way because I understand it. I've seen lots of other ways to do charlieplexing but honestly I don't understand them.

I'm an artist who is VERY new to coding. Math is always a struggle for me :-/

@AWOL Yeah I have seen the Charlieplexing library but I couldn't find an explanation of how to use it that made sense to me. When I opened up the library to look at the code inside it it made even less sense :-/

However that was a while ago and I have learned a lot since then. I'll take another look at the library page and see if I can make better sense of it now.

Numbers are easy to digest - print and post the analogue input values at 1/4 turn, half turn, 3/4 turn.

Sorry, I have no idea how to do that :-}

That code is very odd, why are you initialing the array every time round the loop?

In order to get the different inputs, outputs and pins needed for each charlieplexed LED.

Wait, do you mean why did I put it in the Void loop() section of the program? Duh, you mean put the array up at the top where I declare the rest of the variables? That works. Thank you for the clunk on the head :slight_smile:

But it looks to me like you spend so long in the loop doing things the long way that the time delay is insignificant compared to the loop time.

Ah, that would make sense. So by doing it this way it's actually taking so long to digest the code in the loop that it takes a while to get to the new information from the pot?

But then why do I get a smooth transition of speed over the top 1/4" of the pot? If the way the code was written was the problem wouldn't it be a problem period? Not just over a portion of the pot? Unless it's the initialization the array each time?

I've moved the array up to the top of the program but the hardware is attached to a different computer. I'll try it tonight and report back how the change effects the program.

THANKS!

Is it a logarithmic pot? A linear pot might work better for that application.
-e

Just for the heck of it I put up a video:

In it you can see the type of results I get and the delay when I turn the pot past the responsive “zone.” When the pattern goes from the slow to suddenly very fast that’s the delay until the pot becomes active again…

This is the pot I’m using:

100K-Ohm Linear-Taper Potentiometer
250VDC .25W

I moved the array up to the top of the program (out of the void loop()) but it didn’t seem to make much difference :-/

Sigh…

I tried to run the Charlieplaxing program given on the page:

http://www.arduino.cc/playground/Code/Charlieplex

to figure out the code and got back this error message (yes I had the library loaded and included):

sketch_jun27a.cpp: In function ‘void loop()’:
sketch_jun27a:20: error: ‘plex’ was not declared in this scope
sketch_jun27a:22: error: ‘plex’ was not declared in this scope

#include <Charlieplex.h>

#define NUMBER_OF_PINS 3
//define pins in the order you want to adress them
byte pins[] = {11,12,13};
 
//initialize object
Charlieplex charlieplex = Charlieplex(pins,NUMBER_OF_PINS);
 
//individual 'pins' , adress charlieplex pins as you would adress an array
charliePin led1 = { 1 , 2 }; //led1 is indicated by current flow from 12 to 13
charliePin led2 = { 2 , 1 };
charliePin led3 = { 0 , 2 };
 
boolean singleOn = false;
 
 
void setup(){ /*nothing*/ }
 
void loop(){
  if (singleOn){ plex.clear(); }
 
  plex.charlieWrite(led1,HIGH);
  delay(1000);
  plex.charlieWrite(led2,HIGH);
  delay(1000);
  plex.charlieWrite(led3,HIGH);
  delay(1000);
 
  singleOn=!singleOn;
}

I opened up the library and looked for plex and didn’t see it being used anywhere. Does anyone know how it’s being used and why I’m getting this error?

Maybe pull aref hard up to 5v (short 5v and AREF pins) What if it is floating?

AndrewStone:
Maybe pull aref hard up to 5v (short 5v and AREF pins) What if it is floating?

That is almost never a good idea. What is your thinking on that recommendation?

Lefty

You need to write a sketch that just reads the port and outputs the data it reads. Then you can see if the pot is giving the full range as I suspect it will. I think what is going wrong here is the delay is not in the right place, or should I say places.

I tried to run the Charlieplaxing program given on the page

From: Arduino Playground - HomePage

I would love feedback at alexanderbrevig@gmail.com

Talk to the man.

@retrolefty: Well I DID say "maybe" so I was more opening the idea then offering a recommendation. To answer your question, my thinking is that since there are no details in the AVR spec on exactly how the chip chooses to use AREF verses its internal voltage reference its a big question mark as to when it switches. And even if there were, perhaps for some reason that circuit is marginal on his chip. So what if it is choosing AREF, or popping back and forth?

Sure its a long shot (but you guys had exhausted all the obvious stuff), but why is it not a good idea? I mean I thought that that was what the AREF pin was for.

Cheers!
Andrew

but you guys had exhausted all the obvious stuff

I don't think we had, I was trying to get him to just print put the readings from the A/D to see if there was a problem before we get into trying to fix it.

Quote
Numbers are easy to digest - print and post the analogue input values at 1/4 turn, half turn, 3/4 turn.

Sorry, I have no idea how to do that :-}

const int potPin = 2;
void setup ()
{
  Serial.begin (9600);
}

void loop ()
{
  Serial.println (analogRead (potPin));
}

@grumpy_mike: You are right, I am 100% guilty of offering a solution to a problem that might not exist! :slight_smile:

OK I ran the program that AWOL was kind enough to write for me.
I compiled it and then uploaded it to the board. When I checked the serial monitor

the number go from 259 to 480 from one side to the other

From all the way left to 3/4 the numbers go from 256 to 333
then in the 1/4" zone it goes from 333 to 480

Does that help?

I did try emailing alexanderbrevig@gmail.com when I first started this. He never answered...

@Grumpy_Mike I did try moving my timing statements to the top of the loop just to see what effect it might have. It changed nothing. Unless you had something else in mind?