Servo sweep sketch not working

Hi,

My son is trying to work with the servo littlebit (011 servo) and we tried running the example in aruduino. We modified it in order to make it go faster and nothing happened. We cannot figure out what the problem is and we’re in a science fair time crunch!

When we attached the servo directly to the power without the arduino board, the servo operates fine (and can be sped up or slowed down with an i6 dimmer).

I’m attaching the sketch (taken directly from the example with changed numbers)

#include <Servo.h>

Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0; // variable to store the servo position

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

void loop() {
for (pos = 0; pos <= 180; pos += 50) { // goes from 0 degrees to 180 degrees
// in steps of 5 degrees
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(1000); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 50) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(1000); // waits 15ms for the servo to reach the position
}
}

The littleBits servo has a microcontroller inside as part of its circuit, which is probably why you’re not getting the type of results you expect from “myservo”.

Try using analog write or digital write statements instead.

@JackANDJude So you’re saying the arduino built-in sketch that they have as an example won’t work at all, right?

I’ll let my son know and hopefully he can work this out!

Sorry, I don’t know what sketch you are referring. Was it built in with the littleBits Arduino or in the Arduino IDE? In any case, here is a project that works (I tested it a moment ago). Give it a try, and hopefully it will give you and your son some insight. :sunglasses:

1 Like

@JackANDJude Thanks again!

Yes, it was an “example” sketch built in to the arduino IDE.

If you are using the littleBits servo, then you do not need to use the Servo library. The bit takes an analog input and activates the servo motor based on the value of the input, and the position of the switch on the servo bit.

You can use nothing more than a power, dimmer and servo bit to run ‘sweep’ and change the speed of the motion. If you want to use an arduino bit to control the speed of the sweep action, then just use analogWrite(9, speedValue); where speedValue is a variable that contains a number from 0 to 255, meaning still to the fastest ‘sweep’ the bit can manage.

This is because the servo bit has an ATTiny45 microcontroller chip that runs the code to control the servo motor. The bit needs only an analog voltage for input.

This is old, but I just want to say that changing the number inside the delay from 15 to 1000 will make it slower. That number is adjusting how many milliseconds it will wait for to change the servo’s data.