servo-balayage.ino

LilyPad Arduino · File : servo-balayage.ino · Language : Arduino · Use case : Faire balayer un servo-moteur de 0 à 180 degrés

The Servo library generates the control pulse (1-2 ms) and sweeps the angle end to end. Feeding a mid-size servo from a dedicated 5 V rail avoids brown-out resets from current spikes.

Hardware required

A LilyPad Arduino (ATmega168V/328V, 8 MHz, 3.3 V) with its sew tabs, programmed via an FTDI cable (breakout) and powered by 3.7 V (LiPo) or 5 V on V-REG. 1 standard servo (SG90/MG90S) + recommended external 5 V supply.

Wiring

Orange (signal) to pin 3, red to +5 V, brown to GND (common ground with the board).

How it works

myservo.write(angle) sends a pulse whose width maps the angle; 5° steps every 50 ms give smooth motion. In the Arduino IDE, select « LilyPad Arduino » and the FTDI port, then Upload. Conductive thread adds a few ohms of resistance: keep runs short and insulate crossings.

Going further

Add a potentiometer on A0 for a position → servo feedback loop (robot radar).

servo-balayage.ino

// Balayage servo 0..180 degres avec la bibliotheque Servo.
#include <Servo.h>

Servo myservo;
int angle = 0;
int sens = 1;

void setup() {
  myservo.attach(3); // broche avec pin signal du servo
  Serial.begin(9600);
}

void loop() {
  myservo.write(angle);
  angle += sens * 5;
  if (angle >= 180 || angle <= 0) sens = -sens;
  delay(50);
}

← Back to the board