DAC project questions

I've recently been studying up on AD and DA conversion. I am wondering if there is a good method in arduino for taking an analog value obtained via analogRead(), and using that value to trigger, and not trigger, the appropriate pins/groups of pins to represent the value in binary.
i.e.
I have the output of a potentiometer running to an analog pin. I would like to build a small circuit with 10 LEDs representing the 10 bits, such that when the potentiometer is grounded none of the LEDs light up, but when it's shorted they all light up. (10 LEDs switched on when a value of 1023 is read, first LED only when a value of 512 is read, so on and so forth)

I'm new to all things circuit related, but feel like this would be a cool project.

The only way I personally know how to do it would be to use lots of if statements (at least 1,023 of them)

Thanks in advance!

You could use the bitRead function.

Maybe I've misunderstood something.

Use the bitRead() function on your variable to determine if a given bit is set or not.

unsigned int val = analogRead(A0);
for(int i=0; i < 10; ++i ) {
  if ( bitRead( val, i ) == 1 ) {
    // bit is set, turn on led
  }
  else {
    // bit is not set turn off led
  }
}

You could also use a shift register...

Grounded? Shorted? Whaaa? What does your circuit look like?

Believe it or not, we've seen things like that on this board...

10 LED's 10% of the analog value per led.

Analog value 0 to 5. Analog values are from 0 to 1024. (Uno) An analog value of 0 = all LED's off. an Analog value of 1024 = all LED's on.

1024/10=102

An analog value >102 and <=204 would be turn on LED1

An analog value >204 and <= 306 turn 2 LED on and so on and so forth.

0 to 1023

Hi, @hunterwayne95
Welcome to the forum.

If you Google;

arduino led level indicator

You will see many tutorials/projects on what you are looking for.

Tom.... :smiley: :+1: :coffee: :australia:

Am I missing something?
I'd suggest an interesting way is to write to the PORTB and PORTD registers.
However to avoid changing pins 0 and 1 you would need to shift the value read in 2 places, and mask it;
then write to PORTD;
then for the upper bits you would need to shift and mask again to write to the PORTB register .
https://www.arduino.cc/en/Reference/PortManipulation

Just trying to save myself some typing. Probably using bad vernacular. One outer terminal of the pot is going to ground, the other outer terminal to 5v, the middle to the analog input. I was just using “grounded” and “shorted” to represent a “wide open” or “closed” pot I guess??

Sure, NP. Did you get what you needed from us?

I don’t simply want to have half the LEDs on at half the voltage. I want the LEDS to represent the binary bits, at a voltage of 682, I want the LEDs to be as follows: 1010101010

Thanks everyone for the responses. I wanted to clarify something. I’m not wanting to build a simple level indicator. What I’m looking for is a way to convert the read analog values back to binary, with the LEDs representing the 10 bits. At a reading of 682 I don’t just want the first half of the LEDs on. I want the LEDs to be High/low as follows: 1010101010

Everyone here understood that, we're professionals. The advice that was given, would do exactly that. Is there any part of it, that you need further help with?

The misunderstanding arose from this statement, since a binary counter and a bar graph both share the same endpoint states.

However, there are several responses that tell you how to produce a binary display. So in that sense, what you're looking for, has already been found.

Have you tried
int iBits = 682;
Serialprintln( iBits,BIN);? What do you get? Then send each bit to the proper LED's.

see post #9

I’m not doubting anyone here’s capabilities, but I don’t believe everyone here understood that. At least two people have responded with instructions on building a simple voltage indicator. 1023/10 has very little significance in the project I’m actually trying to create. Whether I’m at 20% or 60% of the voltage has very little significance in the project I actually want to build.

If someone gives you ice cream, and a decomposing rodent, do you throw both away, or just one? You can simply ignore responses that aren't relevant to your problem, and use the ones that are. Believe me, there are some that are. I think the lack of understanding is at your end.

I did not understand from your original description you wanted to represent LEDS as binary thingies.

Dir post9 help you out?

I’m obviously in way over my head lol. I’ll give all your suggestions and the others a try and do some more studying. Thanks very much!