Commandé avant 14h00 un jour ouvrable = expédié le jour même 30 jours de délai de rétractation Garantie d’un an
← Retour à l’aperçu

La lecture charge la vidéo depuis YouTube.

Schéma de câblage et exemple de code

Voici comment connecter le Servo SG90 micro 180 degrés à un Arduino UNO ou à un ESP32, avec un exemple de sketch que tu peux téléverser directement.

Démo de balayage du micro servo SG90

Ce projet montre comment contrôler un micro servo SG90 avec un Arduino Uno. Le sketch fait balayer le bras du servo en douceur d'avant en arrière de 0 à 180 degrés. Ouvrez le Moniteur Série à 115200 baud pour observer l'angle actuel du servo.

Schéma de câblage : Servo SG90 micro 180 degrés sur un Arduino UNO
Schéma de câblage · Cliquez pour agrandir
Tableau de câblage : Servo SG90 micro 180 degrés sur un Arduino UNO
Tableau de câblage · Cliquez pour agrandir
SG90_Micro_Servo_Sweep_Demo.ino · compilé et testé
/*
 * ==================================================================
 *  Generated by Codey.online  —  https://www.codey.online
 * ==================================================================
 *  Project   : SG90 Micro Servo Sweep Demo
 *  Board     : Arduino UNO (arduino:avr:uno)
 *  Parts     : Servo SG90
 *  Libraries : none (built-in)
 *
 *  Codey Online is an AI-powered browser IDE for Arduino and ESP32.
 *  Describe your project and Codey writes the code, draws the wiring
 *  diagram and uploads it to your board, straight from the browser.
 *  This code is free to use, modify and share, without warranty.
 * ==================================================================
 */

#include <Servo.h>

const int SERVO_PIN = 9;
Servo myServo;

void setup() {
  Serial.begin(115200);
  myServo.attach(SERVO_PIN);
  Serial.println(F("SG90 Servo Sweep Demo Started"));
}

void loop() {
  // Sweep from 0 to 180 degrees
  for (int pos = 0; pos <= 180; pos += 1) {
    myServo.write(pos);
    delay(15);
  }
  Serial.println(F("Reached 180 degrees"));
  delay(500);

  // Sweep back from 180 to 0 degrees
  for (int pos = 180; pos >= 0; pos -= 1) {
    myServo.write(pos);
    delay(15);
  }
  Serial.println(F("Reached 0 degrees"));
  delay(500);
}

Wiring diagram and example code generated by Codey.online — https://www.codey.online

Balayage du servo SG90 avec ESP32

Ce projet fait balayer un micro servo SG90 d’avant en arrière sur 180 degrés. Le servo est alimenté depuis la broche VIN de l’ESP32 (5V via USB) et commandé à l’aide d’un signal PWM généré avec la bibliothèque ESP32Servo. Ouvrez le Moniteur série pour observer l’angle actuel pendant le balayage.

Schéma de câblage : Servo SG90 micro 180 degrés sur un ESP32 DevKit V1
Schéma de câblage · Cliquez pour agrandir
Tableau de câblage : Servo SG90 micro 180 degrés sur un ESP32 DevKit V1
Tableau de câblage · Cliquez pour agrandir
SG90_Servo_Sweep_with_ESP32.ino · compilé et testé
/*
 * ==================================================================
 *  Generated by Codey.online  —  https://www.codey.online
 * ==================================================================
 *  Project   : SG90 Servo Sweep with ESP32
 *  Board     : ESP32 DEVKIT V1 (esp32:esp32:esp32doit-devkit-v1)
 *  Parts     : Servo SG90
 *  Libraries : ESP32Servo 3.1.3
 *
 *  Codey Online is an AI-powered browser IDE for Arduino and ESP32.
 *  Describe your project and Codey writes the code, draws the wiring
 *  diagram and uploads it to your board, straight from the browser.
 *  This code is free to use, modify and share, without warranty.
 * ==================================================================
 */

#include <ESP32Servo.h>

const int SERVO_PIN = 18;  // GPIO 18 connected to servo PWM pin

Servo myServo;

void setup() {
  Serial.begin(115200);
  Serial.println("ESP32 SG90 Servo Sweep Demo");

  // Allow allocation of all timers for ESP32Servo
  ESP32PWM::allocateTimer(0);
  ESP32PWM::allocateTimer(1);
  ESP32PWM::allocateTimer(2);
  ESP32PWM::allocateTimer(3);
  myServo.setPeriodHertz(50);      // Standard 50 Hz servo
  myServo.attach(SERVO_PIN, 500, 2400); // Standard pulse width limits for SG90
}

void loop() {
  // Sweep from 0 to 180 degrees
  for (int pos = 0; pos <= 180; pos += 5) {
    myServo.write(pos);
    Serial.print("Position: ");
    Serial.println(pos);
    delay(20);
  }

  delay(500);

  // Sweep back from 180 to 0 degrees
  for (int pos = 180; pos >= 0; pos -= 5) {
    myServo.write(pos);
    Serial.print("Position: ");
    Serial.println(pos);
    delay(20);
  }

  delay(500);
}

Bibliothèques nécessaires : ESP32Servo 3.1.3

Wiring diagram and example code generated by Codey.online — https://www.codey.online