Skip to content

Week 10 - Output devices

## Individual

1. Introduction

In this project, I implemented a high-torque motion system using a DC motor, a dual-channel driver, and an ESP8266 microcontroller. The goal was to achieve not just movement, but precision through encoder feedback.

Step 1: Selecting the Components (Introduction)

To build a reliable output system, I chose components that balance power with data feedback:

Actuator: I used the Rev Hex DC Motor. I chose this specifically because it is a professional-grade motor with an integrated quadrature encoder. This allows the system to "count" rotations, making it much smarter than a standard motor.

Driver: I used the ZK-5AD Dual H-Bridge Driver. Since the microcontroller cannot provide the 12V and high current the motor needs, this driver acts as a bridge, allowing the ESP-12E to control the motor's direction and speed safely.

````````````

Step 2: Circuit Design and Schematic

Before picking up the soldering iron, I drew a detailed wiring schematic. The challenge was managing two different voltages: 3.3V for the logic (ESP8266) and 12V for the motor power.

Logic Mapping: I assigned GPIO12 and GPIO14 to control the motor driver (D0 and D1).

Feedback Mapping: I connected the Encoder Channel A and Channel B to GPIO4 and GPIO5.

Power Strategy: I ensured a Common Ground (GND) connected the battery, the driver, and the ESP8266 to prevent signal floating and electrical noise.

Step 3: Hardware Fabrication and Soldering

Once the plan was ready, I moved to assembly. I soldered the components onto a PCB to ensure the connections were permanent and could handle the physical vibrations of a spinning motor.

Soldering Process: I used high-quality solder for the motor power terminals, as these carry the most current.

Connectors: I utilized 3-pin and 4-pin headers to make the motor and encoder wires easy to plug and unplug during testing.

Step 4: Initial Motor Testing (Movement)

The first software test was a "Smoke Test" to verify the H-bridge logic. I wrote a simple script to cycle the motor: Forward -> Stop -> Backward -> Stop.

PWM Control: I implemented Pulse Width Modulation (PWM) to test the speed. By changing the duty cycle, I confirmed I could make the motor crawl slowly or spin at maximum RPM.

Result: The motor responded perfectly to the direction and speed commands from the ESP8266.

HERE IS SIMPLE CODE FOR TIMER MOTOR

#define IN1 12  
#define IN2 14  

void setup() {
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);

  // Включаем мотор вперед
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
}

void loop() {
  delay(5000); 


  digitalWrite(IN1, LOW);
  digitalWrite(IN2, LOW);

  while(true); 
}

Step 5: Encoder Calibration (Manual Feedback)

The final and most important step was verifying the encoder. To ensure the code was counting correctly, I performed a Manual Rotation Test:

I uploaded a script using Interrupts to catch every pulse from the encoder.

I kept the motor power off and rotated the motor shaft by hand.

Observation: As I turned the shaft, the "Tick Count" in the Serial Monitor increased. If I turned it the other way, the count decreased.

Significance: This proved that the encoder was successfully sending data to the ESP8266, allowing the system to track the exact position of the wheel.

here is code for count encoder

#define ENCODER_A  4
#define ENCODER_B  5

volatile long encoderCount = 0;

IRAM_ATTR void encoderISR() {
  if (digitalRead(ENCODER_B))
    encoderCount++;
  else
    encoderCount--;
}

void setup() {
  Serial.begin(115200);

  pinMode(ENCODER_A, INPUT_PULLUP);
  pinMode(ENCODER_B, INPUT_PULLUP);

  attachInterrupt(digitalPinToInterrupt(ENCODER_A), encoderISR, RISING);
}

void loop() {
  Serial.println(encoderCount);
  delay(100);
}

Conclusion: Integrated Motion Control System

The integration of the Rev Hex DC Motor and the ZK-5AD driver marks a critical milestone in the development of my Final Project. By successfully bridging the gap between high-power actuation and digital logic, I have established a reliable foundation for all physical movements of the robot.

Key Technical Achievements:

Bidirectional Drive: The H-bridge configuration allows for seamless transitions between forward and reverse motion with precise speed modulation via PWM.

Closed-Loop Feedback: The implementation of the quadrature encoder transforms the motor from a basic output device into a smart actuator. The system can now track its own position in real-time.

Hardware Stability: The custom-soldered PCB and isolated power rails ensure that the ESP-12E remains stable and protected from inductive spikes during high-load operations.

Final Result: The system is now capable of more than just spinning a wheel; it can measure distance, monitor velocity, and maintain directional accuracy. With the hardware finalized and the feedback loop active, the next phase will involve implementing autonomous navigation algorithms to achieve fully controlled movement.