Author Topic: lighting an LED instead of moving a servo  (Read 2419 times)

0 Members and 1 Guest are viewing this topic.

Offline ArmouralisTopic starter

  • Jr. Member
  • **
  • Posts: 13
  • Helpful? 0
lighting an LED instead of moving a servo
« on: March 24, 2009, 07:53:27 PM »
i have build the $50 robot, and I have built the $50 robot with the sharp ir sensor.

i would like to modify the circuit, so that a buzzer or an led is attached to the output, not a servo.  I want to build a sort of alarm, where is an object goes within lets say 20 cm of the ir sensor, a buzzer will go off with an led.

how can i do this?  If i plug in an led with a 220 ohm resistor into the out part (left side of the $50 circuit) the led goes on, no matter what i put in the code, the led just lights up, the same with the buzzer it just goes off

i tried putting the code
   servo_left(35);
   servo_right(35);

then
   servo_left(0);
   servo_right(0);
then
   servo_left(80);
   servo_right(80);

in all the cases the led just lights up.  I was thinking that i would have to use an electronic speed controller to power the led or the buzzer, to turn the PWM signal to a voltage.  Is there any ohter way to do this?  I do not want to spend $50 on an ESC, if there is an easier way!  thx in advance

Offline Jdog

  • Robot Overlord
  • ****
  • Posts: 259
  • Helpful? 3
Re: lighting an LED instead of moving a servo
« Reply #1 on: March 26, 2009, 01:52:13 PM »
There is a much much easier way. You do not want to use servo code for this, because that makes pwm. You just want to turn the port on or off. Find out what port you want to plug the LED into, and then instead of where you had
Code: [Select]
servo_left=35;write
Code: [Select]
PORT_OFF(PORTD, 4)This is an example if you wanted to use port D4. I think you can figure out how to change the ports. If you want to turn it off, then type
Code: [Select]
PORT_ON(PORTD, 4)
To plug in the led to the port you'd want to put the + end(the shorter lead) to a resistor, to the output pin on the board(the pin closest to the processor, and the negative one to ground(the one on the edge of the board). If you want to use a buzzer, I recommend using this one from radio shack http://www.radioshack.com/product/index.jsp?productId=2062398. It only draws 5 ma and I think the atmega8 can output 50 ma so you need to throw a resistor in between the ouput pin and the buzzer.

 


Get Your Ad Here