element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Personal Blogs
  • Community Hub
  • More
Personal Blogs
Frank Milburn's Blog Testing DC Motors on a Robot with DIY Rotary Encoders
  • Blog
  • Documents
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: fmilburn
  • Date Created: 1 Mar 2021 5:30 AM Date Created
  • Views 7998 views
  • Likes 13 likes
  • Comments 23 comments
  • motor control
  • robot
  • encoder
  • rotary encoder
  • arduino
Related
Recommended

Testing DC Motors on a Robot with DIY Rotary Encoders

fmilburn
fmilburn
1 Mar 2021

EDIT  2 Feb 2021:  Added explanation for poor matching of motors

 

I have an ongoing project to develop a robot which will use a Raspberry Pi for the main brain and I2C communication with a microcontroller for real time activities such as PID control of motor speed.  Links are given at the bottom of this post describing the implementation of I2C communication between a Raspberry Pi and Arduino, and PID (only proportional and integral are used) motor control on an Arduino.  Here I'll describe adding DIY rotary encoders to a tracked robot not originally so equipped.

image

How It Works

 

The sensor used here is the ITR9608-F, an opto-interrupter consisting of a infrared emitting diode and an NPN silicon phototransistor encased in a thermoplastic housing.

image

The robot did not come with encoders so a wheel with 16 equally spaced slots was designed in Fusion 360 and printed in PLA.  As the openings pass through the slots in the opto-interrupter they trigger the photo-transistor and cause the sensor to output a digital high signal.  When occluded the sensor outputs low.  The photo below shows how the encoder wheel fits onto the tank cog.  It was necessary to modify the slot at 12:00 to allow the screw to be tightened on the cog.

image

Here the encoder wheels are shown installed on the robot without the opto-interrupter in place.

image

A simple circuit is used to interface the ITR9608-F opto-interrupter to the microcontroller.

image

Resistor R1 provides current limiting to the infrared LED.  When the light from the LED is occluded by the encoder wheel resistor R2 pulls the output low.  When the light from the LED can reach the phototransistor it turns on and the output is high.  The circuit was built on a bit of stripboard and a 3D printed mount designed for attaching to the robot.  Testing was done with the Arduino connected through a breadboard to the motor controller and the prototype encoder wheel was reprinted in black PLA although the white ones would have probably been just fine.  It was a rainy day in Portland.

image

Testing

 

This is a new robot built from a kit (DFRobot Devastator) and the motors haven't been run in.  I took off the tracks and put it on a box so it couldn't go anywhere for the tests which consisted of increasing the PWM duty from 20% to 100% in steps of 3.9% with the motors unloaded.  Three runs were made and are shown plotted below.

image

The importance of PID control with feedback for good motor control is apparent:

  • Responses between the two motors differ
  • Responses are not linear
  • Responses vary somewhat between runs

 

We could expect additional variation to occur as the motors experience different loadings, the battery voltage output changes, the motors age, and so.

 

EDIT  2 Feb 2021:  The poor matching of the motors is caused by the Arduino Uno used during these tests putting out different PWM frequencies (but not duty) during the tests shown in the plot above.  See comments below for further detail.  Performance improves greatly when two output pins using the same PWM output frequencies are used.

 

Sensor PCBs

 

I suppose I got in a hurry with the PCBs.  Electrically they are OK but I forgot to move the footprint I had crafted to the back side of the board.  As a result the 0805 surface mount resistors press against the mounts for the sensors so I will reprint the mounts with little indentations or drill indentations to accept them.  I installed the sensor below backwards before figuring out what I had done wrong.  Doh!

 

image

Conclusion

 

I'll modify the KiCad files for the sensor PCB but use the ones I have for now.  The next step is to design mounts for the microcontroller, Raspberry Pi, batteries, a PCB for power distribution and the motor controller, and so on.  The plan is to have something working by next summer for Robot Summer Camp with the grandkids.  Thanks for reading - comments and thoughts for improvement are always welcome.

 

Past Links to this Project

 

Simple Arduino DC Motor Control with Encoder, Part 1

Simple Arduino DC Motor Control with Encoder, Part 2

Raspberry Pi and Arduino I2C Communication

  • Sign in to reply

Top Comments

  • neilk
    neilk over 4 years ago +4
    Nice post, Frank. Very interesting to see the different behaviour of the 2 motors; without some sort of balancing - PI D - would be difficult to get this beast to travel in a straight line. Neil
  • fmilburn
    fmilburn over 4 years ago in reply to genebren +4
    OK, ran it again and then swapped the connections to the motor controller and got the following counts (settings slightly different than yesterday): Original Duty Right Left 49% 77 91 98% 122 121 Swapped…
  • shabaz
    shabaz over 4 years ago +3
    Hi Frank, This is really nice to see the custom work for the encoders. I worked on a transceiver project where the engineers created a similar solution for a custom frequency control dial. It was super…
Parents
  • three-phase
    three-phase over 4 years ago

    Nice blog, I wonder if it would be possible to measure the friction of the motors in a mechanical manner for a comparison.

     

    Kind regards.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • fmilburn
    fmilburn over 4 years ago in reply to three-phase

    That is a good question.  Mechanical friction isn't an area where I have deep knowledge.  They are gear motors so I could try removing the gear heads and see what the current draw is with and without them.  I have an LCR meter and took some readings just now with everything intact and also made some current measurements.  I don't really understand how to interpret them.  Keep in mind these are all unloaded measurements - that is the motors are turning the cogs freely without the tracks attached.

     

    Current                           Right         Left

    50% Duty Cycle              71 mA      83 mA

    100% Duty Cycle            97 mA      97 mA

     

    LCR Measurements at 100 Hz

                 Right              Left

    R          2.14 Ohm       3.12 Ohm

    X          1.66 Ohm       1.66 Ohm

    L           2.64 mH         2.66 mH

    Theta   37.8 deg         28.2 deg

     

    LCR Measurements at 1000 Hz

                 Right              Left

    R          4.09 Ohm       5.00 Ohm

    X          15.6 Ohm       15.6Ohm

    L           2.48 mH         2.49 mH

    Theta   75.3 deg         63.3 deg

     

    These are the kind of rabbit holes you can fall down when you can't accept that something just works.  I haven't decided to pull the gears off yet :-)

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • fmilburn
    fmilburn over 4 years ago in reply to three-phase

    "The problem with using the current is that there is still a mixture of electrical and mechanical losses - its getting more and more complicated”

     

    Agreed!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • genebren
    genebren over 4 years ago in reply to fmilburn

    A relatively simple way to isolate the electrical aspect of the speed difference at 50% would be to swap the connections on the motors (left/right swap) and then to repeat the speed tests.  If the speeds (RPM) change then the issue is electrical.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • fmilburn
    fmilburn over 4 years ago in reply to genebren

    OK, ran it again and then swapped the connections to the motor controller and got the following counts (settings slightly different than yesterday):

     

    Original    Duty          Right          Left

                     49%          77             91

                     98%        122           121

     

    Swapped   49%         93               77

                      98%       121            122

     

    So it does give different results depending on which motor controller channel it is on.  I have a second motor controller and since things are still on a breadboard they were easy to swap out.  I get essentially the same results with the second motor controller.  So, it is not the motor controller.  I checked the wiring and it seemed OK which left the Arduino PWM going to the motor controller?  Here is a screen shot from my oscilloscope:

     

    image

    I find this bizarre.  Why would the Arduino use different PWM frequencies for the output channels?  I looked it up in the Arduino reference and sure enough this is what it says:

    Uno, Nano, Mini

    3, 5, 6, 9, 10, 11

    490 Hz (pins 5 and 6: 980 Hz)

     

    I guess that could be it.  This is one of the problems of using the Arduino functions without a deeper understanding of what they are doing.  I moved the PWM output pin on pin 5 to pin 11.  Here are the results.

     

    Original    Duty          Right          Left

                     49%          90             93

                     98%        122             119

     

    So it is working much more reasonably now.  It also seemed strange that PWM frequency would make that much differenced to the motor controller even though the duty was the same.  The driver is a DRV8833 and looking through the datasheet real quick didn't see anything but I should read it more carefully.  I am going to modify the blog.

    • Cancel
    • Vote Up +4 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • fmilburn
    fmilburn over 4 years ago in reply to genebren

    PS:  should have listened to you the first time on this :-)

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • neilk
    neilk over 4 years ago in reply to fmilburn

    Hi Frank,

     

    I once got tripped up by the 2 different PWM frequencies. Glad you sorted yours out image

     

    Neil

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • neilk
    neilk over 4 years ago in reply to fmilburn

    Hi Frank,

     

    I once got tripped up by the 2 different PWM frequencies. Glad you sorted yours out image

     

    Neil

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube