Multiple PID motor controller (with Wiimote!) using Atmega644


The main idea for our project was to implement an inexpensive solution to the current CU Snake Arm motor-driving system by using a Mega644 microcontroller instead of multiple 3-Amp motor controllers as the snake arm was originally intended to be driven. Since we used DC motors, we implemented a PID control algorithm that determines the speed of the motors using PWM to achieve the best accuracy possible.
Multiple PID motor controller (with Wiimote!) using Atmega32
The motors can be controlled with Hyperterm or a Wiimote. Hyperterm allows for numerical input of each motor’s position ranging from 0 to 255. The Wiimote sends IR data via Bluetooth to a MacBook, which then sends the information to the MCU through a serial connection.

High Level Design

Rationale and Motivation

The Snake Arm team at Cornell designed its fourth generation arm having multiple cells involving gear assemblies, chains, springs, strings and pulleys. In order to move the arm accurately to a desired position, a real-time feedback is required.
The feedback is provided using potentiometers coupled with the motors through gears and shafts. The Snake arm team initially planned on using one Polulu 3-A motor controller to drive each DC motor. The fact that each Pololu PID controller can drive only one motor and has a cost of $50 imposes an inherent limitation in terms of cost and utility as the complete snake arm would require at least 10 controllers (5 segments). In this project, we implement a multiple PID motor controller using the Atmel Mega644 microcontroller which can drive up to 8 motors. This saves enormous cost and pain of calibration for the team.
We have also implemented Wii remote interface with our motor controller. This gives the snakearm more intuitive wireless flexibility in terms of motion control.

Background Math

The main feature of the motor controller is the ability to use feedback from sensors to continually update the motor operation and minimize error using the PID algorithm. The error is the difference between the desired condition set by the user through one of the input modes, and the actual condition reported back by a sensor. In our case the sensor is a potentiometer coupled with the motor shaft through a gear assembly and pulley system.

Tuning Method

We used manual tuning. We first set the Ki and Kd values to zero and kept on increasing the Kp until we reached a suitable value. After having full load on the motor we increased Kd until the motors were able to move the entire segment to the extreme points. Finally we increased Ki until the loop worked within an acceptable error range High values of Kd lead to extreme motor motion and instability. Increasing the Integral term helped us to get rid of oscillation problems.

Logical Structure

Hardware Design

Mechanical Components

Each segment of the snake arm comprises of three cells and two DC motors. The two motors are used to give the segment four degrees of freedom. One of the motor controls movement in the left-right direction while the other controls it in the up-down direction.
The red circular disks are three inch in diameter, laser-cut, out off acrylic for reduced weight. The motor frame has been CNC milled from Aluminum. Ball bearings are used to reduce friction. The gear assembly establishes a 20:1 worm gear reduction ratio. This leads to a maximum pulling force of 100 lbs per cable. The gap between each circular disk is 2 inches and each disk can rotate up to 20 degrees. Fiber rope is used for motion which allows the cable to be in tension at the center position thus reducing the dead zone at the straight ahead position. Opposite cables act in pairs, pull in cable on the inside of the curve, let out cable on the outside of the curve, chain and sprockets are used to synch the opposing pulleys. Springs have been attached for giving rigidity and support to the segment.

Electronic Components


We used the COPAL 60:1 gear motor, it is a high power, light weight and very efficient motor. The main reason for selecting this motor was the high amount of torque it can provide. The operating range is 6-18volts. We carried out all the tests and calibrations using 12 volts and duty cycles of of 25%, 50% and 100%.


We used a Bourns single turn 10K potentiometer for getting the feedback signal


We used the LMD18200 3A, 55V H Bridge. One H bridge is used to control one motor. Three main signals are being sent into the H Bridge which is the PWM, the brake and the direction bit.


We modified the Opto Isolator circuit provided to us by Professor Bruce Land for the Lab exercise number 5. Three opto isolator circuits were required per motor: one for the brake signal, one for PWM, and the other one for direction.
Schematic showing PWM signal being fed into the H-Bridge through the opto-isolator

Wiimote and LEDs

Multiple PID motor controller (with Wiimote!) using Atmega32
The Nintendo Wii remote has a built in IR camera, which senses IR radiation from our IR LED circuit and calculates the position coordinates using triangulation method. The data from the Wii remote CPU is sent to the computer via Bluetooth. Since we couldn’t find enough IR LEDs in the lab, we borrowed a Wii β€œsensor” (really just ten LEDs hidden in a shiny black box) from a friend.

Parts List:

Total Cost: β€” β€” $44.50
H Bridge- LMD18200 2 $12.00 per unit $24.00
H Bridge Holder 2 $1.50 per unit $3.00
Wiimote 1 Borrowed – Free β€”
Wiimote IR Sensor 1 Borrowed – Free β€”
Custom PC Board 1 $4.00 per unit $4.00
Atmel Mega644 1 $8.00 per unit $8.00
Small solder board 2 $1.00 per unit $2.00
Resistor 330 ohms 6 Free – ECE4760 β€”
Resistor 10K ohms 6 Free – ECE4760 β€”
Resistor 1M ohms 6 Free – ECE4760 β€”
Optoisolator – 4N35 6 Free – ECE4760 β€”
Connecting wires – Free – ECE4760 β€”
Max233CPP 1 Free – Sampled from Maxim β€”
RS232 connector 1 $1.00 per unit $1.00
Sip or header socket/plug 40 $0.05 per unit $2.00
DIP socket 1 $0.50 per unit $0.50

For more detail:Β  Multiple PID motor controller (with Wiimote!) using Atmega32

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top