loading

Ive been building an Arduino OBD2 Scanner to interface with my Jeep's OBD2 port, but it became a beeeeeg! schlep to upload code to my Arduino Nano + 16x2 LCD + ELM327 Scanner device, then haul the whole prototype to the Jeep in the gurage the whole time and then only to find there was something small i forgot to change.

I needed to find a way to test my prototype in the comfort of my home.

Ive searched high and low and couldn't find any Arduino OBD2 simulators that i can build my self. I came across one or two websites that's making use of Arduino to build an OBD2 Simulator but they dont give you the code you have to buy the ready made product from them, I.E the FreeMatics for something like a whopping $169, Wheres the love for Open source in that ???? pffft! I dont see $169 I see about 8 Arduinos i can buy with it.

So unfortunatly and fortunatly for you :-) I had to figure out how i'm going to build one my self, which forced me to now focus on a project i had to take on in order to complete my initial project, Took me some time to figure out how to send PIDs in standard OBD2 format. But at the end i could connect a FreeObd Scanner program which you normally get with your ELM327 Scanner.

Stuff you need.

Arduino UNO

CAN-BUS Shield

ELM327 (USB,Bluetooth,Wifi) It doesnt matter which flavour you have. As long as it creates a com port

OBD2 Diagnostics software (Just to Test if it works) any OBD2 software should work, the software you got with the ELM327 scanner should do just fine.

Step 1: Step 1: the Code

Unfortunately for this to work you MUST have a Shield from SeeedStudio Called the CAN-BUS Shield. You also get one from Skpang but the code below will not work for Skpang unless you alter it slightly.

If you dont know already you also need the SeeedStudion CAN-BUS Library loaded int he Arduino IDE.

Upload the below code, if you dont have the CAN-BUS Shield library loaded the below will most probably error out.


//This Arduino UNO Sketch requires the Seeed CAN-BUS Shield Libraries
//https://github.com/yexiaobo-seeedstudio/CAN_BUS_Shield #include #include "mcp_can.h"
INT32U canId = 0x000;
//2024    4    65    12    18    248    185    147
 
unsigned char len = 0;
unsigned char buf[8];
char str[20];
String BuildMessage="";
int MSGIdentifier=0;
void setup()
{
    Serial.begin(38400);
START_INIT:
    if(CAN_OK == CAN.begin(CAN_500KBPS))
    {
        Serial.println("CAN BUS Shield init ok!");
    }
    else
    {
        Serial.println("CAN BUS Shield init fail");
        Serial.println("Init CAN BUS Shield again");
        delay(100);
        goto START_INIT;
    }
}
void loop()
{
    char rndCoolantTemp=random(1,200);
    char rndRPM=random(1,55);
    char rndSpeed=random(0,255);
    char rndIAT=random(0,255);
    char rndMAF=random(0,255);
    char rndAmbientAirTemp=random(0,200);
    char rndCAT1Temp=random(1,55);
    
    //GENERAL ROUTINE
    unsigned char SupportedPID[8] =       {1,2,3,4,5,6,7,8};
    unsigned char MilCleared[7] =         {4, 65, 63, 34, 224, 185, 147}; 
    
    //SENSORS
    unsigned char CoolantTemp[7] =        {4, 65, 5, rndCoolantTemp, 0, 185, 147};  
    unsigned char rpm[7] =                {4, 65, 12, rndRPM, 224, 185, 147};
    unsigned char vspeed[7] =             {4, 65, 13, rndSpeed, 224, 185, 147};
    unsigned char IATSensor[7] =          {4, 65, 15, rndIAT, 0, 185, 147};
    unsigned char MAFSensor[7] =          {4, 65, 16, rndMAF, 0, 185, 147};
    unsigned char AmbientAirTemp[7] =     {4, 65, 70, rndAmbientAirTemp, 0, 185, 147};
    unsigned char CAT1Temp[7] =           {4, 65, 60, rndCAT1Temp, 224, 185, 147};
    unsigned char CAT2Temp[7] =           {4, 65, 61, rndCAT1Temp, 224, 185, 147};
    unsigned char CAT3Temp[7] =           {4, 65, 62, rndCAT1Temp, 224, 185, 147};
    unsigned char CAT4Temp[7] =           {4, 65, 63, rndCAT1Temp, 224, 185, 147};
    
    if(CAN_MSGAVAIL == CAN.checkReceive())  
    {
      
      CAN.readMsgBuf(&len, buf); 
        canId = CAN.getCanId();
        Serial.print("<");Serial.print(canId);Serial.print(",");
        for(int i = 0; i
        BuildMessage="";
    }
    
}

Step 2: Step 2: Preparing the ELM327 Scanner Cable to Test Your New OBDII Simulator.

You can do it which ever way you like. since the ELM327 Scanner cable is quite cheap i modified it to my liking.

I removed the original sticker to get to the 4 screws to open the box, I took a male to female extender USB cable and cut it in half.

and soldered the one piece of the USB cable's end to pin 6-CAN High and Pin 14-CAN Low, made a little hole on the side, closed it up and stuck a sticker on the side to remind me which is which. Look at the photo's

I then terminated the other half of the USB extender cable to the SeeedStudio Can-BUS shield, Obviously CAN-H from ELM327 to CAN-H on the Shield and same with the CAN-L wires.

Step 3: Step 3: the Testing.

I then powered up the Arduino, The Arduino+CANBUS Shield is now stand alone and doesnt need a pc but i just left it connected to get power from the USB port.

Then connectr the ELM327 to USB, in the device manager make sure which comport belongs to the ELM327 double check because you now have 2 com ports the Arduino's COM Port and the ELM327.

Start an OBD diagnostics windows program I.E ScanTool.net then let it monitor the RPM.

The OBD Simulator isnt smooth because its programmed to randomly generate "Valid" data I.E the RPM wil randomly jump from say 5RPM to 800RPM to 20RPM to 1800RPM ect ect, Ive made notes in the Arduino code, its easily readable and doesnt support all PID data but you can certainly add to it. By looking at some of the standard PIDs from Wiki and following "My" methodology

http://en.wikipedia.org/wiki/OBD-II_PIDs

You can also if you want build it into a box then add a few buttons to alter the variables assigned to the random generator function, I didnt need smooth values, Just as long as i'm able to test my Arduino ScanTool Prototype.

<p>Can you suggest an App to use with the ELM device? Those I&acute;ve tried don&acute;t let me conect, looks like the protocol is not recognized.</p>
<p>I have follow the instructions but I receive only CAN_NOMSG (4), status from Arduino. Looks like the shield isn&acute;t sending any message to OBS reader, and in fact the RX and TX didn&acute;t blink, I&acute;ve tested with other program and the shield looks fine. What should be wrong?</p>
<p>Has anyone managed to get this working with a bluetooth elm327 scan interface?</p>
Hi, what shield version are you using? 1.0 o 1.2? It will work with both versions? Thanks in advance!
<p>Hi mviljoen2,</p><p>Like your simulator, instructables code renderer breaks your example. Could you repost your arduino code again or put the .ino file in a zip? Thx</p>
<p>found your code on a forum post. Put it in a github repo to extend it. https://github.com/AppSaloon/ecu-can-bus-simulator</p>
<p>Thanks cinezaster :-) , that's very helpful, apology for only replying now, I somehow missed your previous message.</p>
<p>Hmmm, this comes close to what i'm trying to accomplish... <br>I have an arduino Ethernet setup in our tugboats engine room, its an old slow running diesel engine w/o obd.<br>The arduino has sensors for measuring the engine's rpm, oil pressures, coolant temp etc, and it serves this data on a webpage for the moment.<br>Next step is to create a virtual dashboard with DashXL from Palmer Performance, to do so i would have to make the arduino pour the measurements into OBD format and pipe the data from the network to a virtual serial port.<br>Is this doable ? Any suggestions on how to approach this project ?</p>
Just a quick question, im looking to make exactly whst youve described. Were you succesful with your design? Im looking into a track data ligger (harrys lap timer) for a sprint car! <br>Cheers<br>Dan
Hi Eric, Thanks for the comment, Its definitely doable.<br>I dont know dashXL at all but quickly looking at it I noticed it can do OBD2 Stuff, do you know the Torque Smartphone App ?, You are able to add customizable PIDs, If you are able to do the same in DashXL and If your tugboat has sensors which is outside of the normal OBD2 Type sensors you could easily just create an &quot;eOBD2&quot; PID as in extended OBD2 which is common on some vehicles I.E My Jeep also has a Transmission Temp sensor but is not part of the usual OBD2 spec, but you are able to add it into Torque Pro by supplying the PID and the message value, So what you should do is look at http://en.wikipedia.org/wiki/OBD-II_PIDs then use a PID which is not already used and have the Arduino Simulate the data in OBD2 format using you own PID chosen which .<br><br>I'm sure most of the PIDs you need is already available in the standard OBD2 spec.<br>In the OBD2 Wiki link i posted it also gives you the formula on how to calculate the PID's IE if you have a temp sensor you would supply it in format by adding 40 to the real value, an OBD reader will then take the value and subtract 40 again as per the spec<br><br>Catch my drift ?, <br>You have quite a nice project ahead!, sounds interesting.<br>Cheers<br>
<p>Hi mviljoen2, Thanks to your post I was able to build and run the simulator.</p><p>Using your code I'm able to simulate different sensor values but I'm also interested in simulating DTC's. Could you please guide on how this could done? This link describes <a href="https://en.wikipedia.org/wiki/OBD-II_PIDs#Mode_3_.28no_PID_required.29" rel="nofollow">https://en.wikipedia.org/wiki/OBD-II_PIDs#Mode_3_....</a> that in mode3 set DTC's are returned but i'm unable to figure out how to set the DTCs in this simulator. Any suggestions would be very helpful.</p><p>Thanks.</p>
<p>Hi there! It seems that your code is incomplete, as shown by the lack of sending the data you create, and the incomplete for loop. I could really use this code. Could you upload the missing pieces please? Thank you!</p>
<p>hmmm this is great....</p><p>how ever my car runs ISO 9141 so i dont think the CanBus shield will work </p><p>any advice?</p>
any one knws were i can still buy a obd ii simulator??
<p>Hi, This looks great, I'm going to try it out but have a question if that's OK. </p><p>I'm developing an iOs app and want to use your project for simulating OBDII over WiFI, What method would you recommend for connecting the wifi OBDII dongle up to the CAN-Bus shield? obviously you use a wired setup.</p><p>Any help would be gratefully received.</p>
Hi, <br><br>I assume you cant make use of Bluetooth because of apple's closed BT api?<br><br>Wireless is going to be quite tricky, and i stand to be corrected , for serial communication to happen over wifi, you need to do the obvious by establishing a wifi connection to the obd2 device, next you need to develop a virtual com port driver, the comport driver then needs to be able to establish connection to the obd2 device using tcp ip, <br><br>So the App talks to the virtual com port using normal serial AT commands, the virtual com port drivers then takes the at commands received and send it over wifi via tcp ip:port on the obd2 device, the obd2 device will then automatically translate to serial again by it self.<br><br>The actual obd2 simulator i built doesnt really have anything to do with the above , the above is just a way to get the commands back and to the Obd2 device which in turn will automatically talk to the obd2 simulator<br><br>Thats how i would approach it.<br>Hope this helps<br>
<p>Yes, Bluetooth would be easier but Apple like to be different!</p><p> I'm fine with getting the app talking to my WiFi dongle, I'm going to try hooking up the dongle to your Arduino project.</p><p>I've got hold of a female OBD2 port to bare end cable, I'm going to hook this up to a DB9 (RS232) connector and plug one end in to the arduino project and the other into my WiFi dongle, I'll let you know how I get on...</p><p>Thanks for your help!</p>
<p>i cant wait to see your scan tool, that will be cool</p>
<p>Hey, I eventually created the scan tool, check it out :-)</p><p><a href="https://www.instructables.com/id/Hack-an-ELM327-Cable-to-make-an-Arduino-OBD2-Scann/" rel="nofollow">https://www.instructables.com/id/Hack-an-ELM327-Cab...</a></p><p>Cheers</p>
<p>To be honest my intentions wasn't going to post the scan tool on instructables, cus i figured there are so many out there already, But i have noticed that people are mostly using the OBDII shield (Also based on the ELM327) specifically made for the arduino which cost more than the normal OBD2 Scanner cable, So since you asked I will make an instructable for it aswell., Because you have to modify the Scanner cable to buypass the USB,Bluetooth,Wifi Chip to get direct access to serial TX/RX pins.</p>
<p>what changes are needed to use skpang?</p><p>trying to make an coolant temp display for a peugeot 107</p>
<p>Hi, Remember this is a simulator, basically simulating coolant temp as if it is a car.<br>If you want to make a simulator with the Skpang I'm not able to help as i dont know the board and need to own one before i tell what needs to change (Probabbly almost everything)</p><p>If you want to build a coolant temp reader, I believe the SKpang Board has downloadable libraries that already supports all the OBD2 PIDs, so you could literally just program the arduino and its ready to go. From there off coarse you can modify it to your liking I.E Only show coolant temp if you want.</p><p>Cheers</p>
<p>Greetings,<br><br>Your project is awesome. I am trying to make things <br>work with the sparkfun shield. Do I have to modify something in the code <br> to make it work? Because it seems I cant establish any short of <br>connection.. CAN L and CAN H from the shield go directly to the ELM 327 <br>pins or in the corresponding OBD plug pins? <br><br>Many thanks in advance and keep up the good work</p>
<p>It seems the code is incomplete: &quot;for(int i = 0; i&quot;</p>
<p>Hi Carlos, Yea I know I always struggle with the instructable <br>editor, hopefully soon they will make the editor a bit more &quot;3rd Party <br>Code&quot; friendly.</p><p>You can also find all my projects including this one here <br></p><p>http://techtinker.co.za/viewtopic.php?f=14&amp;t=10&amp;sid=defa251d4fc40af97ee0894a7d8032d0</p>
<p>Hi Carlos, Yea I know I always struggle with the instructable editor, hopefully soon they will make the editor a bit more &quot;3rd Party Code&quot; friendly.</p><p>You can also find all my projects including this one here</p><p>http://techtinker.co.za/viewtopic.php?f=14&amp;t=10&amp;sid=defa251d4fc40af97ee0894a7d8032d0</p>

About This Instructable

64,807views

96favorites

License:

More by mviljoen2:Arduino Controlled Seed Incubator Jerrycan mount with parts bought from a hardware store. How to nativly run Netflix on a raspbery PI2  
Add instructable to: