Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

Moving servo to 50 degree
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Moving servo to 50 degree

by prayag2010 on Thu Oct 27, 2011 12:27 pm

I am building a project for my car in which a character LCD (http://www.adafruit.com/products/181) will display the current temperature of the car using LM35 temp. sensor and we can set the current temperature and a servo will control the speed of the AC in the car (using an arduino) but for that, I need to get the servo to 50 degrees and I seem to have a problem in that. The servo is not moving a bit. I tried using 2 different servos (HXT900 and Futaba S3003) but to no avail. Here is the code that I tried to move the servo to 50 degree :-

#include <Servo.h>

Servo myservo; // create servo object to control a servo


void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object

}

void loop()
{
int i = map(i, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
i = i+50; // moves the servo to 50 degree
myservo.write(i); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
}




I haven't bought the LCD yet but I plan to set the same or a similar one soon.
It will be a great help if you will help a newbie like me....
prayag2010
 
Posts: 22
Joined: Thu Apr 29, 2010 8:44 am

Re: Moving servo to 50 degree

by adafruit_support_bill on Thu Oct 27, 2011 1:01 pm

'i' is never initialized before you call 'map'. Assuming it is initialized by default to zero (although assuming is seldom wise), the result of the map call will always be zero.

adafruit_support_bill
 
Posts: 79109
Joined: Sat Feb 07, 2009 10:11 am

Re: Moving servo to 50 degree

by prayag2010 on Thu Oct 27, 2011 1:49 pm

So how should I write the code ? I can't seem to get it since I am a newbie......
prayag2010
 
Posts: 22
Joined: Thu Apr 29, 2010 8:44 am

Re: Moving servo to 50 degree

by adafruit_support_bill on Thu Oct 27, 2011 2:05 pm

To move the servo to 50 degrees is simply:

myservo.write(50);

If you want it to be proportional to the temperature, you need to read your temperature sensor first. See this tutorial:http://www.ladyada.net/learn/sensors/tmp36.html

adafruit_support_bill
 
Posts: 79109
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.