Monday, April 11, 2011

[Youtube] Nunchuk + DC Motor Controller demo

The motor controller now works in one direction. See the Youtube video below for a demonstration:

Saturday, April 9, 2011

Forward direction + brake works

The controller works in the forward direction. Speed control and braking works. Pictures and videos will be uploaded soon.

So far I have been following's h-bridge design. However, it requires AND gates. After attempting it in the lab today, I'm now abandoning that idea. It takes too many wires to do it, and the logic can be programmed in the Arduino. With this new philosophy, all of the logic will be handled by the Arduino. The number of output lines from the Arduino to the H-bridge will increase from 3 to 4, but the overall amount of wiring will decrease, and so will the overall footprint.

H-Bridge Controller Prototype

I've built a prototype program for controlling the H-Bridge. It should be able to do forward and reverse with braking and direction switching. There is no safety feature for direction switching, so you must manually slow down before you do it. Tomorrow everything will be hooked up. Something is guaranteed to blow up, but hopefully it's not the Arduino or the Nunchuk.

Friday, April 8, 2011

Youtube video and pictures

I finally have some pictures and stuff to post.

Here's a Youtube video of the Nunchuk, Arduino, and LED display working together:

Wednesday, April 6, 2011

7-Segment Serial Display from Sparkfun

The 7-Segment Serial Display from Sparkfun came in the mail today. Arunet has a good guide for this product: Here's some notes.

- After using it for about 4 minutes the brightness went down. Do this to get it back to maximum brightness:


- Changing the baud rate was a little tricky. Sending it "127" and then "4" doesn't work, nor does "1276." I did:


And finally it changed the baud rate to 19200.

- If it starts showing dots when you don't want them, do this:


and the dots should go away.

Monday, April 4, 2011

LED Display Ordered, Hardware assembled

Checked out a DC motor today from school, and got the H-bridge from my ex-lab partner. Also ordered the LED display from the previous post.

Saturday, April 2, 2011

LED Display and Over-current Protection Ideas

I am considering buying an LED display for this project. It would be used to display the value of the PWM signal sent to the H-bridge, as a percentage (i.e. the duty cycle). This would be good because I wouldn't have to use the Serial port on my computer to monitor this value. This 7-segment, 4-character LED display from Sparkfun looks good:

There's a good tutorial here: on how to use it. This particular display can use both NewSoftSerial and SPI, but apparently there is a bug in the SPI implementation:

Over-current protection is still a problem. I need some sort of feedback. Implementing it will cost money. It's not that expensive (Sparkfun sells one:, but I'm running out of cash to spend. I'll probably have to settle for some auto-delay function when you switch directions, that will automatically slow the motor down before you apply counter-current.

Friday, April 1, 2011

More Nunchuk Action

Test code up and running. Speed control, braking, and direction switching coded. Motor is not yet hooked up. Direction switching will have to be idiot proof.

You should to decelerate to zero (or close to it) before you switch, or else the motor literally jumps. it's hard to guarantee this without feedback from the motor. For now a delay/deceleration time of 3 seconds has been coded in. The applied voltage is slowly brought down to zero, and then the motor freewheels during this time. This time should be set to the worse-case scenario (initiating a direction switch while going full speed), which will be determined when the motor is hooked up.

The Nunchuk is working fine. I did have a problem where it wasn't communicating with the Arduino for a while. I discovered that the Nunchuk adapter must be soldered to wires or a header for the connection to be reliable. For now I just use my fingers to hold the header to the adapter, but eventually it needs to be soldered together. I might have to order another adapter in case I don't solder it right.

Wednesday, March 30, 2011

Early Development

I plan to update as the project develops, but so far I haven't been keeping track. So here's the highlights so far.

Phase 0
Got an idea to improve the final project. Began investigating how to implement digital logic and how to hack a game controller. Found out what the Arduino does and how people hacked PS2 controllers.

Originally I thought PS2 controllers would be good because they are widespread, which means people are familiar with them and there are many 3rd-party (cheap) controllers. I also thought since they were older, there would be more information on the internet on how to hack these. I assumed that the newer controllers would be too high-tech to use, and too new for anyone to have a good way of hacking them. These assumptions turned out to be pretty bad (for reasons probably discussed later).

Phase 1
Ordered the Arduino Uno, PS2 Dualshock 2 (non-Sony AKA non-OEM), and accessories from Began to read Bill Porter's website on how to hack a PS2 controller: He goes into a lot of detail and has a Arduino library to boot.

Phase 2
Found out that Nintendo (Wii) Nunchuks are very easy to interface with an Arduino. The Nunchuk communicates over I2C, which the Arduino is capable of reading directly. Tod Kurt invented an adapter that is super easy to use: He also lists a corresponding Arduino library. I order an adapter ($4 from, free shipping!) as backup in case the PS2 doesn't work.

Also found out that people using non-Sony PS2 controllers were having a lot of trouble using them with Arduinos. In retrospect I should have invested the extra ~$4 and bought an authentic Sony PS2 controller.

Phase 3
Attempted to crimp wires from the PS2 to the Arduino, and didn't get it to work. Tried to solder the wires but they are very thin and weak copper wires, and hard to solder. Bought a Nintendo Nunchuk and hooked it up to the Arduino using Tod's adapter and got some test code ( working. Tested the accelerometers, Z, and C buttons. I had a lot of trouble getting the Arduino to print values to the serial monitor but eventually got it to work. Here's an example:

// This program prints out something when you press the z button.

#include <math.h>

#include "Wire.h"
#include "WiiChuck.h"
#include "nunchuck_funcs.h"

#define MAXANGLE 90
#define MINANGLE -90

WiiChuck chuck = WiiChuck();
int angleStart, currentAngle;
int tillerStart = 0;
double angle;

void setup() {


  Serial.print("Setup done!");

void loop() {
  if(chuck.zPressed()) {
    Serial.println("Zbutton pressed");
  else if(chuck.cPressed()){
    Serial.println("cButton pressed");


This blog is to record the development process of an electronics project. The goal of this project is to improve a DC motor controller that was originally produced in a University of Washington class.


A final project from my University class, a motor controller, enabled a DC motor to brake, change direction and adjust speeds. Although this was completed, the analog user interface and logic system were  suboptimal because of excessive wiring and inefficient use of space. A microcontroller would streamline logic processes and save space, while an interfaced gaming controller would be highly user friendly. These upgrades will be attempted.

Specs of DC Motor, logic, and control system:

-27 V DC Motor with MOSFET H-bridge, optocoupled to logic (Will likely be tuned down to ~18 V for presentation)
-Bidirectional rotation
-Speed control
-Dynamic braking, possibly counter-current braking
-User interface: Nintendo Nunchuk or Playstation 2 Dualshock
-Logic: Arduino Uno (AT MEGA 328 micro-controller) 

Motivation (Problem Statement)

The original logic design was based on a multiplexer array. Each multiplexer was fed 4 input signals and were switched based on two more signals. Also, extra features such as slow-start (using RC circuits) were hard-wired into the board. This lead to a very complicated board. An alternative is to use a microcontroller. The Arduino Uno is a microcontroller board that is easily programmable and easily interfaced with other hardware. It has enough computing power to act alone as the logic component. Using the Uno will save space, and it will be easier to customize.

Similarly, the user interface was based on analog components such as dial-potentiometers and switches. This lead to a very messy design; many wires had to be soldered and there was no central box containing all the controls. A gaming controller such as a PS2 Dualshock or Nintendo Nunchuk will be interfaced with the Arduino to provide a more user friendly environment.