Arduino Nano - Motion Sensor - Servo Motor
This tutorial instructs you how to use Arduino Nano and motion sensor to control servo motor. In detail:
- If motion is detected, Arduino Nano rotates servo motor to 90 degree
- If motion is not detected, Arduino Nano rotates servo motor back to 0 degree.
This can be applied in an automation process that triggers actions upon detecting human presence.
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 Motion Sensor
If you are unfamiliar with servo motors and motion sensors, including pinout, how they work, and how to program them, the following tutorials can help:
Wiring Diagram
This image is created using Fritzing. Click to enlarge image
It should be noted that the wiring diagram shown above is only suitable for a servo motor with low torque. In case the motor vibrates instead of rotating, an external power source must be utilized to operate the servo motor. The following wiring diagram demonstrates how to connect the servo motor to an external power source.
This image is created using Fritzing. Click to enlarge image
Please do not forget to connect GND of the external power to GND of Arduino.
Initial Setting
Time Delay Adjuster | Screw it in anti-clockwise direction fully. |
Detection Range Adjuster | Screw it in clockwise direction fully. |
Repeat Trigger Selector | Put jumper as shown on the image. |
Arduino Nano Code - Motion Sensor Controls Servo Motor
Detailed Instructions
- Connect your Arduino Nano to the computer using a USB cable.
- Launch the Arduino IDE, select the appropriate board and port.
- Copy the code above and open it in the Arduino IDE.
- Click the Upload button in the Arduino IDE to compile and upload the code to the Arduino Nano.
- Wave your hand in front of the sensor.
- Check out the servo motor's movement.