Arduino Project
Servo Control (IOT)
Course Introduction
This Arduino project uses Arduino IoT Remote to control a servo motor.
Note
If this is your first time working with an Arduino project, we recommend downloading and reviewing the basic materials first.
1.1 Install Arduino IDE(Important)
1.2 Introduction of Arduino IDE
Please follow the steps in the tutorial below to complete the binding and setup of Arduino Cloud and the Arduino WiFi board.
1.4 Arduino IoT Cloud
Wiring

Common Connections:
Digital Servo Motor A
Connect to breadboard’s positive power bus.
Connect to breadboard’s negative power bus.
Connect to 3 on the Arduino.
Digital Servo Motor B
Connect to breadboard’s positive power bus.
Connect to breadboard’s negative power bus.
Connect to 5 on the Arduino.
Digital Servo Motor C
Connect to breadboard’s positive power bus.
Connect to breadboard’s negative power bus.
Connect to 6 on the Arduino.
Digital Servo Motor D
Connect to breadboard’s positive power bus.
Connect to breadboard’s negative power bus.
Connect to 9 on the Arduino.
Create a New IoT Project
After configuring the Arduino Cloud and the Arduino WiFi board, follow the steps below to complete the Arduino Cloud project setup

Edit Value

Follow the steps below to configure the dashboard.
1.Create New Dashboard

2.Add Widgets

3.Link Variable


4.Remember to click Done

After completing the above configuration, return to the Things page and open the sketch.

When you have completed the configuration of the Things and Dashboard, as well as the connection and network setup of the Arduino WiFi board, the thingProperties.h and Sketch Secrets files will be generated automatically. If Sketch Secrets is not generated, please manually enter the connected SSID and OPTIONAL_PASS
Copy this code into Arduino Cloud.

Don’t forget to select the board(Arduino UNO R4 WIFI) and the correct port before clicking the Upload button.
#include
#include "thingProperties.h"
// ========== Servo pins (modifiable if needed) ==========
const uint8_t SERVO_PINS[4] = {3, 5, 6, 9}; // D3, D5, D6, D9
// Servo pulse width (microseconds), adjustable according to your servo, e.g., 500~2400us
const int SERVOMIN_US = 500;
const int SERVOMAX_US = 2400;
// ======================================================
Servo servos[4];
void setup() {
Serial.begin(115200);
delay(500);
// Initialize cloud properties and connect to IoT Cloud
initProperties();
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
// Attach 4 servos and set default angle
for (int i = 0; i < 4; i++) {
servos[i].attach(SERVO_PINS[i], SERVOMIN_US, SERVOMAX_US);
servos[i].write(90);
}
// (Optional) Sync current device angle to the cloud
angle0 = 90; angle1 = 90; angle2 = 90; angle3 = 90;
}
void loop() {
ArduinoCloud.update(); // Must be placed inside loop
}
// ====== Cloud property change callbacks (triggered when slider changes) ======
void onAngle0Change() { servos[0].write(constrain(angle0, 0, 180)); }
void onAngle1Change() { servos[1].write(constrain(angle1, 0, 180)); }
void onAngle2Change() { servos[2].write(constrain(angle2, 0, 180)); }
void onAngle3Change() { servos[3].write(constrain(angle3, 0, 180)); }
