Smart Motor Driver for Robotics

This motor driver is able to control a motor using PID by I2C.
Taking precise control of a motor have never been so easy.

Similar projects worth following
This is a smart motor driver (aka SAMI) designed to run a micro gearmotor, the objective of this board is to be able to implement a PID control over this motors with the corresponding RPM feedback. All required components are already on board, so it is capable of do the work by itself. Just supply power and send orders by I2C!!!

The host controller will communicate by I2C in order to give the commands to SAMI, this includes speed and direction of the motor. The module will automatically implement the PID control. So your host controller can just relax while this board takes care of the motor. Also you can read the status of the motor and set configs.

SAMI is capable of driving the motor for a desired distance and then stop when is reached. This will be ideal in robotics and simplify a lot of hard work making precise movements. Multiple modules can be connected on a single bus.

Making advanced robots has never been so easy to anyone!!! Just solder the module to your motor.

This is a smart motor driver designed to run a micro gearmotor, the objective of this board is to be able to implement a PID control over this motors with the corresponding RPM feedback using a hall effect sensor. So it must have his own microcontroller and H bridge on board to be capable of do the work by itself.

The host microcontroller (or any system that can use I2C) will communicate by I2C in order to give the commands to the smart driver module, this includes speed and direction of the motor. The module will automatically implement the PID to maintain the speed and apply more/less power in the motor to archive that.

Also the control module will be capable of driving the motor for a desired distance and then stop when is reached. For doing that you must specify the diameter of your wheel and the gearbox relation.

To sense the speed of the motor we will be using a magnetic encoder disk, it is polarized along the surface of the disk. So the hall effect sensor can detect the changes in the magnetic field of the disk and send the signal to the microcontroller. Then using the timer and interrupts we will calculate the RPM of the motor in second plane, so the microcontroller is free to run a PID control algorithm and handle the communication with the host. 

The main idea is to use it in robotics, so by using this modules to control the wheels of the robot it can be possible to make precise movements no matter the surface , the battery charge or even if the robot changes its weight!!!

Also it protects the gears from stripping due to a sudden acceleration or braking and will avoid the battery to trip the protection circuit caused by a current rush. 

This is a project under development, so please follow me get updates :) This is an open source project, so if you have any ideas to improve it you are welcome. Also you can adapt the hardware to run a bigger motor!!!

I2C Memory Map.xlsx

In this excel file I show you all required register to interact with SAMI directly. Also control modes are explained on sheet 2 of this document.

sheet - 24.95 kB - 09/09/2018 at 18:43



Bill of Material from Digikey, this corresponds for the second revision that uses 12F1840 instead of 12F1822. For more details go to the materials section.

ms-excel - 1.05 kB - 06/26/2018 at 01:02



Schematic of the SAMI board in pdf format. For PCB files get it on EAGLE from the Github repository. Gerbers also included.

Adobe Portable Document Format - 15.70 kB - 06/01/2018 at 17:29


  • 1 × PIC 12F1840 Pic microcontroller
  • 1 × DRV8838 H-bridge motor driver
  • 1 × TLE4946-2K Hall effect sensor
  • 1 × SM05B-SRSS-TB(LF)(SN) JST 5 Position and 1mm pitch SMD connector
  • 1 × Magnetic Encoder Disc from Pololu Used to send the magnetic signal to the Hall effect sensor

View all 10 components

  • Arduino library now available

    Danny FR3 days ago 0 comments

    Today the Arduino library for SAMI got approved and added to the library manager in the Arduino IDE.  The project is moving forward to be successful, just a little bit more testing. 

    Tomorrow I will be receiving more motors and other stuff to build a new robot with 4 independent wheels. Using tracks was not a good idea, they have to much friction and turning with the robot precisely is almost impossible because the tracks slip on the floor. I also need to add a IMU in this case, but for my demonstration that is not valid. Robot must be capable of moving perfectly just by using the Smart Motor Driver.

  • Beta prototype ready

    Danny FR6 days ago 0 comments

    Last weekend I have been testing what it's seems to be the first fully working prototype and fixing some bugs. Now SAMI is alive and fully capable of what I promise. In the next weeks I am going to do more test and after I have confirmed everything is as it should be I will sell some units on Tindie for beta testers. I would like to hear your thoughts and how we can make it better.

    In the video I show SAMI - Smart Motor Driver moving 1 exact meter in a practically perfect straight line at exactly 80 RPM with just 10 lines of code(thanks to the Arduino library). You can connect everything in a couple of minutes and you can have up to 128 motors in the same I2C bus:

  • Releasing Arduino Library

    Danny FR09/09/2018 at 18:42 0 comments

    Good news the Arduino library for SAMI is here, it is still on beta testing but it works. The Github link is now added to this project documentation and will be released on Arduino Library Manager in a few days after some more testing. Enjoy!!!!

  • Final module functions

    Danny FR09/08/2018 at 20:00 0 comments

    Today I have finally done analysing what functions will be the most popular and common in almost any application scenario. And i have got this, the I2C register map listing all possible configurations and required parameters in SAMI: 

    And also this are going to be the driving modes:

    Of course there will an Arduino and Python libraries for easy using of SAMI. 

    Next week I will show you the finished project, so keep tuned in!!!

  • Putting all code together

    Danny FR09/05/2018 at 00:55 0 comments

    For some time I have been experimenting a lot with I2C communications and PID motor control, however I was running this experiments by separate. But now it's time both worlds meet and live together. Today I proudly present the prototype working all together as promised.

    There is still things to do and a few tweaks before I can say it's done, but I am almost there. Just a little bit more of patience. In the next video I have attached two SAMI's for showing you that it works and also ask your opinion about the two different ways to do a direction toggle. Which one do you think is better? Please leave a comment with your opinion.


  • Make your own SAMI!!!

    Danny FR08/20/2018 at 03:56 0 comments

    Hi, I want to share with you this video. In it I explain how to assemble the pcb, is not a high quality video but you will get the idea.

    PD: sorry for the bad pronunciation and some drafting errors, I got nervous :/

  • More components, more boards

    Danny FR08/14/2018 at 22:30 0 comments

    Finally after almost two months waiting for the parts they have arrived. So I am making more boards with the PIC 12F1840 update. So no more space limitations and I can continue developing the software. Also I am working in a video showing the assembly process for the curious!!!

  • Thinking about manufacuring

    Danny FR08/05/2018 at 22:43 0 comments

    Well, one of the purposes of this project is to make it available to the public. However it may be so difficult to ask everybody to make their own board. Because some parts are pretty small and require a little bit of experience doing SMD soldering before trying to make this boards.

    It will be a waste if I let that happen, I want that everyone can use this in their robots and all kinds of projects. So they can benefit from the advanced control available for motors in this board put right in their hands in an easy to use and practical way.

    I make a quotation on Digikey and some other providers in order to calculate the selling price of this. In the table below you can see the price for each part and some other costs. However it will be some more cost hidden, but for now this will give us an idea.

    This prices are only for a small batch of 25 boards, the cost is per board. So $16.36 selling price seems cheap enough, but surely it can be improved building at least 1000 boards!!! 

    I will need to do my best for making it as cheap as possible and make it available for everyone :)

  • "Pass the butter" demo robot finish

    Danny FR08/02/2018 at 22:35 0 comments

    In the past log I started working on a robot that would be used for my video and also demo the Smart Motor Driver (SAMI) in a real life application. Here are the results :)

    I am using a Pololu track set, a custom made laser cut chassis an a bit of cardboard. Now I can ask the robot to pass me the butter ;)

    The robot doesn't have any sensor or communication with the outside world. It would navigate a maze completely using pre-programmed distances on the smart motor drivers.

    This will be the maze for my demonstration:

  • Still waiting parts

    Danny FR07/30/2018 at 18:51 0 comments

    So today I am still waiting the parts to continue the project, however meanwhile I am making a simple robot for a demonstration of the capabilities of SAMI (Smart Motor Driver). This robot is just to be a simple one, the only thing used will be the Smart Motor Driver, an Arduino and the battery. 

    The base is designed to use two motors and their tracks, here is a preview of how it will look. 

    And am thinking in adding a comic appearance, so I can ask it to pass the butter :)

View all 25 project logs

  • 1
    Gather all the parts

    The first thing you wanna do to build your own is to get all the parts. Please go to github and download the eagle files of the board. You can upload directly the design to Oshpark, if you want to use another manufacture service you will need the gerber files. Board must be 0.8mm thick!!!

    Now purchase all the parts, you can get it on Digikey, but be careful when selecting the size and the case style. Make sure everything is correct and in the right size. The BOM is attached here, just download it for easy ordering.

    Optionally order the stencil, it will save you a lot of time and frustration when soldering. You can get one on Oshstencils. 

  • 2
    Solder all the parts

    Apply solder paste to the board using the stencil. Now put the SMD parts in place, make sure to put it in the right way. Check where and how the parts go using the EAGLE board files. Then you can solder it using hot air or a reflow oven. Just be careful, it's pretty easy to make a mess with this tiny components.

    Finally solder the motor in place making sure is centered to the shaft hole, then put the encoder disk in place.

  • 3
    Burn the firmware

    Now using a PIC microcontroller programmer (like the Pickit 3) burn the supplied firmware into the board. I used pogo pins to make the connection between the board and the programmer.  Check ICSP pin order on the EAGLE files.

    Remember this project is under development, so I will be changing and updating the firmware until it supports all the functions wanted.

View all 4 instructions

Enjoy this project?



peter jansen wrote 08/04/2018 at 06:59 point

This is a great project!  I was interested in doing something similar with these micro gear motors a year or two ago -- it turns out they're much less expensive if you get them directly from China (e.g. ).

  Are you sure? yes | no

Danny FR wrote 08/04/2018 at 17:54 point

Thanks, if I can help in some way just let me know! 

Great tip :)

  Are you sure? yes | no

peter jansen wrote 08/05/2018 at 04:47 point

One of the things I was trying to work on is how to create essentially a linear servo or square-shaped piston using these motors, with the caveat that it had to be as small a square with as long a throw as possible (at least 4-6 inches), to try and make one of those pin-bed displays like from one of the x-men movies, where they essentially combine thousands of linear actuators to make a variable height map.  But to make it happen, you'd have to make them /really/ inexpensively, likely sub-$5 each, and ideally REALLY inexpensively, in the sub-$2 range, so that you can build literally thousands of them.   I have almost completely shelved the idea, but it's an interesting use case to think about when trying to make inexpensive actuators such as this. 

  Are you sure? yes | no

Danny FR wrote 08/05/2018 at 22:28 point

Sure, they definitely can be used to create a linear servo with a square shaped piston to make a pin-bed display. The simplest , cheaper and compact mechanism I can imagine at the moment is a thread rod and a nut attached to the base of piston with motor at the end and a limit switch for first calibration at start up. Them motors can use this driver to track and set the desired position of the piston. 

However it won't be so cheap, maybe something around $20 per piston. I would be interesting to make a quotation for some thousands units and see how much the cost lowers. But surely a prototype and a lot of experimentation will be necessary before thinking in mass production.

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates