Arduino Nano 33 IoT - Ultrasonic Sensor - Servo Motor
This guide shows you how to use the Arduino Nano 33 IoT with a potentiometer to control a servo motor. Here are the details:
- The Arduino Nano 33 IoT turns a servo motor to 90° when an object is close to the ultrasonic sensor.
- The Arduino Nano 33 IoT turns the servo motor back to 0° when an object is far from the ultrasonic sensor.
Hardware Preparation
Or you can buy the following sensor kits:
1 | × | DIYables Sensor Kit (30 sensors/displays) | |
1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Overview of Servo Motor and Ultrasonic Sensor
If you're new to using the Servo Motor, Ultrasonic Sensor, and Arduino Nano 33 IoT, please check out these tutorials:
These tutorials explain how Servo Motor and Ultrasonic Sensor work, their pinouts, how to connect them to the Arduino Nano 33 IoT, and how to program Arduino Nano 33 IoT to work with the Servo Motor and Ultrasonic Sensor.
Wiring Diagram

This image is created using Fritzing. Click to enlarge image
Arduino Nano 33 IoT Code - Ultrasonic Sensor Controls Servo Motor
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 to compile and send the code to your Arduino Nano 33 IoT board.
- Place your hand in front of the sensor.
- Watch the servo motor move.