🛠 Piloter un micro-servo avec la PWM du GIGA R1
Objectives
Master PWM (Pulse Width Modulation) output to control an angle micro-servo. You will learn how to use the Arduino core Servo library, correctly power an external load, and respect the 3.3 V logic of the GIGA R1 (76 GPIO pins available on the board).
Hardware
- 1 Arduino GIGA R1 WiFi board
- 1 SG90-type micro-servo
- 1 dedicated external 5 V power supply (batteries or regulator) — do not power the servo from the board
- Jumper wires, USB-C cable
Complete code
// GIGA R1 WiFi — balayage de micro-servo avec la bibliotheque Servo
#include <Arduino.h>
#include <Servo.h>
const int BROCHE_SERVO = D9; // broche PWM de la sérigraphie
Servo monServo;
int angle = 0;
int sens = 1;
void setup {
Serial.begin(115200);
monServo.attach(BROCHE_SERVO); // attache la broche au signal servo
monServo.write(0);
}
void loop {
angle += sens * 5; // balle 0 -> 180 -> 0
if (angle >= 180) sens = -1;
if (angle <= 0) sens = 1;
monServo.write(angle);
Serial.printf("angle = %d\n", angle);
delay(30);
}
Wiring: orange wire (signal) to D9, red wire to external +5 V, brown wire to external GND, and external GND connected to a board GND (common ground is mandatory).
Expected verification
The servo sweeps back and forth regularly from 0° to 180°. The Serial Monitor (115200 baud) displays the current angle. The movement is smooth, without jitter or saturation whining.
Common errors
- Powering the servo from the board's 5 V pin: voltage drops, restarts, or even damage to the regulator; the GIGA accepts 6–24 V on VIN, but the servo must have its own power source.
- Forgetting the common ground between the external power supply and the board: the servo vibrates or does not respond.
- Non-PWM compatible pin: not all pins generate PWM; the exact number of PWM pins on the Arduino side is not published in the retrieved pages.
- 3.3 V / 5 V confusion: the control signal is accepted by the servo, but never feed 5 V back to the pin.
Other tutorials for this board
- Faire clignoter la LED de l'Arduino GIGA R1
- Bouton poussoir et console série sur le GIGA R1
- Potentiomètre et sortie DAC sur la prise audio du GIGA R1
- Connecter un capteur I2C sur le GIGA R1
- Publier des données en MQTT/HTTP via le Wi-Fi du GIGA R1
- Programmer les deux cœurs M7 et M4 du GIGA R1 et les faire communiquer
Code examples for this board
clignotante.inoArduinobouton.inoArduinorespiration.inoArduinoanalogique.inoArduinodac-onde.inoArduinooled-i2c.inoArduino