go_away

Author Topic: LED wont work  (Read 2552 times)

0 Members and 1 Guest are viewing this topic.

Offline bakilTopic starter

  • Jr. Member
  • **
  • Posts: 20
  • Helpful? 0
LED wont work
« on: June 27, 2007, 03:33:09 AM »
ok wait i modify the topic so its clear

btw i use a 4.5 volt power suply



i have made a program that lets the led go on with portc (worked on STK500 board)

Offline Eco19R

  • Full Member
  • ***
  • Posts: 104
  • Helpful? 0
Re: LED wont work
« Reply #1 on: June 27, 2007, 04:09:15 AM »
you need a steady 5 volts first thing.....

Offline bakilTopic starter

  • Jr. Member
  • **
  • Posts: 20
  • Helpful? 0
Re: LED wont work
« Reply #2 on: June 27, 2007, 04:18:16 AM »
i dont have the materials to do it and the guy of the store where i buy it said that as long as i dont get under 3v u should see it light a little (and believe me it was dark when i tested it) and the atmega16l works with 4.5V (it says in the datasheet)

Offline ed1380

  • Supreme Robot
  • *****
  • Posts: 1,478
  • Helpful? 3
Re: LED wont work
« Reply #3 on: June 27, 2007, 06:28:04 AM »
first make sure the mcu is ok.
did you take it our to program it?

you'll need to set the pin high to get it to work
did you do the polarity of the switch right?
Problems making the $50 robot circuit board?
click here. http://www.societyofrobots.com/robotforum/index.php?topic=3292.msg25198#msg25198

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,663
  • Helpful? 169
    • Society of Robots
Re: LED wont work
« Reply #4 on: June 27, 2007, 06:40:12 AM »
What is your resistor value? Is your LED hooked up in the correct direction? The LED works when outside of your circuit, right? Are you sure the port is going high?

You can also connect the ground of your LED to the port, and the resistor end to the 5V supply. By bringing the port low the LED will turn on. The microcontroller wont need to supply the LED power using this setup.

Offline bakilTopic starter

  • Jr. Member
  • **
  • Posts: 20
  • Helpful? 0
Re: LED wont work
« Reply #5 on: June 27, 2007, 09:28:48 AM »
resistor for the led is 330 ohm (guy from store said i needed to use it for the led

btw i can calculate it myself but i dont know what voltage to give to an LED)

Code: [Select]
#include <avr/io.h>    // header file

int main(void)
{
PORTC = 0;
DDRC = 255;

return 1;
}


and LED works outside of the circuit
and port should go hy with this code (i tested it with the stk500 board and it worked)

Offline rgcustodio

  • Robot Overlord
  • ****
  • Posts: 217
  • Helpful? 0
  • Use "Search" and ye might find answers!
Re: LED wont work
« Reply #6 on: June 27, 2007, 11:40:51 AM »
I think you didn't read enough of the data sheet.

Start on page 50 of the data sheet. Now on page 51, you will see a section entitled "Configuring the Pin". Then read Table 20 Port Pin Configurations.

Your code is correctly setting PC0 to output BUT as a sink. Your schematic does not match this. If you are using a sink your LED should be connected appropriately to Vcc and not to GND.

Or you can change your code to something like:
(Verify the names, I didn't compile check them.)
Code: [Select]
#include <avr/io.h>

int main(void)
{
  /* set only one bit, set to 1 direction output, read Page 51 2nd paragraph */
  DDRC = (1 << PC0);

  /* set only one bit, set to 1 to drive it high, read Page 51 3rd & 4th paragraph, refer to page 52 Table 20 */
  PORTC = (1 << PC0);

  /* embedded apps do not return */
  do
  {
  }
  while (1);

}

So you have two options change your wiring (and use your original code) or change you code (with no changes to your wiring).
« Last Edit: June 27, 2007, 11:47:16 AM by rgcustodio »
The best thing one can do when it's raining is to let it rain. - H. W. Longfellow

understanding is the path to enlightenment

Offline bakilTopic starter

  • Jr. Member
  • **
  • Posts: 20
  • Helpful? 0
Re: LED wont work
« Reply #7 on: June 27, 2007, 12:16:13 PM »
ok thks all (mostly rgcustodio  ;)) it works now

NOW LETS GO ON TO THE NEXT STAGE -> 2 LEDS  :D

Offline pomprocker

  • Supreme Robot
  • *****
  • Posts: 1,430
  • Helpful? 16
  • Sorry miss, I was giving myself an oil-job.
Re: LED wont work
« Reply #8 on: March 10, 2008, 01:46:18 PM »
You can also connect the ground of your LED to the port, and the resistor end to the 5V supply. By bringing the port low the LED will turn on. The microcontroller wont need to supply the LED power using this setup.


What does admin mean by bringing the port low?

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,663
  • Helpful? 169
    • Society of Robots
Re: LED wont work
« Reply #9 on: March 10, 2008, 01:51:14 PM »
Quote
What does admin mean by bringing the port low?
A digital port is either high (a 1, or 5V) or low (a 0, or 0V).

To control the LED in software, just look at my source code. Its explained in the comments.

 


Get Your Ad Here