This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| en:iot-open:practical:hardware:taltech:arduino:scenarios:dc [2025/06/25 08:56] – created raivo.sell | en:iot-open:practical:hardware:taltech:arduino:scenarios:dc [2025/09/02 15:02] (current) – raivo.sell | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== DC motor ====== | + | < |
| + | ====== | ||
| + | |||
| + | This scenario demonstrates how to control a DC motor' | ||
| + | |||
| + | {{: | ||
| + | |||
| + | ===== Prerequisites ===== | ||
| + | * Familiarize yourself with the Arduino hardware reference. | ||
| + | * Understand basic PWM concepts. | ||
| + | * Familiarity with the Pololu TB6612FNG motor driver. | ||
| + | |||
| + | ===== Hardware Connections ===== | ||
| + | ^ Motor Driver Pin ^ Arduino Pin ^ | ||
| + | | AIN1 | 12 | | ||
| + | | AIN2 | 11 | | ||
| + | | PWMA | 3 (PWM) | | ||
| + | |||
| + | **Motor specifications: | ||
| + | * Voltage: 12 V DC | ||
| + | * Speed: 5 rpm | ||
| + | * Torque: 20 N·cm | ||
| + | * Shaft Diameter: 4 mm | ||
| + | |||
| + | |||
| + | ===== Task ===== | ||
| + | Implement a program that rotates the DC motor forward at full speed for 5 seconds, pauses for 2 seconds, reverses at half speed for 5 seconds, and then pauses again for 2 seconds, repeating this sequence. | ||
| + | |||
| + | ===== Steps ===== | ||
| + | |||
| + | === Step 1: Define Pins === | ||
| + | <code c> | ||
| + | const int AIN1 = 12; | ||
| + | const int AIN2 = 11; | ||
| + | const int PWMA = 3; | ||
| + | </ | ||
| + | |||
| + | === Step 2: Setup === | ||
| + | Configure pin modes: | ||
| + | <code c> | ||
| + | void setup() { | ||
| + | pinMode(AIN1, | ||
| + | pinMode(AIN2, | ||
| + | pinMode(PWMA, | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | === Step 3: Control Loop === | ||
| + | Implement motor control logic: | ||
| + | <code c> | ||
| + | void loop() { | ||
| + | // Rotate Forward at full speed | ||
| + | digitalWrite(AIN1, | ||
| + | digitalWrite(AIN2, | ||
| + | analogWrite(PWMA, | ||
| + | delay(5000); | ||
| + | |||
| + | // Stop motor | ||
| + | digitalWrite(AIN1, | ||
| + | digitalWrite(AIN2, | ||
| + | delay(2000); | ||
| + | |||
| + | // Rotate Reverse at half speed | ||
| + | digitalWrite(AIN1, | ||
| + | digitalWrite(AIN2, | ||
| + | analogWrite(PWMA, | ||
| + | delay(5000); | ||
| + | |||
| + | // Stop motor again | ||
| + | digitalWrite(AIN1, | ||
| + | digitalWrite(AIN2, | ||
| + | delay(2000); | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ===== Validation ===== | ||
| + | Observe the motor rotating in both directions with clear speed differences. Verify pauses between rotations. | ||
| + | |||
| + | ===== Troubleshooting ===== | ||
| + | If the motor doesn’t rotate or behaves erratically: | ||
| + | * Check power supply (motor needs 12V DC). | ||
| + | * Confirm motor driver connections. | ||
| + | * Verify Arduino pin assignments match the code. | ||