DIY Encoded Pulley and Guide to Make Encoder With Hall Sensors & Magnets
by gokux in Circuits > Electronics
1222 Views, 14 Favorites, 0 Comments
DIY Encoded Pulley and Guide to Make Encoder With Hall Sensors & Magnets
I am currently working on a project (cable cam), that need-to-know rotation position of a rope pulley. this pulley rotated at a high rpm, so it didn’t need an expensive high-resolution encoder. then I decided to build my own encoder using magnets and hall sensors, which is cheap and easy to build .in this instructable we will talk about how it works and how to make it .with the same design principle you can make your own encoder to incorporate with your design. Also, it is my first instructible! So, let’s begin.
What is a rotary encoder?
rotary encoders translate rotational movement into electrical signals for more precise control, incremental encoders produce alternating high and low pulses as rotation occurs, which may indicate the speed and direction of the rotating object.
here is a useful video about the encoder
and how it works.
Our encoder has a disk with evenly spaced alternative pole magnetic zones and two other separate hall Sensor’s output pins A and B,
Hall effect sensors like these are designed to give a logic level output when they are near a magnetic field. The output is high (logic 1) for a North pole and low (logic 0) for a South pole. This response can vary depending on the model of the sensors.
The ah44e sensor connects the output to GND if the magnetic field perpendicular to the chip surface exceeds a certain level and opens that switch if it falls below a level (=Open Drain). These two levels are different, hence avoiding noise in case the magnet field is exactly at the switch level (=Hysteresis). As a result, the sensor board can be quite simple. Power between 4.5V-28V is provided - and a capacitor nearby the chips is needed. The output signal of both is connected directly to Arduino.
When the disc turns, the two sensors change state as the magnetic poles move past. High for a North Pole, low for a South Pole. Because of the careful placement of the sensors, the two signals overlap in a clear pattern.
By examining the sequence of signal levels, A and B, Arduino can work out how speed, direction, and position of the rotation. With 20 magnets, there will be 40 changes in the combined signals as the motor makes one complete rotation. If only one of the channels is examined, you can only 20 changes per rotation. Also, there would be no way to know what direction the motor was turning. In my build, I have 20 magnets, so I will 40 count per rotation (CPR), If there are more poles, then you can detect more changes and the resolution of the encoder increases.
The important things to make sure are.
- It should be clear that there must be an even number of poles so that there are changes from North to South and back ( 2, 6, 10, 14, 18,. . . magnets.)
- The hall sensor does switch on and off reliably, meaning the magnetic field must rise above and fall below the thresholds for sure.
- The two hall sensors have a delay between switching on/off as this delay tells the rotation direction. If both would switch on exactly the same time, no rotation direction can be derived.
Supplies
- 20x Neodymium Disc Magnets 3x3mm
- 2x AH44E hall sensor
- Connecting wire
- Arduino nano (clone)
- Breadboard
- 3.5" Universal Bearing Pulley Wheel
- Ribbon cable
- Kapton tape
all ebay link
Modeling Magnetic Disk and Sensor Holder
We need to make a magnetic disk that will hold our 3mm magnet to the pulley, also we need to find a way to attach the hall sensor, so let's measure all dimensions
I already provided the .3fm files of this design, but if you are still curious about how I designed it, follow these steps. I only provided instructions to design the magnetic disk, and a time-lapse of the Sensor holder design due to space constraints. it is only to show how easy it is to go from an idea to a prototype in Autodesk Fusion 360
it is time to fire up Autodesk Fusion 360,
- create a new sketch and draw 45mm and 60mm circles
- select the outer circle and using the extruder tool extrude it to 3mm
- create a new sketch on the top of the disk and draw a 52.5mm circle
- draw a 3mm circle on the line of the 52.5mm circle
- using the circular pattern future in Fusion 360 create 20 circles around the disk, select a 3mm circle as the object, and select the center point
- delete the 52.5mm circle and extrude the rest of the plate to 3mm
- select the body > right click>save as mesh using this method you can convert the body to a .3MF/.STL file
This is how easy it is to bring your ideas to reality with Autodesk Fusion 360
Magnetic Disk
After 3d printing the design we need to insert 20 magnets into the 3mm holes .make sure the magnets are inserted alternating north/south poles, you can use vise or pliers for inserting. after that fix the Magnetic Disk to the pulley
Downloads
Hall Sensor Holder
it is used to fix the hall sensor in the correct position and Hight, The important things to make sure when placing Hall Sensors are
- The hall sensor does switch on and off reliably, meaning the magnetic field has to raise above and fall below the thresholds for sure.
- The two hall sensors have a delay between switching on/off as this delay tells the rotation direction. If both would switch on exactly the same time, no rotation direction can be derived.
we need to bend the Sensor leg in Z or L shape and fix the hall sensor with hot glue in this case, I melted a PLA filament on top of it, making sure the sensor is not touching the magnet, a minimum of 5mm distance is needed between sensor and magnet, also the flat side of the sensor need to face the magnets
Downloads
Wiring Up
wire up using this circuit diagram, also need to add a 0.1uf capacitor near the +Ve and GND of the sensor, I also used a 4-wire ribbon cable to bring the signals to the microcontroller. this ribbon cable is fixed using an insulation tap/koptan tap
Testing
for testing the encoder we need to connect it into an Arduino
PINOUT
- +Ve------5v
- -Ve-------GND
- A---------D2
- B---------D3
Code
volatile long temp, counter = 0; //This variable will increase or decrease depending on the rotation of encoder
void setup() {
Serial.begin (9600);
pinMode(2, INPUT_PULLUP); // internal pullup input pin 2
pinMode(3, INPUT_PULLUP); // internalเป็น pullup input pin 3
//Setting up interrupt
//A rising pulse from encodenren activated ai0(). AttachInterrupt 0 is DigitalPin nr 2 on moust Arduino.
attachInterrupt(0, ai0, RISING);
//B rising pulse from encodenren activated ai1(). AttachInterrupt 1 is DigitalPin nr 3 on moust Arduino.
attachInterrupt(1, ai1, RISING);
}
void loop() {
// Send the value of counter
if( counter != temp ){
Serial.println (counter);
temp = counter;
}
}
void ai0() {
// ai0 is activated if DigitalPin nr 2 is going from LOW to HIGH
// Check pin 3 to determine the direction
if(digitalRead(3)==LOW) {
counter++;
}else{
counter--;
}
}
void ai1() {
// ai0 is activated if DigitalPin nr 3 is going from LOW to HIGH
// Check with pin 2 to determine the direction
if(digitalRead(2)==LOW) {
counter--;
}else{
counter++;
}
}
After uploading the code to Arduino, opening the serial monitor, and rotating the pulley you can see the value increase if you rotate the encoder in a clockwise direction, and the value decreases if you rotate in the anti-clockwise direction. value showing reverse means giving -ve value for a clockwise motion. You can reverse the “A” & “B” connection.
Final Thoughts
I came up with these Instructables only to have an idea of how to build an encoder, with the same design principle you can make your encoder work with your design, by increasing the number of magnets you can increase the resolution of the encoder. , you can use different SMD sensors and make this encoder even smaller
thanks