Introduction: Arduino Control/Integrate Aftermarket Accessories Via the CAN-BUS

If you wanted to control aftermarket accessories using the existing controls in your vehicle you would have to connect a relay to end where an existing factory accessory is connected to.

For an example:
You have a 4x4 and want to add aftermarket spot lights, So you need to then connect a relay to an existing light, which will click the relay and let more power through to the aftermarket lights. This means you have to splice and cut into the existing factory wiring of your vehicle.

With this instructable you can tap into the can bus (in my case the can bus wires at the back of the radio)
The radio has a can-bus because its controllable via other accessories such as the steering wheel buttons, so instead of cutting into it you can buy a female-to-make connector and then tap into the connector.


You need the following.
Arduino UNO.
SeeedStudio CAN-BUS Shield.
Arduino IDE with the SeeedStudio CAN-BUS Library.
Relay Shield, can be a single channel, but I used an 8 channel relay board.

The Arduino Code (At the end of this instructable)

Step 1: Another Example of Its Use.

See the picture.

Some vehicles knows how much power the factory bulbs in the Blinkers,Brakes and headlights are supposed to consume, anything under and over it will shutdown the circuit.

So If you wanted to add a trailer , you also need to by the wiring harness which basically does exactly this, and they are very pricey!

Step 2: See This Instructable in Action

Ive created an example prototype on youtube of this.

It monitors the CAN-BUS for the message that turns on the lights, and then DigitalWrite to the pin of your choice.
The Arduino's IO pin is connected to an 8Channel Relay board which can be used to turn on accessories.

In the video i'm controlling the relay by turning on the main beams.

Enjoy! Happy CAN-BUS Hacking!

More Information about this project can be viewed in this forum thread on techtinker.co.za

http://techtinker.co.za/forum/viewtopic.php?f=14&t...

The Arduino Code.

#include <br>#include "mcp_can.h"
INT32U canId = 0x000;
unsigned char len = 0;
unsigned char buf[8];
char str[20];
String CanMessage="";
int HeadLightsDetected=0;
int RelayCHN01=7;
void setup()
{
     //INIT RELAY PIN
     pinMode(RelayCHN01, OUTPUT);
     //TEST RELAY PIN
     TESTRElay();
    Serial.begin(115200);
START_INIT:
    if(CAN_OK == CAN.begin(CAN_125KBPS))
    {
        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()
{
    if(CAN_MSGAVAIL == CAN.checkReceive())  
    {
        CAN.readMsgBuf(&len, buf); 
        CanMessage="";
        canId = CAN.getCanId();
        
        //Detect Main Beam HeadLisghts
        if (canId==680)
        {
          //Build Complete Message Without CAN ID From BUS
          for(int i = 0; i
void TESTRElay()
{
digitalWrite(RelayCHN01, HIGH);
delay(200);
digitalWrite(RelayCHN01, LOW);
delay(200);
digitalWrite(RelayCHN01, HIGH);
delay(200);
digitalWrite(RelayCHN01, LOW);
delay(200);
digitalWrite(RelayCHN01, HIGH);
delay(200);
digitalWrite(RelayCHN01, LOW);
delay(200);
digitalWrite(RelayCHN01, HIGH);
delay(200);
digitalWrite(RelayCHN01, LOW);
delay(200);
}