DEF Sensor Simulator – Arduino UNO
Assembling a DEF Sensor Simulator Using an Arduino UNO
Only basic electrical and DIY skills are required for the hardware assembly. The software installation in this procedure can be done from Windows.
Before you begin, please click here to read an important compatibility notice regarding the ECM (Electronic Control Module, aka Engine Computer) and info on compatible DEF head connectors.
If you run into difficulty post a comment at the bottom of this page.
Please read through all the instructions FIRST before beginning the project. There are web site links embedded in the instructions to help obtain parts.
Note: It is highly recommended that you program the Arduino board before starting the assembly of the DEF simulator. Please see the Programming section at the bottom of this post.
The UNO/ATMega2560 boards require the use of an additional board called a CAN shield. The Arduino UNO or equivalent can be purchased from online retailers such as Amazon.
The CAN shield (V2) is made by Seeed Studios and can be purchased directly from them, Amazon or other online retailers. Here is a link for Amazon.
The assembly will also need a female DB9 connector to attach the wires to the vehicle connector. This connector can be purchased from Amazon:
The entire assembly of the UNO with the DB9 connector is slightly larger than the size of an Arduino DUE, so it will require a larger enclosure. Here is one from Amazon that will work:
The Seed CAN shield will need a small wire trace to be cut before use. Cutting this run removes a termination resistor that is not needed when connecting the simulator to the vehicle. The wire trace is connected between the blocks labeled P1 on the back side of the shield. The run can be cut with an X-acto knife or box cutter. Do not cut too deeply so as to damage the board. The trace is not very thick.
As an alternative to the “Gland nut” you can use a rubber grommet, which can be purchased from most hardware stores, such as ACE Hardware. Just get one that will fit your cable diameter. You could also just fill the hole in the box where the cable goes through with silicone sealant.
The wiring connections on the 4 pin DT-4 connector are: +12v, ground, CAN-H and CAN-L.
The wires associated with these pins (above picture) are connected to the DB9 connector via the screw terminals.
Strip about 3/16 inch of insulation off each wire end and connect to the DB9 screw terminals. If the wire is too thick, cut off a few strands. Be sure there are no stray wire strands touching anything.
Pin 2 = ground Pin 3 = CAN-H Pin 5 = CAN-L Pin 9 = +12v
Make sure to move the switch on the CAN shield to the “ON” position (see Picture above).
Put a small piece of electrical tape to cover the entire top of the USB connector. This helps prevent pins on the bottom of the CAN shield from contacting the connector.
The CAN shield needs to be mounted on top of the UNO board. There is only one way for it to attach.
The finished board assembly can be secured in the box using Velcro.
Programming the UNO/ATMega2560:
It is assumed that someone attempting to construct one will have a modest knowledge of a Windows based computer. The initial work was completed on a Windows 10 based machine, but it is expected that a Windows 7 or XP based machine will also work. The computer will need to have at least 1 available USB 2/3 port.
The software for the Arduino UNO can be downloaded from here.
The download file (DEF Emulator Install Files v0.2(x32).exe) is a self-extracting file that will include the compiled Arduino software appropriate for your hardware configuration ( .bin or .hex) and files for actually programming the Arduino. It is not necessary to install any additional software from Arduino or anywhere else.
Save the file somewhere convenient on your computer. The Windows Desktop will do nicely. After the file is downloaded, just double-click the file and it will automatically create the required directory structure on your C drive and copy all necessary files into their appropriate locations. It will prompt you to verify the destination directory, just accept the suggested default. You may see warnings from your anti-virus software on your Windows computer and you may have to deal with those to allow the installation to run. The downloaded installation package will create the following directory structure in the root of your C:\ drive:
Using an appropriate USB cable, attach your Arduino board to your computer. Please note that the DUE has 2 USB connections, the one nearest the black power connector is known as the “Programming Port” and it is the one you should use. Note that the preceding sentence applies only to the DUE. Some LEDs will light up on the board showing power is connected via the USB cable. Open the Windows “Device Manager” tool and expand the “Ports (COM & LPT)”. You will need to make note of the number of the COM port being used by the Arduino. Note that the Port may also be shown as a “USB Serial Device (COM xx)”.
Close the Device Manager window.
Open the Windows CMD program ( on Win10 right click the windows icon at lower left, select run, type CMD in the box and hit OK). A “CMD” window should open.
In the CMD window type: cd\AVRProg and then hit the enter key. The prompt should now indicate: C:\AVRProg.
The file “program.bat” will be used to upload the compiled Arduino software to your board. Program.bat takes 2 inputs to operate correctly: the board type and the COM port number. The board type can be UNO, DUE or atmega. You can use all upper-case or all lower-case but you cannot mix upper and lower cases. The COM port number will be 1,2,3 etc (just use the number part. Don’t type the ‘COM’ OR ’USB‘ part) that you found from Device Manager.
As an example to program a UNO on COM port 4 use:
Program.bat uno 4
For a DUE on port 3 use:
Program.bat due 3
Type the required command in the CMD window and press the “enter” key.
A lot of information will scroll by on the CMD window. As example for the UNO:
And at the completion:
The Arduino board should now be programmed.
Connecting to your motorhome CAN network:
- Make sure that before you unplug your def head that the ignition is turned off, then unplug your def head. You may need to cut a zip tie to provide working slack in the wiring.
- Plug the simulator into the connection to your chassis wiring where the def head was plugged in.
- Turn on your ignition, some or all of the fault codes should go away and the Check Engine and MIL (Malfunction Indicator Lamp) lights should extinguish within a few minutes.
- If some codes remain, to clear your codes you will need to turn your ignition on (let all systems come up, about 20 seconds), then start your engine and fast idle for 5-6 minutes, shut down for 90 seconds, turn ignition on (wait for systems to boot 20 sec) start engine and fast idle for 5 min. You will do this a total of 3 times on the 4 cycle the codes should clear to the inactive status.
Note: on older engines or engines with older ECM software, some codes may not completely clear on their own. In this case code clearing intervention may be required. This is something that is still under study, see the Troubleshooting section for more info.