Arduino Nano - Touch Sensor - Servo Motor
This tutorial instructs you how to use Arduino Nano and touch sensor to control servo motor. In detail:
- When the touch sensor is touched, Arduino Nano rotates the servo motor to 90 degrees
- When the touch sensor is touched again, Arduino Nano rotates the servo motor back to 0 degrees.
The same steps are carried out again.
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 Touch Sensor
If you are unfamiliar with servo motors and touch sensors (including pinouts, how they operate, 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.
Arduino Nano Code - Touch Sensor Controls Servo Motor
Detailed Instructions
- Connect your Arduino Nano to a computer using a USB cable.
- Launch the Arduino IDE, select the correct board type and port.
- Copy the code above and open it in the Arduino IDE.
- Click the Upload button in the Arduino IDE to send the code to the Arduino Nano.
- Tap the touch sensor multiple times.
- Check out the servo motor's angle changing.