# Arduino Setup Guide

This detailed and beginner-friendly guide walks you through every step needed to build, connect, program, and troubleshoot a robot using the **SMD Red** motor controller and an **Arduino** board. Whether you're a student, teacher, hobbyist, or engineer, this guide is designed to be practical and accessible.

***

### Introduction

The **SMD Red** is a smart motor controller that lets you easily drive motors, control servos, and read sensor data. It communicates with Arduino through an RS-485 connection via the **Arduino Gateway Module**, making it powerful yet easy to use even for beginners.

This guide explains everything you need to:

* Build your robot with SMD Red and Arduino
* Wire all components correctly
* Write and upload code using Arduino IDE
* Understand how the SMD Red system works
* Test and troubleshoot each part step by step

Even if you've never built a robot or written a line of code, this guide will help you go from zero to a working robot confidently.

***

### 1. User PC Setup

#### Install Arduino IDE and SMD Library

1. Download Arduino IDE from [arduino.cc](https://www.arduino.cc/en/software).
2. Install and open the IDE.
3. Navigate to `Sketch > Include Library > Manage Libraries`.
4. Search for `Acrome-SMD` and click **Install**.

#### &#x20;Install [SMD UI](https://docs.acrome.net/software/smd-ui) for:

* Verify the IDs of connected modules and controllers
* Change SMD Red IDs to unique values for project usage
* Test functionality of motors and modules

✅ Your computer is now ready to program your robot.

***

### 2. Robot Assembly + Arduino Setup

#### 🔌 Connecting SMD Red to Arduino

* Use the [**Arduino Gateway Module**](https://docs.acrome.net/electronics/gateway-modules/arduino-gateway-module) — a red shield that plugs directly into your Arduino Uno/Mega headers.
* Plug an **RJ-11 cable** from the Gateway Module to the first SMD Red Motor Driver Board.

#### Connecting Modules

* Connect modules (e.g., motors, servos, sensors) to the SMD Red using **RJ-45 cables**.

#### Module IDs

Each SMD module comes with a **module ID** that identifies it. These IDs are hardware-based and may vary between module versions. Use the [**SMD UI**](https://docs.acrome.net/software/smd-ui) to:

* Detect which modules are connected
* Confirm or discover module IDs
* Test functionality

📌 If multiple modules share the same ID, they must be connected to different SMD Red controllers to prevent conflict.

#### Daisy-Chaining Multiple SMD Reds

* Use **RJ-11** cables to connect additional SMD Reds.
* Each SMD Red must have a **unique ID** (0, 1, 2, ...).
* Use [**SMD UI** ](https://docs.acrome.net/software/smd-ui)to:
  * Assign and verify SMD Red IDs
  * Monitor and test all connected modules

#### ⚡ Powering Your System

* Plug a 12V DC adapter into the power port of the SMD Red.

***

### 3. Programming and Code Upload

To control the SMD Red from Arduino, you'll write and upload C++ code using the Arduino IDE. Here’s a breakdown of how it works:

#### Program Flow

1. **Include the library** for SMD Red: `#include <Acrome-SMD.h>`
2. **Define the serial baud rate** (default is 115200).
3. **Create a Red object**, defining which SMD Red you’re connecting to.
4. In `setup()`, initialize the communication, choose control mode, and enable torque.
5. In `loop()`, send commands to control motors.

#### Example Code: Basic Motor Control

```cpp
#include <Acrome-SMD.h>
#define BAUDRATE 115200

Red red(0, Serial, BAUDRATE);  // SMD Red ID 0 on Serial port

void setup() {
  red.begin();                       // Start communication
  red.setOperationMode(PWMControl); // Set PWM speed control mode
  red.torqueEnable(1);              // Turn motor output ON
}

void loop() {
  red.setpoint(0, 50);  // Run motor 0 forward at 50% power
  delay(1000);
  red.setpoint(0, 0);   // Stop motor
  delay(1000);
}
```

#### Code Explained

* `Red red(...)`: Creates a connection to SMD Red ID 0
* `begin()`: Establishes communication
* `setOperationMode(PWMControl)`: Sets control mode to PWM (speed)
* `torqueEnable(1)`: Enables motor power output
* `setpoint(0, 50)`: Sends command to motor 0 to run at 50% forward
* `delay(1000)`: Waits for 1 second before stopping

💡 You can add more `setpoint()` lines or change the speed/direction with values from -100 to 100.

***

### 4. Run and Test Your Robot

#### Uploading the Code

1. Connect Arduino to your PC using USB.
2. In Arduino IDE, go to `Tools > Port` and select the correct COM port.
3. Click the **Upload** button to flash your code.

#### Verifying Operation

* After uploading, the motor should spin forward for 1 second, then stop.

***

### 5. Troubleshooting Table ([SMD Red Troubleshooting Guide](https://docs.acrome.net/electronics/smd-red/troubleshooting-guide))

| Problem                 | Possible Cause               | Recommended Fix                           |
| ----------------------- | ---------------------------- | ----------------------------------------- |
| Nothing is moving       | No power to SMD Red          | Connect 12V adapter                       |
| Upload error in IDE     | TX/RX conflict with Serial   | Disconnect SMD Red before uploading       |
| Module not detected     | Wrong ID / cable loose       | Verify using SMD UI                       |
| Motor spins wrong way   | Wiring reversed              | Swap motor wires or use negative setpoint |
| Sensor returns 0 always | Wrong module ID or bad cable | Check ID with SMD UI and replug cable     |

***

### 6. Final Checklist

* [x] Arduino IDE installed
* [x] Acrome-SMD library installed
* [x] Arduino Gateway Module attached
* [x] RJ-11 cable connected to SMD Red
* [x] Modules connected via RJ-45
* [x] 12V power supply connected
* [x] SMD Red IDs confirmed via SMD UI
* [x] Code uploaded and working

🎉 **You’re done!** Your robot is now fully operational using Arduino + SMD Red. Start adding new features like servo control, sensor-based actions, or AI-assisted navigation!
