Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:iot-open:practical:hardware:taltech:arduino:scenarios:dc [2025/07/18 14:03] ingmar05en:iot-open:practical:hardware:taltech:arduino:scenarios:dc [2025/09/02 18:02] (current) raivo.sell
Line 1: Line 1:
 +<pagebreak>
 +====== Controlling a DC motor ======
 +
 +This scenario demonstrates how to control a DC motor's rotation direction and speed using Arduino with the Pololu TB6612FNG Dual Motor Driver.
 +
 +{{:en:iot-open:practical:hardware:taltech:arduino:scenarios:dc.jpg?100|}}
 +
 +===== 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;
 +</code>
 +
 +=== Step 2: Setup ===
 +Configure pin modes:
 +<code c>
 +void setup() {
 +  pinMode(AIN1, OUTPUT);
 +  pinMode(AIN2, OUTPUT);
 +  pinMode(PWMA, OUTPUT);
 +}
 +</code>
 +
 +=== Step 3: Control Loop ===
 +Implement motor control logic:
 +<code c>
 +void loop() {
 +  // Rotate Forward at full speed
 +  digitalWrite(AIN1, HIGH);
 +  digitalWrite(AIN2, LOW);
 +  analogWrite(PWMA, 255);  // Full speed
 +  delay(5000);             // 5 seconds
 +
 +  // Stop motor
 +  digitalWrite(AIN1, LOW);
 +  digitalWrite(AIN2, LOW);
 +  delay(2000);             // 2 seconds pause
 +
 +  // Rotate Reverse at half speed
 +  digitalWrite(AIN1, LOW);
 +  digitalWrite(AIN2, HIGH);
 +  analogWrite(PWMA, 128);  // Half speed
 +  delay(5000);             // 5 seconds
 +
 +  // Stop motor again
 +  digitalWrite(AIN1, LOW);
 +  digitalWrite(AIN2, LOW);
 +  delay(2000);             // 2 seconds pause
 +}
 +</code>
 +
 +===== 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.
  
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0