My Stepper motor "Analog" speedometer project

Post Reply
User avatar
walterclark
Posts: 1442
Joined: Sun Feb 08, 2009 12:57 pm
Location: Dover, MA.
Contact:

My Stepper motor "Analog" speedometer project

Post by walterclark »

These are the hardware notes I made during this project. The next reply will contain some pics I took.

Arduino based stepper motor speedometer - Walter Clark

The hardware and my notes:

This is what I am using. You can buy all the things I list here from multiple sources. I list where I bought mine. I cant make any promises that these sources will be available when you need to obtain the items on the list. You may find better deals elsewhere depending on when and where you look. Dont ask me about anything I havent listed here related to this project because I probably dont know about them or I would have mentioned them.

This started out as a simple parts list, but there are so many caveats and little things I discovered along the way that might be of help, it has grown into more of an article....Minus the pictures and step-by-step directions. Notice that it does not say Heathkit across the top of this writeup...

The actual cost of the hardware for this speedo retrofit that currently resides in my car is under $20. This does not include the cost of a programming cable I made ($20), which I can reuse for other Arduino projects, the speed sensor that was already in the car ($40) or the extra parts I ended up with or damaged during development.

Micro-controller:

Arduino Pro Mini 328 5V/16MHz. https://www.sparkfun.com/products/11113

Probably, any Arduino micro-controller could work. Other Arduino controllers could also require hardware or software changes from what we did to work or work properly.

I am using the Pro Mini because I developed the project on the Uno R3 SMD and this is the same hardware minus all the development friendly connectors and a USB port but at about 1/3 the price at around $10. You either have to solder everything to this board, or install your own headers, but its extremely small size makes it very easy to include right inside most non-electronic speedometer cases in place of the meter movement and odometer. Soldering everything in place ensures better reliability.

The Uno R3 SMD that I used during developmenthttp://www.amazon.com/dp/B00F6JCV20/ref ... 25410_item will work well but it does contain some unnecessary features and uses connector headers that may vibrate apart under use in a car. The non-SMD Uno R3 module is the same except the processor chip is a plug-in DIP. It is is available at: https://www.sparkfun.com/products/11021 . This could be a good module to have if you want to mess around with Arduino for other projects. It is also about 6 times larger in area and about 10 times taller than the Pro Mini.

I list a stepper shield in this parts list but depending on the actual motor you use it may not be necessary. If the motor you use is the same as the one I used and you have things configured where nothing can interfere with the electrical path from controller to motor (i.e. shorts from one of the controller pins to ground or a voltage over 5V) then I think the shield is unnecessary. If you want to know why, read on. If not skip to the next paragraph. The Uno R3 and Pro Mini processor is a ATMega328P. This processor chip spec's the absolute maximum voltage ratings on the digital IO pins at +5.5V and -0.5V. Directly driving the X27.168 stepper from the micro-controller module pins I measured that the steady output levels from the processor IO pins are 4.3V (high) and 0.4V (low). The inductive kick I observed on the output pins from the motor adds up to .3V positive to the high and .3V negative to the low levels. These result in a peak of 4.6V high and +0.1V low which are well within the margins of 5.5V high and -0.5V low. Also, the motor itself draws under 20ma per pin which is less than half the 40ma per pin rating of the controllers processor chip and the stepper behaves the same when driven from either the controller board or thru the shield I used in development. Drawing current from the IO pins to drive the stepper motor, in theory produces additional heat in the processor chip. On the bench when driving the stepper at maximum rates I saw maybe .5 degrees F rise in the surface chip temperature. I am inclined to ignore the heat effects of driving one of these stepper motors. I used a shield during development but eliminated it for the final product in my car.

I list a USB to Serial TTL adapter in this list but it may not be needed depending on the controller you choose. The Uno R3 already has one as do some of the others. If you picked one with a USB port already or already have a suitable USB to Serial TTL adapter you can use skip the rest of this pararagraph. Otherwise read on. The Pro Mini that I used to build my final speedo does not have a USB pot on it so I needed one. Note that if a USB adapter IS needed and you choose to not have it wired to the controller board all the time you need to take steps to first, protect the serial input and output pins from Electrostatic Discharge (ESD) and second, tie the Rx line to 5V (a 20k Ohm resistor is fine). The processor may be damaged if you were to plug in a cable to the controller and having had some static charge built up on you, discharge that thru the controller as the cable is connected. The USB adapter will prevent this in a couple ways automatically. If its not there it is up to you to provide this. Tying the Rx line to 5V pulls the line up and prevents electrical interference in the car from causing the Rx line to toggle between high and low. While this shouldnt damage the processor or cause it to suddenly reprogram itself, it might cause it to unnecessarily waste some computer cycles handling it.



Stepper shield.

Mini Motor Drive Shield Expansion Board L293D Module For Arduino UNO MEGA2560 R3. Sold by eBay alice1101983. http://www.ebay.com/itm/200982006661?ss ... 1439.l2649
eBay listings change frequency so the URL above will probably be invalid in short order. Thus I included the complete subject line description to help locate it or one similar.

Most stepper shields fall into 2 families. Those intended to drive small motors (up to 600ma) and using the L293D chip and those intended to drive larger motors (up to 4A) using the L298N. For this application the L293D based is more than adequate.
It is possible to find modules that have more than 1 L293D on board. Each L293D will drive a single 2 pole stepper motor like in this project. Boards with 2 or 3 chips will be able to drive 2 or 3 of these motors. That might be a useful option if your project also includes driving something like a stepper tachometer in addition to this speedometer with the one Arduino controller.
You may be able to skip using this “shield” entirely. Read my comments under the micro-controller. If you plan to use the one micro-controller to drive more than the one motor or if the motor you use requires close to the 40ma limit of the micro-controller, you may want to consider use of a shield to offload the motor current demands from the micro-controller.


USB interface.

FTDI USB to Serial TTL . https://www.sparkfun.com/products/9716
NOTICE: THIS IS NOT A USB TO FULL RS232 ADAPTER!! DO NOT USE A USB TO FULL RS232 ADAPTER CABLE!
The Arduino Pro Mini controller above does not have a USB port, which is required to program the controller, but not any other time. Some of the other controller choices like the Uno R3 that I used for development of this project have the USB port feature embedded on the controller board. It is probably the largest single cost/price difference between the Uno R3 SMD and the Pro Mini 5V/16MHz controllers.
Arduino uses the FTDI USB (FT232R UART IC) for its USB interface because the FTDI USB driver set (the part that runs on your PC) is excellent and easily available. Most Windows PC's that have had a USB device connected to it other than a mouse or flashdrive probably already has the driver installed since this chip is so popular. If not, the drivers are easy to locate at FTDI http://www.ftdichip.com/FTDrivers.htm and work well.
The serial interface on the micro-controller board is TTL, that is nominally 0V and 5V and it uses the basic RS232 serial protocol (but NOT the RS232 signal voltage levels). The FTDI FT232R chip is also TTL (or UART compatible) and uses the RS232 serial protocol. Why the warning above?
The FULL implementation of RS-232 includes following the physical layer (the signal and voltage) specifications. In that specification the RS-232 Rx/Tx may be as high as +15 and -15V. These levels will damage the ATMEGA328P processor serial input and otuput pin. True full USB to RS232 adapters (and cables) will have at least +5v and -5V out the Tx line to the receiver.
Some times a TTL level compatible adapter will be referred to as UART, TTL or BASIC. If it doesnt say any of these things it still might be TTL compatible since the cheaper USB to RS232 adapter cable will sometimes omit the level shifting circuits. They can sometimes get away with this because a lot of RS232 ports are OK with seeing just 0 and 5V on the Rx and Tx lines. But not always. My advice is if you dont know dont use it.
Use the one I did above, or look for an FTDI USB to RS232 or Serial but with BASIC, UART or TTL in the description as well. Again be aware that is is a common mistake on the part of sellers to use words serial and RS232 without specifying whether the adapter is UART/TTL compatible or true RS232 physical layer compatible... All these things are “serial” and they are all RS232 as that describes handshaking or signal sequences used and not necessarily the voltage levels in use. The one you want will have the DTR line available. This is used allows the Arduino to auto reset when a new sketch is loaded. Many of the TTL level adapters I found breakout RTS but not DTR.
DTR. Some Arduino micro-controller may not correctly implement a path for the DTR to be correctly recognized by the Arduino and instruct it to do that reset. This is not an issues with the Pro Mini but it may be with others. There are some notes to that effect in the COMMENTS area of the Sparkfun web page for the adapter https://www.sparkfun.com/products/9716. If you are NOT using the Pro-Mini check this and your micro-controller schematic. If its not clear what that means look at the Pro-Mini schematic for this little circuit: http://dlnmh9ip6v2uc.cloudfront.net/dat ... ni-v13.pdf. Its at the top center of the drawing and includes the needed circuit plus an optional push button to force a reset manually.

Stepper motor.

Switec X27.168 or equivilant. Listings selling this motor and its clones change daily. Basically it is a replacement stepper motor for the GM instrument clusters from around 2003-2006. You can find them sold in “kits” of 6 on eBay and Amazon, as that is the number of these used in a single GM cluster. You can also find them available individually, but at abut 4 times the per piece price. I bought a pack of 6 off eBay for $22 a year ago.

You can find spec sheets for several of the Switec clones on the web. Here are a few:
http://guy.carpenter.id.au/gaugette/res ... SP_E-1.pdf
http://guy.carpenter.id.au/gaugette/res ... 080606.pdf
http://guy.carpenter.id.au/gaugette/res ... 720473.pdf
http://www.ism-intl.net/content/ISM-Int ... 0Guide.pdf
The X27 is a follow-on and replaces the X25 so the X25 specs are good to reference.
The first link shows a connection diagram at the top of the second page. The pin numbers shown on the “Rear Contacts” drawing match the X27.168 motor. They get connected to the Arduino micro-controller digital IO pins in that order For example in our program (or “sketch”) they would be connected: (motor pin #)-(Arduino pin #) 1-4, 2-5, 3-6, 4-7. Assuming you solder wires to the pins on the motor take care to not heat the pins too long as the heat can distort the plastic body of the motor and alter the way it operates. Also when you mount the motor dont allow the wires or objects nearby to apply a constant side or down force on the pins as that can shift the location of the internal electromagnets and change the motor behavior. If you mount the motor to a surface be sure that surface is flat and the mounting screws dont torque the motor in any axis except directly toward the mounting surface. A symptom of the motor shell being distorted is erratic and noisy movements and in extreme cases loss of position (error in the speedo reading) that clears when the Arduino is reset. When unmounted or properly mounted they are quiet and smooth.
This motor has a mechanical stop that will serve as the 0MPH position in the full CCW position and about 320 degrees CW is the other side of the stop. This should be beyond what most any speedo was designed to sweep. Mine swept about 280 degrees to the top mark on the face. We have the program allowing a 315 degree sweep.
The output shaft is quite small but in my case, using a VW speedo built by VDO it was just a little larger than the original pointers mounting hole. I have read online of at least one other person encountering the same thing. I would guess that the GM pointers from the 2004-2006 would push right on if that matters to you. In my case I carefully bored out the pointer hole with a wire sized drill that was 1 step up from one that fit existing hole. Turned out this was a bit too much and the pointer was not a tight fit on the shaft. So I carefully inserted the pointers mounting boss in a connector crimp tool that happens to have a couple tapered dies for small gauge wire and very carefully compressed the boss several times until the pointer was a tight fit. The MAX pressure when pressing on a pointer per the spec is 150 Newtons or 33 pounds.
I mounted my on a flat surface that originally held the speedo pointer shaft and odometer. I made a small daughter board from .1” spaced PTH perf board. To that board I soldered 4 pins from a DIP socket lined up with the stepper pins and a 4 pin header that lined up with the Pro Mini pins 4-7. I jumpered the proper pins to each other, soldered the daughter board to the back side of the Pro Mini, plugged this into the stepper and that is how it is all mounted in my speedometer.

VSS sensor notes. http://www.demon-tweeks.co.uk/motorspor ... ed-sensors

Its probably safe to assume your application (car) did not already come equipped with a source for electronic speed reporting or it would probably already have an electronic speedometer.
So, you probably need to install a speed sensor.
I recommend a “Hall effect” type sensor vehicle speed detector. There are also VR (variable reluctance) type units but they are not directly compatible with the Arduino, whereas a Hall is compatible.
The Hall sensor will require DC power (5VDC), a ground wire and an output wire. You can connect all 3 to the Arduino (the DC power from the Arduino 5V output terminal, the ground from the Arduino ground terminal and the output will go to the Arduino IO pin 8 (using our software). These consume nearly zero current so are not a load on the Arduino supply.
I used a speed sensor originally sold by Brantz of England for rally odometers. A link to a retailer for them is above. My car was previously a rally car and had the sensor for the odometer still mounted to the speedometer output of the transmission. I can recommend them based on my 10 years experience with them. You may find other solutions for less money, but at least review the models of sensors they sell to get an idea at to what is available off the shelf. http://www.brantz.co.uk/Manuals.htm
A number of companies sell Hall sensors suitable to the automotive environment and intended to convey speed by detecting a ferrous metal slug passing by the sensor. Cherry http://www.cherrycorp.com/english/senso ... Direction/ is one of the larger ones. Many of these can be made to work as a VSS by putting them in close proximity to one or more teeth or slugs around something rotating inside or coming out of the transmission.
Note that nearly all Hall effect sensors require what is called a 菟ullup・resistor between the output of the sensor and the supply voltage to it (5V). The Arduino ATMEGA328P can be configured with software to provide a pullup resistor of 20k-50k ohms (this is the approximate range of the pullup not a selectable value) using the pinMode(8,INPUT_PULLUP) command if that range works for the Hall you use. That is how our sketch is configured. If you need something like a 10K pullup resistor you will need to add that yourself and you can hide the pinMode(8,INPUT_PULLUP) command by adding // on the line to the left of it. An external pullup resistor can be put on the micro-controller board between IO pin 8 and +5V out or between the power and output pins on the sensor itself.
On the subject of VSS. The sketch is set up to produce an accurate speed representation based on 5764 pulses per mile from the sensor. This value is what my car requires. The value used in your sketch should be changed to what you calculate or measure your vehicle produces in terms of pulses per mile.
In my car the VSS input to the speedometer comes from a Megasquirt 3 ECU. The Brantz speedo cable sensor above feeds the Megasquirt.

Power supply notes.

The Arduino micro-controller and shields all are rated to operate from up to 12VDC supply fed to their power input . However at that voltage they suggest the onboard voltage regulators may have heat issues and the recommend something in the 8-10V range. Also, 12V car systems arent 12V. A full charged battery in a car is 12.7V and while running most 12V systems are actually between 13.8V and 14.4V. A reduction in supply voltage below the “12V” in a car electrical system for the Arduino is appropriate. This can be easily addressed with an LM7808 3 terminal regulator and 2 small electrolytic caps. I recommend an LM7808 in a TO-220 package and a pair of 100uf (microfarad) 24V electrolytic capacitors. The value of capacitance and the voltage are NOT critical, so long as the capacitance value is >10uf and <1000uf and the voltage is >16V (higher than 16Vis better, I suggest 25V). The LM7808 doesnt require any heatsinking for this but it should be fused with a 1A fast blow fuse in the 12V input line and the exposed leads should be insulated. The capacitor + leads will be connected to the LM7808 input and output legs and the capacitor – leads will be tied together and to the LM7808 Ground leg. Obviously the LM7808 input leg is connected to that fuse then back to a switched-by-the-ignition 12V source, the output leg goes to the Arduino and shield (if used) and the ground leg ties into the ground wire from battery – (or wherever you can find ground near the speedometer) to the Arduino ground input.
My stepper speedometer is going into a 1987 VW GTI instrument cluster. I found this cluster uses a regulated 10V to supply most of the instrument electronics, so I chose to just tap off this. A little digging in your application might turn up a suitable regulated DC source already in the instrument cluster and save you having to add the above 8V regulator.

The basic schematic:

Image
Last edited by walterclark on Tue Mar 11, 2014 7:40 am, edited 2 times in total.
The older I get the better I was.
User avatar
walterclark
Posts: 1442
Joined: Sun Feb 08, 2009 12:57 pm
Location: Dover, MA.
Contact:

Re: My Stepper motor "Analog" speedometer project

Post by walterclark »

First a copy of the "proof of concept" wherein I use an analog input to the Arduino controller to move the proto speedometer with a stepper mounted.



A couple closeup pics of the proto. This was when the motor was connected to an Arduino Uno R3 via a cable.

Image
Image

A pic of the Arduino Pro Mini 328 showing size.

Image

A video I shared with Kevin during the latter stages of software development to show behavior. The speedo was now connected to my Megasquirt 2 and a square wave generator was standing in for a VSS. It is sitting on my laptop running a Tuner Studio window (software to talk to a Megasquirt) which shows the official Megasquirt speed for comparison



Finally a pic of the completed speedo, back in the car, car running at a constant 22MPH (in the shop, on the lift).

Image

Next will be pointers to and notes regarding the sketch for this project that Kevin (THANK YOU) is responsible for getting working properly as well as pointers to the needed libraries for the VSS (frequency) input and Speedo motor (stepper) output.
The older I get the better I was.
User avatar
walterclark
Posts: 1442
Joined: Sun Feb 08, 2009 12:57 pm
Location: Dover, MA.
Contact:

Re: My Stepper motor "Analog" speedometer project

Post by walterclark »

Software.

Please note that while it is possible to create an exact copy of this project by simply replicating the hardware and downloading and installing the libraries and sketch all the resources used are aimed at the tech hobbyist so it is assumed one will take the time to read and learn what Arduino is about and how to do it, and that includes programming the Arduino processor. This is the home for Arduino: http://arduino.cc/ Begin here. Before you do anything you want to read the process for getting started http://arduino.cc/en/Main/Software#.Ux7w9IVBpqA and then, if using the Pro Mini http://arduino.cc/en/Guide/ArduinoProMini#.Ux7yD4VBpqA. That is not the end of it by any means but that should get you started and give you an understanding of what info is available at the Arduino website. You will next want to download the Arduino IDE as this is where the sketch you will download is reviewed and edited, then compiled and uploaded to the Arduino processor. Description of the IDE is here: http://arduino.cc/en/Main/Software#.Ux7w9IVBpqA.

Location of the FreqMeasure.zip library and article describing its development and authors use.
https://www.pjrc.com/teensy/td_libs_FreqMeasure.html

Location of the SwitecX25 library.
https://github.com/clearwater/SwitecX25

Location of the blog by Guy Carpenter, who wrote the SwitecX25.h and .cpp for his project, leading up to creating the library.
http://guy.carpenter.id.au/gaugette/201 ... -gaugette/

Location of sketch for this project. Kevin has extensively commented this sketch so it should be pretty obvious what everything is for and what you may need to change to "calibrate" it for your car or use it for similar projects.
https://github.com/Walterclark1/Stepper_Speedometer
This is the github location. If you are not a github member or cannot find it for some reason, it is also here:
http://home.comcast.net/~walterclark1/g ... tepper.ino
If you click on this second link you will see the contents of the sketch. Copy it into an opened Arduino IDE window (you have downloaded the IDE, right?) and save it. You should be good.
Last edited by walterclark on Fri Mar 28, 2014 3:31 pm, edited 1 time in total.
The older I get the better I was.
Chief Geek
Posts: 302
Joined: Sun Feb 07, 2010 2:36 pm
AntiSpam: No

Re: My Stepper motor "Analog" speedometer project

Post by Chief Geek »

Thanks for the write-up. Great job. Now I have even more nutty ideas running around in my head.

Paul
"Christina", New #13/#55x, '90 Miata: In progress
"Keiko", Old #13x/#55x, '96 Miata: R.I.P.
Daily Driver: '11 Mazda2 (small cars... some men have nothing to compensate for)
User avatar
walterclark
Posts: 1442
Joined: Sun Feb 08, 2009 12:57 pm
Location: Dover, MA.
Contact:

Re: My Stepper motor "Analog" speedometer project

Post by walterclark »

I am starting to think about also running a 2 digit 7 segment LED speed display off the same Arduino. The speedo has a nice blank area where the odometer used to live, and I have found the digital speed readout on my smartphone is quite easy to glance at and get an exact number from. And if I decide to not mount it there, Sherms heads-up idea is always a possibility http://lifehacker.com/how-to-build-a-he ... 1129913775.

And, it would appear that one of the next releases of the MS3 firmware will offer a way to multiply the VSS output versus its VSS input. Depending on how well this is done, having more pulses per mile into the Arduino than I have now should let me get a little smoother pointer movements, especially at lower speeds.
The older I get the better I was.
Post Reply