Arduino Nano Servo Motor Control Code
Servos are fast and strong motors with a limited movement range. You can control SG90, MG996R and other small servo motors with your Ozeki software by providing a desired angle. Each servo has a built in potmeter. It will try to position the motor axis to reach the desired angle. You can discover the minimum and maximum movement range by reading the datasheet. You can simultaneously control as many servo motors as you wish. It also supports the waterproof SM-S8330M with 30 kg torque.
Required hardware
- Arduino Nano
- Servo Motor(s)
Source code to install on controller
Before you upload this code to your Arduino, please format the EEPROM...
#include <OzIDManager.h> #include <OzServoController.h> OzIDManager* manager; OzServoController* servocontroller; void setup() { Serial.begin(115200); manager = new OzIDManager; manager->_sendACK = true; manager->_checksum = true; OzCommunication::setIDManager(manager); servocontroller = new OzServoController; //pin 6, MG996R servo (motor min -60, motor max +60), starting angle +5 servocontroller->AddMotorconfig(6, ServoMotors::SERVO_MG996R, 5); int x=1; manager->sendLinkSetup(); manager->PrintWelcomeLine(servocontroller, x++, "MyServoMotor"); servocontroller->showMotorDetails(); } void loop() { OzCommunication::communicate(); }
Good to know
You can use the following enums in the constructor to use the SG90, MG996R or SM-S8330M servos:
servocontroller->AddMotorconfig(5, ServoMotors::SERVO_SG90);
servocontroller->AddMotorconfig(6, ServoMotors::SERVO_MG996R);
servocontroller->AddMotorconfig(7, ServoMotors::SERVO_SM_S8330M);
More information
- How to setup a servo motor on arduino mega
- How to setup a servo motor on arduino nano
- How to setup a servo motor on arduino uno
- How to setup a servo motor on Ozeki matrix
- Servo motor protocol for arduino
- How to control a servo motor using chat messages
- Servo Motor Desc
- Servo Arduino
- Servo Matrix Arduino
- Servo RaspPI Shield