Scale-N

Scale-N
Arduino
Componenten
Rollend Materieel
Naslag
Onderdelen
Wissels
Basis Electronica
Symbols Electronica
Programming Arduino
AKS
DCC++
DR5000













































Simple servo code
Breadboard
Arduino
Capacitor
Your servo may behave erratically, and you may find that this only happens when the Arduino is plugged into certain USB ports. This is because the servo draws quite a lot of power, especially as the motor is starting up, and this sudden high demand can be enough to drop the voltage on the Arduino board, so that it resets itself.
If this happens, then you can usually cure it by adding a high value capacitor (470uF or greater) between GND and 5V on the breadboard.
Servo

Pin layout:

Rood 5v
Zwart Gnd
Geel 9 (PWM)

Code
#include <Servo.h>

int servoPin=9;
Servo servo;
int angle=0;

void setup()
{
  servo.attach(servoPin);
}

void loop()
{
  for(angle=0; angle<180; angle++)
  {
    servo.write(angle);
    delay(30);
  }

  for(angle=180; angle>0; angle--)
  {
    servo.write(angle);
    delay(30);
  }
}