# help with beginner arduino project

Objective: Develop a program to perform the following tasks:

• Measure a variable DC voltage ranging from 0 to 9 volts.
• The input voltage to the microprocessor cannot go above 3 VDC.
• The DC voltage will be displayed in 1 volt increments on the 9 LEDs.

im assuming im gonna need a lot off if statements but its asking for leds to be displayed every 1 volte but 3 volt is the limit..

Id appreciate some advice on where to start or go about doing this

Divide the measured voltage by 3 using a voltage divider.
A ladder of 9 “if’s” sounds like possible to run well.

``````inVolt = 3 * analogRead(inVoltPin);//compensate for divider

if(inVolt <1023/9) digitalWrite(ledPin1, HIGH);
else if(inVolt <2*1023/9) digitalWrite(ledPin2, HIGH);
else if(inVolt <3*1023/9) digitalWrite(ledPin3, HIGH);
.
else if(inVolt <8*1023/9) digitalWrite(ledPin8, HIGH);
else digitalWrite(ledPin9, HIGH);
.
``````

the code you gave me wouldthat be a good code to replicate 9 times and change according to pin/action?

I think so but You need to make declarations, define the input pin and output pins in Setup(). That snippet of code belongs to loop().

A more elegant solution might be to put the pin numbers of the LEDs in an array and light the first n of them in a for loop, where n is the measured voltage.

wildbill:
A more elegant solution might be to put the pin numbers of the LEDs in an array and light the first n of them in a for loop, where n is the measured voltage.

So how do i set up pins 2-10 as an array to give "power" to certain LEDs when voltage is read from either 9v battery or a Dc voltage regulator (variable one)

Actually, if you plan to use sequential pins, you won't even need the array, just a for loop than runs from 2 to 10 and a little math.

so what use 3 Leds per pin? and base the power of LED on the amount of voltage given ?
or just all pins ?
int LED1 2;
int LED2 3;
int LED3 4;
int LED4 5;
int LED5 6;
int LED6 7;
int LED7 8;
int LED8 9;

and set in motion each one to power at a certain voltage?

You can use a switch-case to operate the LEDs as shown here

Beginners: using the switch - case statement

Hi,
What model controller are you using?

Thanks.. Tom...