forked from arduino/Arduino
-
Notifications
You must be signed in to change notification settings - Fork 6
RL78 G23 128p FPB ServoMotor (Arduino™ Sketch)
MikiyaKobayashi edited this page Oct 22, 2025
·
3 revisions
- This page describes how to make a servo motor perform reciprocating motion from 0 to 180 degrees
- For basic information such as how to install the Arduino IDE, Arduino libraries, and how to write sketches to the board, please refer to the Quick Start Guide
This page uses the following environment and products
- Arduino IDE 2.3.6
- RL78/G23-128p FPB Arduino Library v1.2.0
- Connect the SG-90 and RL78/G23-128p FPB as shown below
| SG-90 Pin | RL78/G23-128p FPB Pin |
|---|---|
| SIG (Orange) | 9 |
| +V (Red) | 5V |
| GND (Brown) | GND |

- Open the Arduino IDE and select “File” → “Examples” → “Servo” → “Sweep”
-
Compile and Upload the sketch
- Select “Upload” in the Arduino IDE to start compiling and writing
- Select “Upload” in the Arduino IDE to start compiling and writing
-
If the servo motor moves back and forth from 0 to 180 degrees as shown below, it is working correctly

-
You can set the angle using
myservo.write(angle_in_degrees); -
Modify the sketch as shown below to set the target angle to 20 degrees
Lines 24–33 - for(pos = 0; pos <= 180; pos += 1) // goes from 0 degrees to 180 degrees - { // in steps of 1 degree - myservo.write(pos); // tell servo to go to position in variable 'pos' - delay(15); // waits 15ms for the servo to reach the position - } - for(pos = 180; pos>=0; pos-=1) // goes from 180 degrees to 0 degrees - { - myservo.write(pos); // tell servo to go to position in variable 'pos' - delay(15); // waits 15ms for the servo to reach the position - } + myservo.write(20);
- Actual operation
- Actual operation
-
To change the pin number, modify the number in
myservo.attach(9);on line 19 to the desired pin number -
The following pins can be used for connecting the SIG pin Pin list here:
Pins Compatible with Servo Motor 0–19, 23, 25–29, 31–56, 58, 59, 62–71, 74–89, 92–118 -
Example: Change SIG pin from pin 9 to pin 2
-
Change the pin connections as follows
SG-90 Pin RL78/G23-128p FPB Pin SIG (Orange) 2 +V (Red) 5V GND (Brown) GND
-
-
Modify the sketch as shown below to set the SIG pin to pin 2
Line 19 - myservo.attach(9); + myservo.attach(2);