servo-balayage.ino
The Servo library of the UNO R4 core drives standard servos (1-2 ms pulse at 50 Hz) without the AVR timer conflicts. A full 0-180° sweep serves as a test bench before mounting it in a mechanism.
Hardware
An Arduino UNO R4 WiFi (Renesas RA4M1 @ 14 MHz + companion ESP32-S3 Wi-Fi/BLE, 12x8 LED matrix, RGB LED) powered by USB or 6-24 V. 1 hobby servo (SG90/MG90S); external 5 V supply for bigger models.
Wiring
Signal (orange) to D9, + (red) to 5 V, - (brown) to common GND.
How it works
myservo.write(angle) sends the position pulse; the loop increments the angle by 1° every 20 ms and reverses at the stops.
Running it
Arduino IDE 2.x with the « Arduino UNO R4 Boards » core, « Arduino UNO R4 WiFi » board, serial port then Upload. The ESP32-S3 coprocessor updates separately if the IDE asks.
Variants
Add a potentiometer on A1 for angle following, or show the angle on the LED matrix (R4 WiFi).
servo-balayage.ino
// Balayage servo avec la bibliotheque Servo (portage RA4M1).
#include <Servo.h>
Servo myservo;
int angle = 0, sens = 1;
void setup() {
myservo.attach(9);
myservo.write(0);
Serial.begin(9600);
}
void loop() {
myservo.write(angle);
static unsigned long t0 = 0;
if (millis() - t0 < 20) return;
t0 = millis();
angle += sens;
if (angle >= 180) sens = -1;
if (angle <= 0) sens = 1;
}
// Sur R4, la lib Servo utilise les timers du RA4M1 sans
// entrer en conflit avec analogWrite() comme sur les AVR.
// Alimentation externe conseillee au-dela du micro-servo.