Can an Arduino be used as an Auto Cruise Control?

Hello all,

First time poster here. Please be gentle. This would be my first foray into the world of microcontrollers. I read an article about the Arduino in this month's WIRED magazine. At first thought, it seemed like a really cool device, but I could not think of a practical use for myself to use one. Then it hit me, I'd like to have cruise control in my car.

I'm rebuilding a 93 Civic, and have installed all the parts needed for cruise control scavenged from junk cars. I have installed the steering wheel buttons, the clockspring behind the steering wheel to transfer the signal down to the cruise module. I have installed and tested the servo motor/clutch under the hood. I have used an oscilloscope to monitor all the signals going into the cruise module while driving and all seem to be correct, but the cruise will still not set. I have replaced the module, still no cruise. I have the sneaky feeling that the module is looking for certain RPM to match up with certain Vehicle speed, and this model Civic (CX) did not come from the factory with cruise control. The gearing in this model is higher than a regular Civic, so it gets better gas mileage. I think that might be confusing the module. I have considered building a cruise tester that has switch inputs for the set, coast and brake switches, and a couple of 555's as oscillators to simulate speed signal and tach signal. If I had such a tester, then I could plug in a module that I want to buy at the junkyard and test it before I buy it. Also if I had such a tester, I could maybe sell it, there are folks who part out old civics as a living, and a few that I've met have expressed interest in such a tester. But it would be cool to build a cruise control with an Arduino.

I have been reading various datasheets on the Arduino and have been unable to find the information what I am looking for.

In building a cruise control for the car, I would need for at least two of the input pins to be able to be used as counters. I am anticipating about a 50Hz signal on one input and about 200Hz on the second. The 50Hz signal is from a Vehicle Speed sensor, and the 200 Hz is from a tach signal. Don't worry, these will be optically isolated signals. I would read these frequencies and when the set input is asserted, store the values. I would then continue to read these frequencies on a continuous basis, doing some simple math to determine if my speed has dropped or risen more than a hysterisis value. I could then turn on an output to run the factory module that has a small motor that pulls the gas pedal. That part is already in the car and I'm clear on how that works.

As an ultimate wish, has anyone written a PID Loop for the Arduino? For a cruise control to work best, the larger the error from the setpoint, the larger the correction would need to be. (Proportional Gain). Also, for small errors, where the proportional is not enough to make a difference, Integral could be used to apply correction for error that exists for a certain period of time. Actually just a PI would be needed, as I really can't see a use for derivative, this application is not that intense. I am in the Industrial automation business and we very rarely use derivative, even for motor control.

I have read a few things about interrupts. I think this would work best with several interrupts, 2 for counting pulses, one each for the set and coast buttons, and one for the brake pedal. Can that many interrupts be used at once?

So it all boils down to.

Can the Arduino read up to 200Hz on a digital input? Can it count pulses for a fixed interval, and when an input goes high, store that value to a variable? Can it use several interrupts at once? Can it then perform simple math to determine error between that setpoint and the next interval count of pulses? Has anyone done PID, or just PI control in the Arduino?

Thanks for reading, thanks in advance for any info anyone is willing to share.

Happy developing to all, and to all a good night!

Jason

a. Can the Arduino read up to 200Hz on a digital input?

b. Can it count pulses for a fixed interval, and when an input goes high, store that value to a variable?

c. Can it use several interrupts at once?

d. Can it then perform simple math to determine error between that setpoint and the next interval count of pulses?

e. Has anyone done PID, or just PI control in the Arduino?

a. Yes I think so, some people have made oscilloscopes using 'duinos http://www.coolcircuit.com/gadgets/2008/02/19/arduino-based-oscilloscope/

b. Yes

c. I think so

d. Absolutely

e. Not sure

This is not what you're looking for but you may find it useful, it interfaces OBD to a 'duino

http://code.google.com/p/opengauge/wiki/OBDuino

:)

Thank you for the reply. I looked through the link you sent and through the similar MPGuino device, and if they are reading VSS and Injector pulses, I should be able to read VSS and Tach pulses. Those projects seem to be doing alot more calculating than I will and I also don't need to drive a display, I only need to engage a relay to apply either a forward polarity or reverse polarity to the gearmotor under the hood. Again, thank you for the response, I think I'm ready to order my Arduino.

Jason

I haven’t done it yet to the mpguino, but I’ve been wanting to add cruise control to my car. It is entirely possible for an atmega168 to perform that function. If you are not afraid of doing some wiring on your car (which you can’t be for this project) then you can do this with the mpguino circuit (plus additional speed control circuit) and not have to buy an elm327 chip. But the mpguino only senses the injectors and the vss. And you can compute speed/distance, fuel consumption, and occasionally RPM plus all permutations from there.

I lost cruise control on my saturn after swapping out the automatic transmission and putting in a stick shift, and would like to get it back, but need the help of a small computer. I have to decipher the actuator circuits. Also it has resistive switches on the console which I could read with an analog pin.

A normal saturn ECU keeps an internal table of the transmission gear ratios, and if the RPM to MPH isn’t one of those ratios then it assumes the clutch is in/slipping and disengages the cruise control.

Your “typical” actuator is a vacuum diaphragm controlled by a couple valves however, connected to the throttle lever by a piece of chain.

Aside from maintaining a target speed, you can maintain a target mpg, or a target engine load, or have it determine the most fuel efficient acceleration rate, etc. I’d be happy just to get my cruise control back :slight_smile:

P.S. Be safe, be prepared to shut off the ignition, without locking the steering wheel as you are giving partial control of your vehicle to a new computing device. Do some bench testing first, and even then keep your guard up when road testing as computer devices rarely work right the first time. And do your road testing on a quiet road.

Oh my Gosh, Thank you so much for responding to my meager request. It is a true honor to have attracted the attention of the MPGuino creator himself!

I’m not sure what the elm327 chip is. Thanks for the advice about being careful. I installed Cruise in my last car. I bought an Audiovox unit off of Amazon for $100. I then hacked it to work with the buttons on the steering wheel by buying and adding the buttons and replacing the clockspring with one out of a Civic that originally had cruise. It looked completely factory, no one would ever know that it was aftermarket unless I told them.

I was a little suprised with this Civic in that the unit under the hood to pull the gas pedal is actually a gearmotor with a 12V clutch. And that part has been tested and it all works. Since I took the cruise out of another Civic, including the module, the gearmotor, the cable, and the pedal assembly, I thought it would work. And I’m not scared of the wiring. But like I said above, perhaps it is picky about the gear ratios. But it’s a stickshift, so really you could set the cruise in any gear. I would think that although my model Civic has a little taller gearing, that 3rd or 4th gear would equal about the ratio of a normal Civic in 5th gear. Buying the Chilton manual from Autozone has really helped with the wiring, well worth the $12.

I would really want mostly to be maintaining speed. Some of the hills I go up on the way to work would really slow me down if I was trying to maintain a target load or MPG. As far as safety, I’m sure I could have the brake pedal unlatch the gearmotor clutch with hardware external to the Arduino as well as software disengage so that if the processor hangs in a loop or at a line of code, I can still get the cruise to disengage quickly. There is also a cruise control main power switch on the dash. Power for the cruise sections could go through there.

With all these positive feelings that this project will work, I’m about ready to order my Arduino. I’m just trying to decide the cheapest way to do it. Small is good, but not at a premium price. I’m not afraid to breadboard something, like the RBBB. It’s not like I’ll be changing the code alot. Even Serial would be fine, I have old computers with serial ports. I’m also good to build a couple 555 timers on the bench for testing.

Is there only the ability to count two sets of high speed pulses on the chip? At this point the MPG stuff is not all that inportant to me, and I’ll need the tach signal instead of the injector signal. How do you get the RPM? Just by counting injector pulses and not worrying about pulse width? Since the code is already available, and I would only need minor tweaking to act as cruise, as long as there is memory space to add the extra code. I suppose that would work, the MPG display would be waaaay cooooool.

Have you given any thoughts to PID loops? There should be some sort of proportional and integral gains to get the cruise to work properly without continually cycling the gearmotor back and forth…over…under…over, you know what I mean…

I thought I was reading at one point that there was a new Arduino chip that had twice as much memory as the atmega168, or am I just imagining things?

Again thank you for responding to my meager request for information. Gosh, I feel like I just met Angelina Jolie or something! ( Or insert some really exciting Celebrity Sighting as you see fit!) And thank you for all your hard work into this open source project…together we are stronger!

Jason

You can get the ATmega328 which has twice the Flash and RAM ( 32K Flash, 2K RAM )

Or the 644 which has 64K Flash and 4K RAM and lots of extra pins

http://farm4.static.flickr.com/3206/2692856142_bf041a07aa.jpg?v=0

You may have some issues programming the 328 and 644, they are not 100% arduino compatible but are pretty close

:)

gnu-

More memory would be great. Do you have any specifics on the differences between the other two chips and a true arduino?

Looking at the schematic of the MPGuino, I see that not many digital i/o points remain. I'm not sure if it would work, but the Modern Devices website shows a serial interface to the LCD display from the arduino, using only one data pin. One additional pin would be needed for brightness. That would free up some digital points. I have not finished reading all of the MPGuino posts yet, but I believe that they are running out of memory. Adding the extra IO for the cruise buttons and clutch and brake switch is going to add some code. Even more code will be required to add a PI loop. I believe that to combine an MPGuino and a cruise control needs a little more chip horsepower. But since I have not ordered my hardware yet, I can't say for sure. I'm looking for anybody's input on this.

Thanks

Jason

There are some minor changes you have to make to get the arduino IDE to work with the 328 or 644 ( Sanguino )

Sanguino specs

atmega644P core

32 total general purpose I/O pins (some are multipurpose)

8 analog pins

6 PWM pins

64K flash memory

4K RAM

2K EEPROM

http://sanguino.cc/useit has some installation instructions and information on how to get it working on Linux, Mac OS X and windows

Some code and library changes may be required

Wulfden and Modern Device may have some more info too, in fact Wulfden has BBB and Sanguino boards modified to program the chips in conjunction with an Atmel ISP programmer -- they look very cool :)

http://www.ladyada.net/library/arduino/upgrade.html has some info on the 328

There is a modified Arduino IDE for the 328 ( there's a link at the bottom of the page to the IDE for the 328 Danger, Will Robinson, the IDE is currently windows only and version 0011 )

If the 328 and 644 are not big enough you can upgrade to the ATNGW100 http://linuxdevices.com/news/NS2837651365.html which is a lot more powerful and still quite affordable

The ATNGW100 is AVR32 based and runs ucLinux

:)

It sounds like you found the K107 LCD driver board from Wulfden / Modern device which lets you drive your LCD with 3 pins ( 1 signal 1 PWR+ 1 GND )

There is an optional trimmer pot available for the K107 for contrast, I am not sure about brightness, you might have to hack the board to control the LED backlight

:)

http://moderndevice.com/LCD.shtml

Is the Device I was referring to. It looks like they call it the LCD117. It looks like it will eliminate the multiple pins required between the Arduino chip and the LCD. Has anyone used it before? I'll need those pins for the Cruise inputs/outputs. Hacking the board for the brightness should not a problem.

Thanks for the info..

Jason

I have used the Wulfden K107 which is very similar

http://www.phanderson.com/ebay/lcd117_rear.jpg

http://wulfden.org/TheShoppe/k107/k107-51.jpg

The K107 Rev 4 has pads for an optional trimmer pot ( labeled R1a on the board ) for controlling the contrast

I think you would have to modify the board and use a current limiting resistor to control the backlight brightness

http://wulfden.org/TheShoppe/k107/about.shtml

http://wulfden.org/TheShoppe/k107/k107.shtml

It comes in 2400, 9600 and 19200 baud versions

Very cool stuff :)

Looking at the schematic of the MPGuino, I see that not many digital i/o points remain.

You have 4 pins open (not including rx and tx) which should be 2 more than you need to control a cruise control actuator. if you want to retain the LCD then you will be hard pressed to add much new functionality without going to an atmega328. I don't know how arduino compatible the sanguino is, it looks like overkill to me and they don't have their own support forum, so know what you are getting into there. It's real easy to get sidetracked on the hardware :) But serial LCDs and atmega644s are not required for this. They just add cost and complexity. And there are a few mpguino kits that work with the atmega168 and are fairly easily adapted to the 328.

Jasonh, if you already have an arduino (or clone), I would recommend that you try and control your existing actuator with it, in the driveway or with a 12v adapter on the bench. Perhaps with a couple mosfets from ratshack or something? Getting that figured out is really the key to this whole idea.

dcb and gnu - Thank you for the responses. I appreciate all your attention to my little planned project.

I'll actually need several IO points

  1. Set Button
  2. Resume Button
  3. Brake/Clutch Pedals (I can make them in series on the same input as they do the same thing - disengage.)
  4. Actuator Clutch (There is a light on the dash that could be the same output as the clutch)
  5. Actuator Forward
  6. Actuator Reverse

So I'd like to have 6 I/O points. Is there a problem with the serial LCD? THe LCD117 kit on moderndevice.com is $10. It appears that I could save 7 I/O points using the serial LCD. I know that I'm being greedy, but there are a couple switches that I want to use as toggles to do other functions in the car as well. So that would be 4 more - 2 in and 2 out. That brings my total to 10, there are currently 4 left +TX and RX, and if I save 7 with the Serial LCD, that's 13 without even using the RX. How much memory space is currently left in the 168 with the MPGuino code as it is today? The cruise logic is going to need some memory, especially if I try to use a PI loop.

I would be willing to go to a 328 chip for the extra memory.

I see in the spec sheet for the 168 that it can go to a 20Mhz clock speed. Anyone have any experience with that? That speed might help running all these functions, or am I in a pipe dream?

Running the actuator is easy, all I need is three 5V outputs. I've already run it by jumpering 12V to the proper wires. I'm sure three little relays would work fine. I could actually get this to work right now with a switch for the clutch and two pushbuttons for the forward/reverse.

Again...thank you for all the experience and input.

Jason

In response to part 'e' of your question, is there a PID library, yes there is. I'll post the link when I find it.

A friend of mine wrote it - he knows this stuff inside and out due to the kind of work that he does (he's a programmer for a company that lives and breathes PID related stuff)

Hope this helps!

Found the PID link: http://www.arduino.cc/playground/Code/PIDLibrary

Thanks for the reply on the current info. I have decided to get away from the Arduino based Cruise and have installed an Audiovox unit ($100 from Amazon). I still plan on builing a MPGuino at some point however, but it won't need PID. In the future however, PID might be quite useful for some other project....

This product is really cool and the community is quite helpful...

Thanks

Jason