Arduino Nano 33 IoT - Ultrasonic Sensor - LED
This guide shows you how to use the Arduino Nano 33 IoT and an Ultrasonic sensor to control an LED. Here are the details:
- The Arduino Nano 33 IoT turns the LED on by itself when an object is near the ultrasonic sensor. It turns the LED off by itself when the object is far away.
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 LED and Ultrasonic Sensor
If you're new to using the LED, Ultrasonic Sensor, and Arduino Nano 33 IoT, please check out these tutorials:
These tutorials explain how LED 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 LED and Ultrasonic Sensor.
Wiring Diagram
- The wiring diagram shows the power provided by a USB cable.

This image is created using Fritzing. Click to enlarge image
- This is a wiring diagram that uses a 5V adapter as the power source.

This image is created using Fritzing. Click to enlarge image
Arduino Nano 33 IoT Code
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 build and upload the code to your Arduino Nano 33 IoT board.
- Move your hand in front of the sensor.
- Watch the LED change.
Line-by-line Code Explanation
The Arduino Nano 33 IoT code above explains each line. Please make sure to read the comments in the code.