turning lights on with different voltage

I am trying to make some led lights turn on with different voltage. Goal is to have 10 led lights turn on at 1 volt, then 10 more turn on at 1.5 volts then 10 more turn on at 2 volts...ect is there any one out there that has done this or could point me in the right direction? Thanks in advance.

I haven't done exactly that, but it's not too hard...

Each I/O pin can only drive about 1 LED so you'll need a driver circuit. Do you need help with that?

Do you know how to [u]read the analog input[/u]? i.e. With the default 5V reference, 5V reads 1023 on the 10-bit analog-to-digital converter, so 1V reads 204 and 2V reads 409, etc.

Then it's just [u]if-statements[/u] to turn-on the LEDs if the reading is above (greater than) the threshold.

...Maybe start-out with just one LED (maybe the built-in pin 13 LED) and one voltage threshold, and then slowly build-up from there.

P.S.
You can either pre-calculate the raw analog thresholds, or the software can convert to voltage. It's usually best to do whatever makes your code easier (for humans) to understand. The micro processor doesn't mind doing an "extra" calculation and it's only going to take a few microseconds. Either way, your code should probably have some comments explaining (to humans) what it's doing. ...Even if it's for yourself, comments can be helpful if you come back an look at your code a month or a year later.

And... If your voltage is coming from the "outside world" beware that the Arduino can be damaged by negative voltages (including a "reversed" connection) or by voltages greater than +5V. And, you'll need a common ground... The Arduino measures voltage relative to it's ground.

Thanks for the help. I am still new to this so I'm getting my bearings. I will have an outside power source coming into the arduino. One thing I am wondering is do I need to set a threshold for each pin that has a led on it or do I just set one and then make an if statement to run each led? If you have an example code I can look at I would like see that. Also I have read that there is an analog reference for what type of power its getting analogreference() does this need to be put into my code as well?

Once I get the single led working I my need help building a driver for my other leds. In all my goal is to have a total of 170 LEDs light up at different voltage

int led = 1; //led1//
int led2 = 2; //led2//
int led3 = 3; //led3//
int volt = A0; //outside voltage//

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:
volt = analogRead(A0);
if (volt > 204)digitalWrite(led, HIGH); //condition for led1//
if (volt > 409)digitalWrite(led2, HIGH); //condition for led2//
if (volt > 613)digitalWrite(led3, HIGH); //condition for led3//
Serial.println(volt);
}

This is the code I'm running now...its not working for what I need is there something I can do to chang it to work?

One issue I see is that you never switch off the LEDs, and I assume you do want to do this when the voltage drops again.

if (volt > 204) {
  digitalWrite(led, HIGH); // condition for led1.
}
else {
  digitalWrite(led, LOW); // condition for led1 not met.
}

Other than that: please specify how what this code does is different from what you want it to do.

int led = 1; //led1//
int led2 = 2; //led2//
int led3 = 3; //led3//
int volt = A0; //outside voltage//

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(led, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(volt, INPUT);
}

void loop() {
// put your main code here, to run repeatedly:
volt = analogRead(A0);
if (volt > 204)digitalWrite(led, HIGH); //condition for led1//
else digitalWrite(led, LOW);
if (volt > 409)digitalWrite(led2, HIGH); //condition for led2//
else digitalWrite(led2, LOW);
if (volt > 613)digitalWrite(led3, HIGH); //condition for led3//
else digitalWrite(led3, LOW);
Serial.println(volt);

}

Here is my code now. Nothing is working how I need it it.

Pin 1 stays constantly on when I power the uno up. When I apply different voltages to pin A0 nothing changes. I can not get pin one to turn off and pins 2&3 do not turn on.

pin A0 is + voltage from outside source
pin GND is - voltage outside source

pin 1 is led
pin 2 is led2
pin 3 is led3
pin GND is negative side of each led

llomo000:
else (led, LOW);

Missing digitalWrite here?

Move your pins - pin 1 is of the Serial interface - and add some Serial.print() statements to see what your readings really are. That’ll also help a great deal.

Okay, I got it working!!! Thanks for the help. Looking at the serialprint helped out on my values of what the input is!

Having trouble with this code again. I purchased a MEGA2560 board and uploaded the same code to it. The Mega board does not work the same as the uno board. Is there any coding difference in the two boards.

I need more outputs on my board this is why I chose the mega board.

Thanks

This is the code that works on the UNO board but not the MEGA

int led = 2; //led1//
int led2 = 3; //led2//
int led3 = 4;//led3//
int led4 = 5;
int led5 = 6;
int led6 = 7;
int led7 = 8;
int led8 = 9;
int led9 = 10;
int led10 = 11;
int led11 = 12;
int led12 = 13;
int volt = A0; //outside voltage//

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(led, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
pinMode(led6, OUTPUT);
pinMode(led7, OUTPUT);
pinMode(led8, OUTPUT);
pinMode(led9, OUTPUT);
pinMode(led10, OUTPUT);
pinMode(led11, OUTPUT);
pinMode(led12, OUTPUT);
pinMode(volt, INPUT);
}

void loop() {
// put your main code here, to run repeatedly:
volt = analogRead(A0);
if (volt > 150)digitalWrite(led, HIGH); //condition for led1//
else digitalWrite(led, LOW);
if (volt > 175)digitalWrite(led2, HIGH); //condition for led2//
else digitalWrite(led2, LOW);
if (volt > 200)digitalWrite(led3, HIGH); //condition for led3//
else digitalWrite(led3, LOW);
if (volt > 225)digitalWrite(led4, HIGH);
else digitalWrite(led4, LOW);
if (volt > 250)digitalWrite(led5, HIGH);
else digitalWrite(led5, LOW);
if (volt > 275)digitalWrite(led6, HIGH);
else digitalWrite(led6, LOW);
if (volt > 300)digitalWrite(led7, HIGH);
else digitalWrite(led7, LOW);
if (volt > 325)digitalWrite(led8, HIGH);
else digitalWrite(led8, LOW);
if (volt > 350)digitalWrite(led9, HIGH);
else digitalWrite(led9, LOW);
if (volt > 375)digitalWrite(led10, HIGH);
else digitalWrite(led10, LOW);
if (volt > 400)digitalWrite(led11, HIGH);
else digitalWrite(led11, LOW);
if (volt > 425)digitalWrite(led12, HIGH);
else digitalWrite(led12, LOW);
Serial.println(volt);

}

There should be no code difference to speak of (at least not for this level of code), but there are differences in pin numbers: some numbers that exist on the Uno don't on the Mega and the other way around. Make sure your pin numbers are correct.

And another thing: do look into the concept of arrays. The moment you use numbers in variable names, that's a sign you really need arrays. It's not hard, and can make your code much simpler and more maintainable.

As far as pin placement goes I think it is working in that aspect. What is happening, With the UNO my volt raises and lowers depending on how much power is givin to the board on pin A0. With the MEGA the volts raise but never lower