Happy building!
Always add large electrolytic capacitors (1000µF, 25V) across the Vs and GND terminals. The L298N creates severe voltage spikes during switching, which can reset your Arduino. A capacitor absorbs this noise, creating a professional-grade robot.
// Motor A Reverse, Motor B Forward digitalWrite(IN1, LOW); digitalWrite(IN2, HIGH); digitalWrite(IN3, HIGH); digitalWrite(IN4, LOW); delay(2000); hw 130 motor control shield for arduino datasheet
int currentPin = A0; float voltage, current; void setup() Serial.begin(9600);
| HW 130 Signal | Arduino Pin | Function | Notes | | :--- | :--- | :--- | :--- | | | Digital Pin 4 | Motor A Direction 1 | | | IN2 | Digital Pin 5 | Motor A Direction 2 | | | IN3 | Digital Pin 6 | Motor B Direction 1 | | | IN4 | Digital Pin 7 | Motor B Direction 2 | | | ENA | Digital Pin 3 | Enable / PWM for Motor A | Hardware PWM capable | | ENB | Digital Pin 11 | Enable / PWM for Motor B | Hardware PWM capable | | +5V | 5V Pin | Logic supply (input or output) | | | GND | GND | Common ground | | | CS A | Analog Pin A0 | Current sense for Motor A (voltage proportional to current) | | | CS B | Analog Pin A1 | Current sense for Motor B | | Critical Note: Unlike some generic L298N modules, the HW 130 reserves pins 3 and 11 for PWM, making it ideal for speed control. Do not use these pins for other sensors. Part 3: Schematic Logic & How It Works The heart of the HW 130 is the L298N dual full-bridge driver. To understand the logic, you must grasp the truth table for one channel (using IN1/IN2 and ENA). 3.1 Motor Direction Truth Table (for Motor A) | IN1 (Pin 4) | IN2 (Pin 5) | ENA (Pin 3) | Motor A State | | :--- | :--- | :--- | :--- | | LOW | LOW | HIGH | Brake (stop fast) | | HIGH | LOW | HIGH | Forward | | LOW | HIGH | HIGH | Reverse | | HIGH | HIGH | HIGH | Brake (stop fast) | | X | X | LOW | Coast (free spin) | Happy building
// Set direction forward for both motors digitalWrite(4, HIGH); digitalWrite(5, LOW); digitalWrite(6, HIGH); digitalWrite(7, LOW);
Detect stalls, measure load, or implement torque limiting. Part 3: Schematic Logic & How It Works
Motor Current (A) = (analogRead(A0) * (5.0 / 1023.0)) / 0.5