Arduino Nano 33 IoT - Servo Motor

This guide explains how to use the Arduino Nano 33 IoT to control a servo motor.

Arduino Nano 33 IoT Servo Motor

Hardware Preparation

1×Arduino Nano 33 IoT
1×Micro USB Cable
1×Servo Motor
1×Breadboard
1×Jumper Wires
1×Optionally, DC Power Jack
1×Recommended: Screw Terminal Expansion Board for Arduino Nano
1×Recommended: Breakout Expansion Board for Arduino Nano
1×Recommended: Power Splitter for Arduino Nano

Or you can buy the following sensor kits:

1×DIYables Sensor Kit (30 sensors/displays)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

Overview of Servo Motor

A standard servo motor is a motor that turns from 0 degrees to 180 degrees.

Servo Motor Pinout

The servo motor comes with three connection points:

  • GND pin (brown or black): This pin connects to the ground (0 volts).
  • VCC pin (red): This pin connects to the power supply (5 volts).
  • Signal pin (yellow or orange): This pin receives the PWM control signal from a pin on the Arduino Nano 33 IoT.
Servo Motor Pinout

How Servo Motor Works

Check out this page to learn how a servo motor works: How servo motor works

Wiring Diagram between Servo Motor and Arduino Nano 33 IoT

  • When giving power to the Arduino Nano 33 IoT board using the USB port.
The wiring diagram between Arduino Nano and 33 IoT Servo Motor

This image is created using Fritzing. Click to enlarge image

  • When you supply power to the Arduino Nano 33 IoT board through the Vin pin.
The wiring diagram between Arduino Nano and 33 IoT servo motor external power supply

This image is created using Fritzing. Click to enlarge image

※ NOTE THAT:

When you power the Arduino Nano 33 IoT board with USB, do not use the Vin or VBUS pins to power your servo motor. Using these pins for the servo can damage your board.

Arduino Nano 33 IoT Code

/* * This Arduino Nano 33 IoT code was developed by newbiely.com * * This Arduino Nano 33 IoT code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano-iot/arduino-nano-33-iot-servo-motor */ #include <Servo.h> #define SERVO_PIN 2 // The Arduino Nano 33 IoT pin connected to servo motor Servo servoMotor; void setup() { servoMotor.attach(SERVO_PIN); // attaches the servo on Arduino Nano 33 IoT pin } void loop() { // rotates from 0 degrees to 180 degrees for (int pos = 0; pos <= 180; pos += 1) { // in steps of 1 degree servoMotor.write(pos); delay(15); // waits 15ms to reach the position } // rotates from 180 degrees to 0 degrees for (int pos = 180; pos >= 0; pos -= 1) { servoMotor.write(pos); delay(15); // waits 15ms to reach the position } }

Detailed Instructions

If you are new to the Arduino Nano 33 IoT, be sure to check out our Getting Started with Arduino Nano 33 IoT tutorial. Then, follow these steps:

  • Connect the components to the Arduino Nano 33 IoT board as depicted in the diagram.
  • Use a USB cable to connect the Arduino Nano 33 IoT board to your computer.
  • Launch the Arduino IDE on your computer.
  • Select the Arduino Nano 33 IoT board and choose its corresponding COM port.
  • Copy the code above and paste it into the Arduino IDE.
  • Click the Upload button in the Arduino IDE to check and send the code to the Arduino Nano 33 IoT board.
How to upload Arduino Nano 33 IoT code on Arduino IDE
  • See the result: The servo motor slowly turns about 180 degrees, first to the right and then to the left.

Line-by-line Code Explanation

The code for Arduino Nano 33 IoT above explains each line. Please read the comments in the code!

How to Control Speed of Servo Motor

Check out this guide on how to control a servo motor's speed: https://arduinogetstarted.com/faq/how-to-control-speed-of-servo-motor

Video Tutorial

You can find the guide and code for the video above in this How to control a servo motor via the web tutotial.

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!