LED, Potentiometer, AVR = Dimming leds

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hey all,

Its been a few months since I was here the last time and tried to learn avr..

Since then I've had a lot to do and havent had the time to focus on the development on my non existing skills ;)

Anyway, I've played around with some code on my STK500 together with the microprocessor Atmega32 that I bought at the same time as the STK500..

so that's what I have to play with at the moment..

My thought now is to connect a potentiometer, that I've somehow figured out that it should be possible to connect directly to the atmega32 and then with code read the value of this and then send out a pwm signal to a led, controlling the brightness of it..

I've tried searching this forum for potentiometer, dim leds and stuff like that but I havent found anything that gives me the slightest idea of how to connect it all together. I've even tried Google and found lots of fun stuff, but nowhere near any information on schematics or similar..

I know however how a potentiometer works as I've used several for normal HD4470 or what the name of the LCD displays is that is often used for connecting to the LPT port of a computer, and also with other projects so I have basic knowledge of how an potentiometer works..

I also know that much, that port A is the analog to digital pins on the Atmega32, right? So on these I should connect a potentiometer and then leds, am I right? not on the same pin of course, but I mean on port A ;)

am I on the right track so far?

if so, I'm then looking for some code snippets that can read from the pin on which I connect the pot.. How is this actually read?

What do I get into the uC from the pot? is it like 0 at all left, and then 255 to the far right? hypothetically, or how its spelled ;)

I must say, I'm not after that someone else write it all for me, but I just dont know what to search for or how to find the information I need as I think I've searched for pretty much all the combinations possible, maybe someone could point me to a few words I can search for perhaps?

I've figured out how to lit a led when pressing a button, so I've come that far, is it something similar with a pot?

hope you wont despise me for my questions, but truly I'm just a hobbyist trying to learn and I believe I've come to the right place with lots of pros, right? ;)

// Chris

edit: the joindate is way wrong, its more like jan 2008.. but ok ;)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You are correct on the use of the pot. 1 outer leg to ground, the other outer leg to +5 and the center to one of the porta pins. If you want to feel a bit safer put a 1K reistor in series with the center of the pot and the avr pin in case you accidentally turn it on as output while you try things out.

The led should be connected to one of the pins that can do PWM via a resistor, 470R or 330R should be ok for a red led.

Then it is just a case of reading the pot, say every 100ms, and put the read value into the counter register of the timer you are using for pwm.

If you use one of the 8 bits counter remember to set up the ADC reading so that it gives you the the 8 bits rather than 10 bits reading.

...Start coding..

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thanks, with such a short reply you explained what feels like my whole life or something.. my "problem" felt like that, but with the info you gave me it feels like a huge weight was lifted off my shoulders =D

I thank you for that!

however, I'm going to use the STK500 board in the beginning, do you recon I need resistors anyway for the led as I'm going to use the ones on the board..

havent read the sheet but there seems to be, without any magnification glasses, some resistors around the leds, that should be enough right?

other than that, now I know in which direction I should go =D

Thanks js!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The leds of the STK500 do not need extra resistors. Just remember that they turn on with a 0 on the pin rather than a 1.

I would still put a resistor in series with the centre on the pot, especcially with the STK500 as they are a bit more expensive than just a dead chip. :)

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

haha yeah they sure are more expensive and I will surely use a resistor on the pot, I wasnt planning to go without it but thanks for reminding :D