Introduction: How to Make a Wheel Encoder

I am designing a robot.

I have chosen to use DC motors. So I needed encoders to control these motors.
For doing so I designed an encoder and developed the associated software.

The electronic is very simple and the software designed to be easy to used.

You want to know more about localization ? Here is an article on how to combine artificial intelligence and ultrasounds to localize the robot

Here is a new version and more exhaustive version of motor control

Step 1: How Does It Work ?

The encoder is made of:

  • a little wheel with some holes regularly spaced This wheel is added on the wheel shaft
  • one infrared emitter and one infrared receiver on each sides of the wheel aligned with the holes some
  • a few electronic components that detect each time the receiver see the emitter thru a hole
  • it is up to the software to count the number of holes and deduct the move.

Step 2: Let's Do the Electronic

Firstly we need some very cheap components

  • IR emitter and receiver (I found 20 for 1.79€ on aliexpress)
  • 1 x Mg ohms 1 x 10k ohms resistors 1 x 150 ohms resistor
  • 1 NPN transistors (I used BC547)
  • optionally for power switch
    • 1 NPN transistors (I used 2N222A )
    • 1 x 5 volts regulator

The resistor values may have to be adjusted to fit with the IR components you will get and voltage you will choose

If you will power on with a battery it is better to be able to switch IR emitter power to reduce power consumption

Secondly test on a breadboard

  • set the components according to breadboard picture
  • check the voltage you get on the transistor output
    • it can be done with the following Arduino sketch or with a voltage measurement tool
    • you must get around 4 volt in case there an obstacle between emitter and receiver and 1 volt in the other case. obviously i depends of the distance between the 2 IR components

#define powerSwitchPIN xx // digital PIN
#define encoderInput Ay // analog PIN

void setup() {

pinMode(powerSwitchPIN, OUTPUT);

Serial.begin(38400);

digitalWrite(powerSwitchPIN,1);

}

void loop()

{

Serial.print(float(map(analogRead(encoderInput),0,1023,0,500))/100);

Serial.println(" volt"); delay(1000);

}

At last do some solder

  • On one side IR emitter and receiver
  • On the other side resistors, transistors and wires

Step 3: It Is Time to Work on the Software

I developed a library for Arduino that is free of usage.
Software is designed to handle from 1 to 4 decoders simultaneously. It works asynchronously of the main code. The main code has to initialize some parameters and then can start the encoder control independently of each others . When a requested threshold expressed in number of holes will be reached the main code will be interrupt by the library code and will be able to act accordingly.

The software can be download on Github

WheelControl.h contains the library usage documentation

example/framework.ino helps to start with this library