Example Effect
Using Arduino Uno to drive a 9g servo motor,
achieving a rotation from 0 degrees to 90 degrees, then back from 90 degrees to 0 degrees, continuously repeating…
Component Description
Technical Parameters
Product Size: 32 x 30 x 12 mm
Working Torque: 1.6kg·cm (4.8V)
Operating Temperature: -30 to +60 degrees Celsius
Dead Zone Setting: 5 microseconds
Operating Voltage: 3.5V-6V
Plug Type: JR, FUTABA compatible
Rotational Angle: 180 degrees
Material: Plastic Gear
Applicable Range: Fixed-wing, Helicopter, Kt, Gliders, Small Robot Arms, etc.
Pin Description
Pin / IO | Color |
---|---|
Ground (GND) | Brown or Black |
Power (VCC) | Red |
Signal (PWM) | Orange or White |
BOM Table
Name | Quantity |
---|---|
Arduino Uno | x1 |
9g Servo | x1 |
Jumper Wires | Several |
Wiring Method
Note: The servo receives a PWM (Pulse Width Modulation) signal. Not all pins on the Arduino Uno have PWM functionality; only the pins marked with a “~” symbol support it, such as pins 3, 5, 6, 9, 10, and 11. However, the PWM pin definitions may vary between different boards, so please refer to the documentation for the specific board.
Program Code
Graphical Programming Blocks
This graphical programming uses the Tinkercad platform.
Text Programming Code
(Click to read the original text for a better code browsing experience)
// Load Servo library
#include <Servo.h>
// Create a servo instance named servo_9 (name can be anything)
Servo servo_9;
// Initialization function, runs once at startup
void setup()
{
// Configure using the instance method .attach(pin, min, max)
// pin: the pin number the servo is connected to
// min: (optional) pulse width (in microseconds), corresponding to the minimum (0 degrees) angle of the servo (default is 544)
// max: (optional) pulse width (in microseconds), corresponding to the maximum (180 degrees) angle of the servo (default is 2400)
// (pin, min, max)
servo_9.attach(9, 500, 2500);
}
// Main program, runs in a loop
void loop()
{
while (1 == 1) {
servo_9.write(0); // Move servo_9 to 0 degrees
delay(1000); // Wait 1000 milliseconds
servo_9.write(90); // Move servo_9 to 90 degrees
delay(1000); // Wait 1000 milliseconds
}
}
More technical insights……
Leave a Comment
Your email address will not be published. Required fields are marked *