Go Down

Topic: Potentiometer LED control circuit modification (Read 114 times) previous topic - next topic

TIJHE_VV

Aug 13, 2018, 08:04 am Last Edit: Aug 13, 2018, 10:11 am by TIJHE_VV
Hello All! First off i would like to apologies for my previous post not being up to scratch. So basically, i have an LED circuit of which a potentiometer, when moved to the left or right, will toggle an led to light up. So if the arduino reads a voltage from the potentiometer of lets say 5V(Fully Right), it sets D12 to a HIGH, with the other 11 LEDS off, and if it reads 0 valts(Fully Left), it sets D0 to a HIGH, and so on and so fourth.

I was successful in creating this code, but the problem is that it only uses a very small amount of the potentiometer (10K Ohm) and 3 quarters of the potentiometer just leaves all leds off. I have attempted changing the map value to one that is higher, i have also attempted researching and asking a good friend of mine for help, but he suggested that i post it here.

Here is my code-
Code: [Select]
int FDOT = 0;
int FULL = 1;
int F2 = 2;
int F28 = 3;
int F4 = 4;
int F56 = 5;
int F8 = 6;
int F11 = 7;
int F16 = 8;
int F22 = 12;
int CDOT = 10;
int CLEAR = 11;
int potPin = A0;
int potVal;
float voltage;

void setup() {
  pinMode(FDOT, OUTPUT);
  pinMode(FULL, OUTPUT);
  pinMode(F2, OUTPUT);
  pinMode(F28, OUTPUT);
  pinMode(F4, OUTPUT);
  pinMode(F56, OUTPUT);
  pinMode(F8, OUTPUT);
  pinMode(F11, OUTPUT);
  pinMode(F16, OUTPUT);
  pinMode(F22, OUTPUT);
  pinMode(CDOT, OUTPUT);
  pinMode(CLEAR, OUTPUT);
  pinMode(potPin, INPUT);
}

void loop() {
potVal = analogRead(A0);
analogRead(potPin);
potVal = map(potVal, 0, 1023, 0, 11);
voltage = potVal * (5.0 / 1023);


if  (analogRead(potVal) == 0) // FDOT CODE
digitalWrite(FDOT, HIGH);
else
digitalWrite(FDOT, LOW);    // FDOT CODE END


if (analogRead(potVal) ==  1)  // FULL CODE
digitalWrite(FULL, HIGH);
else
digitalWrite(FULL, LOW);   // END OF FULL CODE  



if (analogRead(potVal) ==  2)  // F2 CODE
digitalWrite(F2, HIGH);
else
digitalWrite(F2, LOW);    // END OF F2 CODE  



if (analogRead(potVal) ==  3)  // F28 CODE
digitalWrite(F28, HIGH);
else
digitalWrite(F28, LOW);   // END OF F28 CODE  



if (analogRead(potVal) ==  4)  // F4 CODE
digitalWrite(F4, HIGH);
else
digitalWrite(F4, LOW);    // END OF F4 CODE  



if (analogRead(potVal) ==  5)  // F56 CODE
digitalWrite(F56, HIGH);
else
digitalWrite(F56, LOW);    // END OF F56 CODE



if (analogRead(potVal) ==  6)  // F8 CODE
digitalWrite(F8, HIGH);
else
digitalWrite(F8, LOW);   // END OF F8 CODE  


if (analogRead(potVal) ==  7)  // F11 CODE
digitalWrite(F11, HIGH);
else
digitalWrite(F11, LOW);   // END OF F11 CODE  


if (analogRead(potVal) ==  8)  // F16 CODE
digitalWrite(F16, HIGH);
else
digitalWrite(F16, LOW);   // END OF F16 CODE  


if (analogRead(potVal) ==  9)  // F22 CODE
digitalWrite(F22, HIGH);
else
digitalWrite(F22, LOW);  // END OF F22 CODE  


if (analogRead(potVal) ==  10)  // CDOT CODE
digitalWrite(CDOT, HIGH);
else
digitalWrite(CDOT, LOW);    // END OF CDOT CODE  


if (analogRead(potVal) ==  11)  // CLEAR CODE
digitalWrite(CLEAR, HIGH);
else
digitalWrite(CLEAR, LOW);   // END OF CLEAR CODE
}


And here is a video better explaining what i mean.
https://youtu.be/ugtiyYPssfA

Wawa

#1
Aug 13, 2018, 09:03 am Last Edit: Aug 13, 2018, 09:06 am by Wawa
Hello All! First off i would like to apologies for my previous post not being up to scratch. So basically, i have an LED circuit of which a resistor, when moved to the left or right, will toggle an led to light up. So if the arduino reads a voltage from the resistor of lets say 5V(Fully Right), it sets D12 to a HIGH, with the other 11 LEDS off, and if it reads 0 valts(Fully Left), it sets D0 to a HIGH, and so on and so fourth.

I was successful in creating this code, but the problem is that it only uses a very small amount of the potentiometer (10K) and 3 quarters of the potentiometer just leaves all leds off. I have attempted changing the map value to one that is higher, i have also attempted researching and asking a good friend of mine for help, but he suggested that i post it here.

Here is my code-
Code: [Select]
int FDOT = 0;
int FULL = 1;
int F2 = 2;
int F28 = 3;
int F4 = 4;
int F56 = 5;
int F8 = 6;
int F11 = 7;
int F16 = 8;
int F22 = 12;
int CDOT = 10;
int CLEAR = 11;
int potPin = A0;
int potVal;
float voltage;

void setup() {
  pinMode(FDOT, OUTPUT);
  pinMode(FULL, OUTPUT);
  pinMode(F2, OUTPUT);
  pinMode(F28, OUTPUT);
  pinMode(F4, OUTPUT);
  pinMode(F56, OUTPUT);
  pinMode(F8, OUTPUT);
  pinMode(F11, OUTPUT);
  pinMode(F16, OUTPUT);
  pinMode(F22, OUTPUT);
  pinMode(CDOT, OUTPUT);
  pinMode(CLEAR, OUTPUT);
  pinMode(potPin, INPUT);
}

void loop() {
potVal = analogRead(A0);
analogRead(potPin);
potVal = map(potVal, 0, 1023, 0, 0);
voltage = potVal * (5.0 / 1023);


if  (analogRead(potVal) == 0) // FDOT CODE
digitalWrite(FDOT, HIGH);
else
digitalWrite(FDOT, LOW);
if (analogRead(potVal) == 1)
digitalWrite(FDOT, HIGH);
else
digitalWrite(FDOT, LOW);     // FDOT CODE END


if (analogRead(potVal) ==  2)  // FULL CODE
digitalWrite(FULL, HIGH);
else
digitalWrite(FULL, LOW);
if (analogRead(potVal) ==  3)
digitalWrite(FULL, HIGH);
else
digitalWrite(FULL, LOW);    // END OF FULL CODE  



if (analogRead(potVal) ==  4)  // F2 CODE
digitalWrite(F2, HIGH);
else
digitalWrite(F2, LOW);
if (analogRead(potVal) ==  5)
digitalWrite(F2, HIGH);
else
digitalWrite(F2, LOW);    // END OF F2 CODE  



if (analogRead(potVal) ==  6)  // F28 CODE
digitalWrite(F28, HIGH);
else
digitalWrite(F28, LOW);
if (analogRead(potVal) ==  7)
digitalWrite(F28, HIGH);
else
digitalWrite(F28, LOW);    // END OF F28 CODE  



if (analogRead(potVal) ==  8)  // F4 CODE
digitalWrite(F4, HIGH);
else
digitalWrite(F4, LOW);
if (analogRead(potVal) ==  9)
digitalWrite(F4, HIGH);
else
digitalWrite(F4, LOW);    // END OF F4 CODE  



if (analogRead(potVal) ==  10)  // F56 CODE
digitalWrite(F56, HIGH);
else
digitalWrite(F56, LOW);
if (analogRead(potVal) ==  11)
digitalWrite(F56, HIGH);
else
digitalWrite(F56, LOW);    // END OF F56 CODE



if (analogRead(potVal) ==  12)  // F8 CODE
digitalWrite(F8, HIGH);
else
digitalWrite(F8, LOW);
if (analogRead(potVal) ==  13)
digitalWrite(F8, HIGH);
else
digitalWrite(F8, LOW);    // END OF F8 CODE  


if (analogRead(potVal) ==  14)  // F11 CODE
digitalWrite(F11, HIGH);
else
digitalWrite(F11, LOW);
if (analogRead(potVal) ==  15)
digitalWrite(F11, HIGH);
else
digitalWrite(F11, LOW);    // END OF F11 CODE  


if (analogRead(potVal) ==  16)  // F16 CODE
digitalWrite(F16, HIGH);
else
digitalWrite(F16, LOW);
if (analogRead(potVal) ==  17)
digitalWrite(F16, HIGH);
else
digitalWrite(F16, LOW);    // END OF F16 CODE  


if (analogRead(potVal) ==  18)  // F22 CODE
digitalWrite(F22, HIGH);
else
digitalWrite(F22, LOW);
if (analogRead(potVal) ==  19)
digitalWrite(F22, HIGH);
else
digitalWrite(F22, LOW);    // END OF F22 CODE  


if (analogRead(potVal) ==  20)  // CDOT CODE
digitalWrite(CDOT, HIGH);
else
digitalWrite(CDOT, LOW);
if (analogRead(potVal) ==  21)
digitalWrite(CDOT, HIGH);
else
digitalWrite(CDOT, LOW);    // END OF CDOT CODE  


if (analogRead(potVal) ==  22)  // CLEAR CODE
digitalWrite(CLEAR, HIGH);
else
digitalWrite(CLEAR, LOW);
if (analogRead(potVal) ==  23)
digitalWrite(CLEAR, HIGH);
else
digitalWrite(CLEAR, LOW);    // END OF CLEAR CODE
}


And here is a video better explaining what i mean.
https://youtu.be/ugtiyYPssfA
First a full copy of your post, so you can't delete it like you did with the other threads.

Seems you are making the same mistakes as PaulRB pointed out in the first post of your other thread.

1) You're using pin0 and pin1 (can't, because they are the USB<>Serial pins).
The analogue pins can also be used as digital pins, so use A2, A3, etc.

2) map is still wrong
Should be: potVal = map(potVal, 0, 1023, 0, 11); // maps to 12 values

voltage = potVal * (5.0 / 1023); // why this useless line
Work with A/D values, not voltages.

Are you using a 10kB linear pot (not someting like 10kA).
Leo..

Grumpy_Mike

Quote
potVal = map(potVal, 0, 1023, 0, 0);
I am sure this is wrong, you seem to be mapping the value of the pot to values between zero and zero.

You should only read the pot once into a variable and use that variable for all of the iteration of the loop. You are reading it several times in the loop and it will change mid loop. You probably had to do this because your map function destroyed the origional reading.

There is no need to convert anything into a voltage anyway, just use the raw readings for your logic.

Your explanation is poor you talk about a resistor moving, which had me very puzzled until I read the code and then it was a pot that was moving. Also you need to post a schematic ( not a Fritzing physical layout ) so we can make sense of the code.

TIJHE_VV

Hello, thanks for the comment. I have fixed the map values. originally i had them at 11 but i changed it to 0 for a quick test. The code that was 'useless' is for later when i allow the serial USB to show the arduino monitor the voltage, just haven't got to that yet. I am also using a 10K ohm potentiometer. Thanks

Grumpy_Mike

Still waiting for the schematic.

Hint make things simple at first until you get the basic logic going. Add the fancy stuff later not first it only confuses you and others.

TIJHE_VV

Ok i just made a Schematic and should be seen on the forum, sorry if its a little messy, but it was the best i could do as fast as i could. (Please don't worry about the power, if it looks strange thats because the LEDs i am working with require alot of current to work brightly, and are safe with just one resistor for 2)

TIJHE_VV

Thanks for all the help : ) Sorry if i'm a complete newbie, i have only being using arduino for 2 months and am 13 years old

Grumpy_Mike

Thanks for the schematic, I have seen many worse ones, in fact yours is quite good.
Quote
because the LEDs i am working with require a lot of current to work brightly, and are safe with just one resistor for 2
Who ever told you that? It is not true, you need one resistor for each LED. Otherwise the brightness of the LED pair will depend on if the other on is on or not.

What are these LEDs? A part number would be good, or even a colour. My concern is that you have too many for a Nano. These is an overall limit of 200mA on the whole chip, with other limits kicking in for specific ports.

I think the next step is to strip out all the crap from your code and just concentrate on the bit that is giving you the problem. Add in the things you have been told about. Post that code and say what it does and what you want it to do.

Go Up