Huy guys, I just got a package from Hobby King with servo's and they are HEXTRONIC HXT500 5gr minis'.
Iv'e tested them out with the Servo Library and they worked Perfetto! However i bought such little ones (they almost fit on your thumb!) for a special purpose. I want to make a light weight and little insect robot. If i want to build it and make it light then I have no option but remove the Arduino Uno from the project and use it only for prototyping. Instead, the robot's brain will be a Attiny 85.
The Attiny has a problem however, it doesn't support the Servo library for the Arduino. I know that there are Servo libraries for little Attinie's but I prefer to do the code by myself.
I wrote a code to control my servo by pulsing a pulse of between 1ms and 2ms and then a stop period of 19- 18ms (20 - 1 = 19 ms; 20 - 2 = 18 ms). The standard stop period is 20ms, which is 50HZ exactly suitable for the servo's. But the servo just sits still when i upload my sketch to my Arduino Uno.
I have no idea how to alter the PWM signal from 500HZ (default) to 50HZ, so instead i decided to do it with the help of digitalWrite() and delay() functions.
Please suggest me how to create a suitable PWM signal for controlling a servo.
Here is the code:
int servo = 14;
void setup() {
pinMode(servo, OUTPUT); //OUTPUT setup
for ( int i = 0; i > 5; i++){ // Set the possition to 90 degrees
digitalWrite(servo, HIGH);
delayMicroseconds(1500);
digitalWrite(servo, LOW);
}
delay(2000);
}
void loop() {
for ( int i = 0; i > 50; i++){
digitalWrite(servo, HIGH);
delayMicroseconds(1000); // Set the possition to 0 degrees
digitalWrite(servo, LOW);
delay(19);
}
for ( int i = 0; i > 50; i++){
digitalWrite(servo, HIGH);
delayMicroseconds(2000); //Set the possition to 180 degrees
digitalWrite(servo, LOW);
delay(18);
}
}
Thank you guys.