1. Attachments are working again! Check out this thread for more details and to report any other bugs.

Arduino Automatic Coolant Temp Hack for Better MPG's

Discussion in 'Gen 2 Prius Accessories & Modifications' started by TheForce, Feb 23, 2011.

  1. TheForce

    TheForce Stop War! Lets Rave! Make Love!

    Joined:
    May 30, 2005
    3,461
    537
    0
    Location:
    Wheelersburg, Ohio
    Vehicle:
    2006 Prius
    Model:
    N/A
    Success in the car!! But..........


    After merging the digital pot code in with the original source I tried it in the car. Turns out I have the same problem as I did before. The average keeps jumping around very quick causing the pot to change its setting quickly which causes the average to change and this goes on and on. Any way I decided to have the average update every 1ms and the digital pot to update every 30ms. This showed some improvement but it was still causing problems. So what I did next was to allow it to start its fake adjusting at 30ms but when it reached the target fake temp + or - a certain amount I slowed it down to 2000ms. This made things about as perfect as I can get.

    So now that I have it working and calibrated I decided to take a drive. I started out leaving my Hymotion battery turned off so I could let the temp rise to about 180F. After starting the car the temp reached about 106F and the arduino started faking the temp. It takes about 5-8 seconds for it to reach its fake temp setting. After it reached its fake temp of about 165F it held it there + or - 2F. After a few minutes of driving I reached the turn off point of 165F. The arduino stopped faking and allowed the car to see the actual temp.

    I got the temp up to 180F and then turned on the Hymotion battery. I tried to stay in EV mode as much as possible from this point on. As the temperature dropped back to 165F the arduiono started to fake the temp again and held the 165F. I continued driving for a while and all of a sudden the arduino stopped faking and when it did the actual temp read 102F which is what I set it to.

    So right now its a success! I want to do at least a week of driving before I release the new schematic and source code just to be sure its working correctly. Plus that will give me enough time to clean up the code and make the schematic.


    Since I had the same issue with this digital pot as I did with the resistor/cap combo I think I will revisit the original to see if it will work with the new code. If I can get by without using the digital pot I will.
     
    Meg&Bear, seilerts and dave77 like this.
  2. TheForce

    TheForce Stop War! Lets Rave! Make Love!

    Joined:
    May 30, 2005
    3,461
    537
    0
    Location:
    Wheelersburg, Ohio
    Vehicle:
    2006 Prius
    Model:
    N/A
    Another quick update.

    I tried using the resistor/cap schmatic again with the new code and I still get too much noise from the PWM. I cant average out the information into something more stable. So I'm abandoning the original design for the new digital pot design.

    Today I have been cleaning up the code, fixing some bugs, and adding a new feature.

    I found out that my averaging logic was not giving me the correct value. I found out that it was not grabbing the last value and adding it to the total before averaging it out. I made some changes to that part of the code and now its giving me the correct average values.

    I also added a feature to let me know what state the Arduino is in. I added a RGB LED to let me know if its too cold, too hot, or if its faking the temperature. Blue means its too cold to fake the temperature. Green means its faking the temperature. Red means its to hot to fake the temperature. This is really only useful for debugging on the bread board but I guess you could put the LED on the dash somewhere if you wanted to.

    I'm currently working on the schematic. I may just go ahead and release the source code and the schematic tonight if I get everything done.
     
    Meg&Bear likes this.
  3. TheForce

    TheForce Stop War! Lets Rave! Make Love!

    Joined:
    May 30, 2005
    3,461
    537
    0
    Location:
    Wheelersburg, Ohio
    Vehicle:
    2006 Prius
    Model:
    N/A
    Getting the schematic done was pretty quick. I decided to release the schematic and source code now since I think I'm done with them at the moment.

    Please visit the first post for the new schematic and source code. As of right now the current design is working. If you see anything wrong with schematic or source code please let me know and I will try to make the changes.

    After a week or two of testing with the bread board I will create a shield for a regular Arduino and put it in a project box to finish it up. I will post pictures of that when I get to it.
     
    Meg&Bear likes this.
  4. TheForce

    TheForce Stop War! Lets Rave! Make Love!

    Joined:
    May 30, 2005
    3,461
    537
    0
    Location:
    Wheelersburg, Ohio
    Vehicle:
    2006 Prius
    Model:
    N/A
    Today the AACTH worked perfectly. It held a 165F +- 2F. It stopped faking when the temp was above ~165F and stopped faking when the temp dropped to 102F. I really wish I had this when it was colder out.

    I'm going to see if I can fabricate something to use a standard perfboard with the Arduino non standard pin spacing. I would hate to spend ~$15 for an Arduino protoshield or a few dollars for offset headers. I'm sure I have something here I can use.

    I'm going to include the RGB LED on the shield but I'm going to put a jumper on it to enable or disable it. It will be going into a project box and stuffed behind the glove box so I don't really need to power an LED where I will never see it once I know its working.

    I'll keep everyone updated on my progress.
     
    Meg&Bear and dave77 like this.
  5. TheForce

    TheForce Stop War! Lets Rave! Make Love!

    Joined:
    May 30, 2005
    3,461
    537
    0
    Location:
    Wheelersburg, Ohio
    Vehicle:
    2006 Prius
    Model:
    N/A
    I updated the schematic to include a DPDT switch which I would recommend installing.
     
    Meg&Bear and dave77 like this.
  6. seilerts

    seilerts Battery Curmudgeon

    Joined:
    Mar 7, 2010
    3,326
    1,513
    38
    Location:
    Santa Fe, NM
    Vehicle:
    2005 Prius
    Jay, this is great work, thank you!!!
     
    Meg&Bear likes this.
  7. hill

    hill High Fiber Member

    Joined:
    Jun 23, 2005
    20,174
    8,353
    54
    Location:
    Montana & Nashville, TN
    Vehicle:
    2018 Chevy Volt
    Model:
    Premium
    Does your coolant temp hack improve on Bob or Ken1784's 2007 mod's?
    Presuming so ... how?
    (discussed here)
    http://priuschat.com/forums/gen-ii-prius-modifications/36342-another-thermistor-hack.html

    As it is, rather than doing more mods, we'll likely have to 'un-do' our current mods in the near future if we sell. We're at 100,000 + miles and 7 years now ... and the new owner (which may just be our daughter) may not want to hear the dealer's service tech tell her, "what the heck have you done??"
    :p
    .
     
  8. 2009Prius

    2009Prius A Wimpy DIYer

    Joined:
    Mar 25, 2009
    2,705
    510
    63
    Location:
    USA
    Vehicle:
    2009 Prius
    Great work! Is there a good link to learn about Arduino from scratch, like "Arduino for dummies", so I know how to compile the code etc.?

    How do I translate these numbers to temperatures in F or C?
    I also wonder about the ADC noise averaging. Instead of reading a value every 1 ms and averaging over an 8 ms time period (if I understand the code correctly), I wonder if it would be better to read a value every 125 ms and average over a time period of 1 second. Actually you could use the serial output to record a continuous stream of raw ADC values and plot the data up (like a digital oscilloscope) to determine the best sampling and averaging strategy.
     
    Meg&Bear likes this.
  9. TheForce

    TheForce Stop War! Lets Rave! Make Love!

    Joined:
    May 30, 2005
    3,461
    537
    0
    Location:
    Wheelersburg, Ohio
    Vehicle:
    2006 Prius
    Model:
    N/A
    I think this is a major improvement over the originals except for Bob's micro controller version.

    With the no wire cut using a pot and a resistor you must keep adjusting the pot as the temp rises or lowers but you know when the car is gets too cold or too hot to continue faking the temp.

    With the mod where you cut the wire your in a "set it and forget it" mode. The problem with that is there is no way to monitor the real coolant temperature. In the event of a problem the engine may overheat or become too cold. If it becomes too cold and you try to start the engine with the car thingking its 165F the engine will stutter and stall. Might even throw some codes.

    With Bob's micro controller and my Arduino doing all the work you dont have to worry about the car getting to cold or to hot since it will automataclly stop faking the temp at a cold set point and a hot setpoint.
     
    Meg&Bear, dave77 and hill like this.
  10. TheForce

    TheForce Stop War! Lets Rave! Make Love!

    Joined:
    May 30, 2005
    3,461
    537
    0
    Location:
    Wheelersburg, Ohio
    Vehicle:
    2006 Prius
    Model:
    N/A
    All you do is open the source code in the Arduino software, hook your board up and hit upload. Best place to learn more about the Arduino is here. Arduino - HomePage

    I cant really give you a temperature vs number chart since the temperature is logarithmic. It also depends on what the reference voltage is set to on the Arduino and it could very from board to board because of small tolerances veriations in the components like resistors. The numbers in the source code are from trial and error and only represents what the ADC can see. I'm guessing if you duplicate what I have done you should be very close to what I have and worst case should only bump the low and target by a few numbers.

    The VT_targetR is used to say how close do we want to get to our target temp berfore slowing down the updates. For an example our target temp is 165F. Once we reach between 163F or 167F we start slowing down the updates to get a more stable average. The number 4 does not represent a temperature in F but just a value as seen by the ADC. For example stay at number 121 +-4. Which means stay between 117 and 125

    I may redo the averaging at a later date but for now my digital pot version is giving me nice flat average on the bench and in the car a nice smooth average. There not a lot of bouncing around like there was when I was using PWM and a resistor/cap to try to smooth it out. What I think really helped is when I slowed down the updates when I got near the target temp.
     
    Meg&Bear, 2009Prius and dave77 like this.
  11. TheForce

    TheForce Stop War! Lets Rave! Make Love!

    Joined:
    May 30, 2005
    3,461
    537
    0
    Location:
    Wheelersburg, Ohio
    Vehicle:
    2006 Prius
    Model:
    N/A
    Well since it was cold out today I found out that the transistor is still causing a little problem with the calculations. Since the transistor is affected by the ambient temp I think I will take a look at the data sheet of the digital pot to see if I can some how hook it up to the car directly instead of driving a transistor.
     
    Meg&Bear likes this.
  12. 2009Prius

    2009Prius A Wimpy DIYer

    Joined:
    Mar 25, 2009
    2,705
    510
    63
    Location:
    USA
    Vehicle:
    2009 Prius
    Sure the simpler the better! :)
     
  13. TheForce

    TheForce Stop War! Lets Rave! Make Love!

    Joined:
    May 30, 2005
    3,461
    537
    0
    Location:
    Wheelersburg, Ohio
    Vehicle:
    2006 Prius
    Model:
    N/A
    Well after trying just the digital pot I found that although it does kind of work the 8bit resolution is just not enough. Even if I put both pots in parallel to get 2.5k 9bit resolution would just not work to well.

    I'm thinking about taking another approach. I'm thinking about driving the transistor but to keep from having the ambient temperature play a roll I think I will stop the faking for just a few milliseconds. During this time take a quick average of the real temp and if the real temp is with in the faking range continue with the faking. If the real temp turns out to be too hot or too cold stop faking. I'm thinking about doing this once every 30-60 seconds.

    I have not tried this yet so I dont know if will work or not. I dont know if there will be any issues with the real temp voltage staying around for a while when the fake temp stops but there is only one way to find out. I also dont know how the Prius would like seeing the temp fluctuate like that.
     
    Meg&Bear likes this.
  14. TheForce

    TheForce Stop War! Lets Rave! Make Love!

    Joined:
    May 30, 2005
    3,461
    537
    0
    Location:
    Wheelersburg, Ohio
    Vehicle:
    2006 Prius
    Model:
    N/A
    Success again! :D

    First off the schematic has not changed.

    Second I have made several changes in the source code.

    First thing I have done is to turn off the digital pot for a millisecond, quickly grab 16 values from the ADC, turn on the digital pot, and then average them out. I do this once every 2500ms. Doing it this way allows the Arduino to see what the real temperature is. The Prius seems to be OK with this as it has not thrown any codes.

    The next thing I added was a latch. With out the latch if the Arduino is nearing the turn on/off fake temp area it will keep trying to either turn it on or turn it off. I created this buffer zone to help prevent that from happening. It can still happen but under normal driving conditions it should not happen.

    I added a start up delay to help let the electronics settle down when the car is turned on.

    I changed when the digital pot gets updated. Before it updated through every run. Now it only updates if the value changes.

    I changed the target temp to be about 170F +-2. The turn on/off temp is still around 105F +-2.


    I thinks thats everything. You can get the new source on my first post. Version 0.11.03.27


    I know my code is not very good and could possibly be more efficient but I'm not a programmer. So I don't really know what I'm doing. As long as it works I'm not going to mess with it. If anyone wants to make the code look good, be more efficient, or fix some issue please do so and post it here.

    I'm going to go through another week of testing before I move this design to a shield and a regular Arduino.
     
    Meg&Bear and dave77 like this.
  15. TheForce

    TheForce Stop War! Lets Rave! Make Love!

    Joined:
    May 30, 2005
    3,461
    537
    0
    Location:
    Wheelersburg, Ohio
    Vehicle:
    2006 Prius
    Model:
    N/A
    So far the latest version of the code is doing very well. I have taken it up to 180F and back down to 100F. It stops faking at each end just fine and is not effected by ambient temperature.

    I'm just wondering if anyone has built this or is going to build this? I would like to see other peoples results.
     
    Meg&Bear likes this.
  16. mrbigh

    mrbigh Prius Absolutum Dominium

    Joined:
    Sep 6, 2005
    3,686
    699
    2
    Location:
    Long Island, NY
    Vehicle:
    Other Electric Vehicle
    Any takers??????
     
  17. ItsNotAboutTheMoney

    ItsNotAboutTheMoney EditProfOptInfoCustomUser Title

    Joined:
    Jul 18, 2009
    2,287
    460
    0
    Location:
    Maine
    Vehicle:
    2010 Prius
    Model:
    II
    I'm not a taker but I thought I'd look at the code.

    I've attached an update. Warning: it has not been tested .

    The changes
    - I simplified the pot average:
    - I eliminated the array sum by calculating a moving sum
    - I eliminated the array shift by moving the index instead.
    - It adds two more variables but that calculation should at least be a bit faster.
    - Added const to some "constant variables"
    - Added a constant for the fast pot interval
    - I renamed some variables for clarity (I hope :p)
    - Moved the average divisions inline and added a comment that they could possibly be done with a bit-shift
     

    Attached Files:

    Meg&Bear likes this.
  18. TheForce

    TheForce Stop War! Lets Rave! Make Love!

    Joined:
    May 30, 2005
    3,461
    537
    0
    Location:
    Wheelersburg, Ohio
    Vehicle:
    2006 Prius
    Model:
    N/A
    Thanks. I'll try the code when I get home from work today.
     
    Meg&Bear likes this.
  19. 2009Prius

    2009Prius A Wimpy DIYer

    Joined:
    Mar 25, 2009
    2,705
    510
    63
    Location:
    USA
    Vehicle:
    2009 Prius
    I will build one eventually but am too busy at this moment. Stay tuned.
     
    Meg&Bear likes this.
  20. TheForce

    TheForce Stop War! Lets Rave! Make Love!

    Joined:
    May 30, 2005
    3,461
    537
    0
    Location:
    Wheelersburg, Ohio
    Vehicle:
    2006 Prius
    Model:
    N/A
    ItsNotAboutTheMoney I tried your code and it had some issues.

    First there was an else if statement error for the hot temp led part of the code.

    Second was that the new averaging was not getting any data. I dont know why. I'll have to look at it some more. It was cold out side and I did not feel like debugging it. When I write code I try to make it as english as possible. Mostly just so I can read it. Once I understand what your doing I will try to see why its not working, fix it and possibly use it in the final code. Personally I dont care if the averaging could be faster or not because in this case its really not that critical. But if I can get your code to work I will keep it in the source.

    In the mean time I made some changes.

    I have made is so there is a cold stop setting and a start setting. I use these values with the latch in order to keep the Arduino from trying to fake the temp and stop faking the temp near the cold turn off point. As an example it will now start faking the temp at about 110F. At that point the real temp must drop to about 105F before it will stop faking. Then the real temp must reach 110F before it will start faking again.

    I also implemented some if not all of ItsNotAboutTheMoney name and constant changes. I have given you credit in the source. Let me know if you want your PC username in the source or if you would like your real name.

    So far I think the hardware design is going to be perfect but we will wait and see if there is any difference in the regular Arduino when I get it finished. I think now its just polishing the source code to make run the way we want.
     
    Meg&Bear and dave77 like this.