Control a servo with Arduino
Vier Positionen anfahren – mit UNO, Wemos D1 Mini oder NodeMCU
You need this
Funduino SG90 servo motor - 9 g, 180°, 3.5-6 V
2,33 € *Item no. F23107201About the product — Funduino SG90 servo motor - 9 g, 180°, 3.5-6 V
Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino
11,12 € *Item no. F23107480About the product — Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino
Breadboard Cables Male-to-Male - 40 Pieces, 20 cm
1,74 € *Item no. FUN-1010558About the product — Breadboard Cables Male-to-Male - 40 Pieces, 20 cm
All 3 parts together 15,19 € *Ready to ship immediately · Delivery time: 1-3 business days
* All prices include statutory VAT, plus shipping costs.
Choose a microcontroller
Pins, schematic, and sketch in the steps change with your selection. It remains saved.
Controlling a servo motor with a microcontroller
// die Bibliothek Servo.h wird eingebunden, sie steuert den Motor
#include "Servo.h"
// der Servomotor erhält den Namen Servomotor
Servo Servomotor;
void setup()
{
// dem Servomotor wird der Pin 8 zugeordnet
Servomotor.attach(8);
}
void loop()
{
// der write-Befehl steuert den Servomotor
// Zwischen den einzelnen Positionen gibt es eine Pause
// Position 1 ansteuern mit dem Winkel 0°
Servomotor.write(0); // Position 1 ansteuern mit dem Winkel 0°
// 3 Sekunden Pause
delay(3000);
// Position 2 mit dem Winkel 90° ansteuern
Servomotor.write(90);
// 3 Sekunden Pause
delay(3000);
// Position 3 mit dem Winkel 180° ansteuern
Servomotor.write(180);
// 3 Sekunden Pause
delay(3000);
// Position 4 mit dem Winkel 20° ansteuern
Servomotor.write(20);
// 3 Sekunden Pause
delay(3000);
}Download: arduino-uno.ino
Board in the Arduino IDEArduino Uno
You don’t need an additional board package for this. The UNO is included in the Arduino IDE by default.
// die Bibliothek Servo.h wird eingebunden, sie steuert den Motor
#include "Servo.h"
// der Servomotor erhält den Namen Servomotor
Servo Servomotor;
void setup()
{
// dem Servomotor wird der Pin D1 zugeordnet
Servomotor.attach(D1);
}
void loop()
{
// der write-Befehl steuert den Servomotor
// Zwischen den einzelnen Positionen gibt es eine Pause
// Position 1 ansteuern mit dem Winkel 0°
Servomotor.write(0); // Position 1 ansteuern mit dem Winkel 0°
// 3 Sekunden Pause
delay(3000);
// Position 2 mit dem Winkel 90° ansteuern
Servomotor.write(90);
// 3 Sekunden Pause
delay(3000);
// Position 3 mit dem Winkel 180° ansteuern
Servomotor.write(180);
// 3 Sekunden Pause
delay(3000);
// Position 4 mit dem Winkel 20° ansteuern
Servomotor.write(20);
// 3 Sekunden Pause
delay(3000);
}Download: wemos-d1-mini.ino
Board in the Arduino IDELOLIN(WEMOS) D1 R2 & mini
The ESP8266 board manager must be installed for this. Add it once via the Arduino IDE settings.
// die Bibliothek Servo.h wird eingebunden, sie steuert den Motor
#include "Servo.h"
// der Servomotor erhält den Namen Servomotor
Servo Servomotor;
void setup()
{
// dem Servomotor wird der Pin D1 zugeordnet
Servomotor.attach(D1);
}
void loop()
{
// der write-Befehl steuert den Servomotor
// Zwischen den einzelnen Positionen gibt es eine Pause
// Position 1 ansteuern mit dem Winkel 0°
Servomotor.write(0); // Position 1 ansteuern mit dem Winkel 0°
// 3 Sekunden Pause
delay(3000);
// Position 2 mit dem Winkel 90° ansteuern
Servomotor.write(90);
// 3 Sekunden Pause
delay(3000);
// Position 3 mit dem Winkel 180° ansteuern
Servomotor.write(180);
// 3 Sekunden Pause
delay(3000);
// Position 4 mit dem Winkel 20° ansteuern
Servomotor.write(20);
// 3 Sekunden Pause
delay(3000);
}Download: nodemcu.ino
Board in the Arduino IDENodeMCU 1.0 (ESP-12E Module)
The ESP8266 board manager must be installed for this. Add it once via the Arduino IDE settings.