School Project

me and my friend here have a school project where we are going to use 8 LED diods which is controlled by the Soft Potentiometer. the kit we have to use is the arduino starterkit.

The soft potentiometer should be working like when you touch the bottom of the SP, the led in the end should start to show some light, and when you stroke your finger across the SP the light should follow, but only 1 led diod whould be shining at the time.

Me and my friend are stuck on the part where we need to wire all the 8 leds up and get them in the right order with only 3 pins on the SP.

Could anyone help us out or bring some tips please? :)

I take it you are using arduino...

You could use if() statements and set a range that one of the LEDs turn on. Then repeat this for the rest. It is not the most efficient way of doing it, but it is quite simple. Then all you have to do is connect the LEDs to digital pins and the middle of the soft pot to an analog pin and the other two to +5v and Ground.

I hope this helps, if you need more explaining tell me! :D

Sreeteja

thanks for quick answer, my mate will post our idea on how we were thinking about it, we havent got the kit just here now, but do you have any good simulator programs to recommend

I tried to use this program:

const int ledpin_1 = 3; const int ledpin_2 = 4; const int ledpin_3 = 5; const int ledpin_4 = 6; const int ledpin_5 = 7; const int ledpin_6 = 8; const int ledpin_7 = 9; const int ledpin_8 = 10;

const int sensorpin = 0;

void setup () {}

void loop() {

analogWrite(ledpin_1, 30); analogWrite(ledpin_2, 60); analogWrite(ledpin_3, 90); analogWrite(ledpin_4, 120); analogWrite(ledpin_5, 150); analogWrite(ledpin_6, 180); analogWrite(ledpin_7, 210); analogWrite(ledpin_8, 240);

}

Part of your problem there is that not all the pins you’ve used are capable of PWM output (unless you’ve got a Mega).
Have a look at the reference page for analogWrite.

Please use code tags - it’s no big deal in this case, but it is a good habit to get into.

Do yourself a favor and start with plain 10k potentiometer. This SP may be little touchy and break easy, but I am just guessing. Check how LED contrast or backlight is wired for LCD LED sample. Wire ONE LED and learn how to control it using analog input and analog output. Use Blink program and Serial as a troubleshooting tool. And do not forget limiting resistor for your LED . Keep all LED's on consecutive pins - limiting resitostors still come in DIP / SIP packages and then they are easier to wire, but that is later. Keep the group posted. PS your loop wont show you anything useful - too fast. Cheers Vaclav

So much information to get, thanks for all the replies!
Can some of you help me out with this, i mean give me some kind of example of how to write this program? :smiley:

Vaclav: PS your loop wont show you anything useful - too fast. Cheers Vaclav

Nonsense - it will be static display.

I have made some mock up code for your project. I hope it gets the idea across. Basically what happens is that the arduino reads the incoming voltage from the soft pot and uses an A/D that creates a number from 0-1023. The arduino then uses that value and the if and else if statements to get the correct LED to light up. I have set the value for each LED to turn on at 1/8th of 1023. That means there is an equal separation between the an LED to turn on. I have not done it all because that is your job ;) . I hope this helps. I am always on hand to provide help.

P.S I am not the best coder out there. This may not be the most efficient way to do this. A switch statement may work. Hopefully a really good coder will come along and give you a small efficient piece of code...

const int ledpin_1 = 3;
const int ledpin_2 = 4;
const int ledpin_3 = 5;
const int ledpin_4 = 6;
const int ledpin_5 = 7;
const int ledpin_6 = 8;
const int ledpin_7 = 9;
const int ledpin_8 = 10;

int sensorVal;

void setup()
{
  pinMode(ledpin_1, OUTPUT);
  //Rest of the LED pins set as output here
}

void loop()
{
  sensorVal = analogRead(A0);
  if(sensorVal = 128)          // 1/8 of 1023
  {
    digitalWrite(ledpin_1, HIGH);
    digitalWrite(ledpin_2, LOW);
    digitalWrite(ledpin_3, LOW);
    digitalWrite(ledpin_4, LOW);
    digitalWrite(ledpin_5, LOW);
    digitalWrite(ledpin_6, LOW);
    digitalWrite(ledpin_7, LOW);
    digitalWrite(ledpin_8, LOW);
  }
  else if(sensorVal = 256)    // 2/8 of 1023
  {
    digitalWrite(ledpin_1, LOW);
    digitalWrite(ledpin_2, HIGH);
    digitalWrite(ledpin_3, LOW);
    digitalWrite(ledpin_4, LOW);
    digitalWrite(ledpin_5, LOW);
    digitalWrite(ledpin_6, LOW);
    digitalWrite(ledpin_7, LOW);
    digitalWrite(ledpin_8, LOW);
  }
  else if(sensorVal = 384)       // You get the idea!!! ;)
  {
                                 // Put the correct pin HIGH
  }
}

Sreeteja

if(sensorVal = 128)

It's a comparison, use ==

Edit:Actually, you don't want equality either - you want a range.

Oh yeah, sorry... Hahaha. Just proves that I am no expert... Again, Sorry.

AMAZING! Thank you guys!

When you say range; what range?

Edit: Can i get an example? :D

Range:

if ((x >= 128) && (x < 256))

Okay, so you use range 128->256. Can i ask; is this ledpin1 or ledpin2? :blush:

Okay, so you use range 128->256. Can i ask; is this ledpin1 or ledpin2?

It's not any ledpin, it was an example.

thanks for all the help me and my friend have got so far, but we are stuck on the wiring part. We couldnt take our arduino KIT with us back home from school (living in Norway, for u US people that might get confused :P ) but could any1 post an idea to a circuit that would work to the program further up in my topic? im gonna post an example on how our plans are. thanks :)

http://i.imgur.com/5CkX95d.png

so this is my thought about the circuit. all i need is to add the other 7 leds and resistors but i hope you might know how im thinking with this.

Could this work or is this like a wild shot in the dark?

I think you have a connected the other end of the resistor to 5v by accident. This would mean you have to put the digitalWrite state as HIGH to keep the LED off…
Here is a circuit I made on Fritzing. It doesn’t have a soft pot so just think that the slider is an soft pot!!! :smiley:

Sreeteja

ok so the final thing to do is to take a wire from the center on the Soft Potentiometer to analog 0? and just thread the 10K resistant over the 5v and gnd on the SP? the SP we are using looks just like the one i drew, just abit shortened :)

Eyah, the soft pot is the same as any other potentiometer when it come to wiring. The middle pin is the 'signal' that you connect to ground. The outer two are connect to ground or 5v it doesn't matter which is connected to which.

Sreeteja