Below is a basic tutorial to get you started with how to connect four servo motors and an I2C RTC (Real-Time Clock) module to an Arduino Nano. This tutorial shows the necessary hardware, a basic wiring diagram, and code examples.
This pairs with the Rack Driven 7 Segment Display
Hardware Required
- 1 × Arduino Nano (https://geni.us/vdx2Pn3)
- 4 × Servo Motors (https://geni.us/G8ArjNg)
- 1 × DS3231 RTC Module (https://geni.us/rtKYLJT)
- External Power Supply (https://geni.us/QwyvCh)
Optional Hardware
- Breadboard (https://geni.us/2dAJj)
- Jumper Wires (https://geni.us/n53x)
Servo Motors
Servo motors are used to control the angular position of an object. They have three pins:- VCC (usually red) - Connects to 5V
- GND (usually black or brown) - Connects to GND
- Signal (usually yellow or orange) - Receives the PWM control signal from the Arduino
DS3231 RTC Module
The DS3231 is a low-cost, highly accurate Real-Time Clock that communicates with the Arduino via the I2C protocol. It has four pins:- VCC - Connects to 5V
- GND - Connects to GND
- SDA - Connects to A4 (SDA) on the Arduino Nano
- SCL - Connects to A5 (SCL) on the Arduino Nano
Wiring Diagram
Connecting Servo Motors
- Connect the VCC pin of each servo motor to the 5V power supply (note: The Arduino has a 5V output pin, however it can't supply enough current to drive your servo motors. This is why you need an external power source.)
- Connect the GND pin of each servo motor to the GND pin on the Arduino Nano and the GND pin of your power supply.
- Connect the Signal pins of the servo motors to digital pins D2, D3, D4, and D5 on the Arduino Nano.
Connecting DS3231 RTC Module
- Connect the VCC pin of the RTC module to the 5V pin on the Arduino Nano.
- Connect the GND pin of the RTC module to the GND pin on the Arduino Nano.
- Connect the SDA pin of the RTC module to the A4 pin on the Arduino Nano.
- Connect the SCL pin of the RTC module to the A5 pin on the Arduino Nano.
Make sure you are powering your Arduino via the USB plug on the board.
Wiring Diagram Image
Alternative Option:
The Sunfounder Servo Board:
This is a board that the Arduino nano plugs into has a spot for up to 12 servos. The RTC module can be connected with jumper cables. Needs a 7-12V power supply (or DC adapter) to run, which powers both the Arduino, RTC, and the Servos.
https://www.sunfounder.com/products/servo-control-board
Note, these are the pin mappings from the nano to the sunfounder board:
Nano SunFounder | Nano Sunfounder
D2 -> 1 A0 -> 7
D3 -> 2 A1 -> 8
D4 -> 3 A2 -> 9
D5 -> 4 A3 -> 10
D6 -> 5 A4 -> 11
D7 -> 6 A5 -> 12
I2C Servo Board:
This board connects to Arduino via the i2c protocol (same as the RTC module). It takes a 5V input, and can power up to 16 servo motors. A great option, but requires a bit more advanced code. (https://geni.us/wNR5d)
The Code: