Akash k- Projects

 

This is application code developed for RKE project with following features. The requirements are taken from https://cruizbyte.co.in/training-blog/f/remote-keyless-entry


The Block diagram for the feature is given below



  Remote Keyless Entry

// CREATED BY                : AKASH.K

// CREATED ON DATE    : 24 september,2022.

// SOFTWARE                  : ARDUINO IDE

 

//=================PROGRAM FOR REMOTE KEYLESS ENTRY==============

 

#include <SPI.h>     // Arduino Library used for communication between microcontroller and can controller using SPI bus                                      

#include <mcp2515.h> //Arduino Library used for CAN message Implementation

// ===================Declaration of CAN Message Structure======

struct can_frame canMsg;    //CAN Receiver Message

struct can_frame canMsg1;   //CAN Transmission Message For Lock  

struct can_frame canMsg2;   //CAN Transmission Message For UnLock

struct can_frame canMsg3;   //CAN Transmission Message For Search

struct can_frame canMsg4;   //CAN Transmission Message For Trunk

struct can_frame canMsg5;   //CAN Transmission Message For AutoReLock

struct can_frame canMsg6;   //CAN Transmission Message For AutoLock

struct can_frame canMsg7;   //CAN Transmission Message For AutoUnLock

struct can_frame canMsg8;   //CAN Transmission Message For PanicAlarm

struct can_frame canMsg9;   //CAN Transmission Message For CentralLock

struct can_frame canMsg10;  //CAN Transmission Message For TheftAlarm

struct can_frame canMsg11;  //CAN Transmission Message For Driver_Door

struct can_frame canMsg12;  //CAN Transmission Message For Front_Left

struct can_frame canMsg13;  //CAN Transmission Message For Rear_Right

struct can_frame canMsg14;  //CAN Transmission Message For Rear_Left

struct can_frame canMsg15;  //CAN Transmission Message For Cylinder_OFF

struct can_frame canMsg16;  //CAN Transmission Message For Cylinder_ACC

struct can_frame canMsg17;  //CAN Transmission Message For Cylinder_ON

struct can_frame canMsg18;  //CAN Transmission Message For Cylinder_CRANK

struct can_frame canMsg19;  //CAN Transmission Message For Emergency_Unlocking

struct can_frame canMsg20;  //CAN Transmission Message For Special_Circumstances

struct can_frame canMsg21;  //CAN Transmission Message For Mute_Function

struct can_frame canMsg22;  //CAN Transmission Message For Beep_Function

struct can_frame canMsg23;  //CAN Transmission Message For Airbag_Function

struct can_frame canMsg24;  //CAN Transmission Message For FEEDBACK-1_Function

struct can_frame canMsg25;  //CAN Transmission Message For FEEDBACK-2_Function

struct can_frame canMsg26;  //CAN Transmission Message For FEEDBACK-3_Function

struct can_frame canMsg27;  //CAN Transmission Message For FEEDBACK-4_Function

 

 

MCP2515 mcp2515(10);//Declaration of specified Arduino board

 

//=============Declaration of ID for CAN communication======

 

int id_110_value[0]; //canMsg_id

 

//======Initializing the variable for remote keyless entry Button====

int keyfob;

int k_lock;   //Keyfob lock

int k_unlock; //Keyfob Unlock

int k_trunk;  //Keyfob Trunk

 

//=======Initializing the variable for Cylinder Status=============

int CylinderStatus;

int CylinderStatus_OFF;

int CylinderStatus_Acc;

int CylinderStatus_ON;

int CylinderStatus_Crank;

 

//======Initializing the variable for the Door Switch============

//Door status-----------[OPEN-HIGH][CLOSE-LOW]

 

int d_door;

int fl_door;

int rr_door;

int rl_door;

int t_door;

 

 

//=========Initializing the variable for the Solenoid Valves=========

//solenoid valve status----[OPEN-HIGH][CLOSE-LOW]

int D_sv;

int FL_sv;

int RR_sv;

int RL_sv;

int Trunk_sv;

 

//=========Output device variable declaration===================

 

int Airbag;//---------------------Airbag_Status

 

//=========Variable declaration of Feedback===============

 

int Feedback;// -------------------Feedback_status

 

//===========Variable declaration of Beep Function============

 

int Beep;//-----------------------Beep_Status

 

//==========Variable declaration of Ledpin==================

 

int ledPin = 13;//----------------Pin_Status

 

 

//========Declaration of initialize stages========================

 

int Door_Switch_Status;// ---------1 = HIGH

int Door_Valve_Status;//----------1 = HIGH

 

//=======Declaration of Timer====================================

 

int k_unlock_timer = 3;//---------3sec//For timer

 

//========Variable declaration for vehicle speed==================

 

int VehicleSpeed;//---------------for Vehicle Speed

 

//========Declaration of Variable========================

 

int i;//--------------------------//For loop

 

void setup() {

 

  Serial.begin(9600);// To initialize Serial communication at (9600 baud rate)

 

  mcp2515.reset();   //Initializing reset function

  mcp2515.setBitrate(CAN_500KBPS, MCP_8MHZ);//Setting bitrate for CAN protocol

  mcp2515.setNormalMode();  //Initializing Normal Mode

 

  canMsg1.can_id = 0x001;  //Lock

  canMsg1.can_dlc = 1;

  canMsg1.data[0] = 0x09;

 

  canMsg2.can_id = 0x001;  //UnLock

  canMsg2.can_dlc = 1;

  canMsg2.data[0] = 0x10;

 

  canMsg3.can_id = 0x001;  //Search

  canMsg3.can_dlc = 1;

  canMsg3.data[0] = 0x15;

 

  canMsg4.can_id = 0x001;  //Trunk

  canMsg4.can_dlc = 1;

  canMsg4.data[0] = 0x12;

 

  canMsg5.can_id = 0x001;  //AutoReLock

  canMsg5.can_dlc = 1;

  canMsg5.data[0] = 0x14;

 

  canMsg6.can_id = 0x001;  //AutoLock

  canMsg6.can_dlc = 1;

  canMsg6.data[0] = 0x07;

 

 

  canMsg7.can_id = 0x001;  //AutoUnLock

  canMsg7.can_dlc = 1;

  canMsg7.data[0] = 0x03;

 

  canMsg8.can_id = 0x001;  //PanicAlarm

  canMsg8.can_dlc = 1;

  canMsg8.data[0] = 0x05;

 

  canMsg9.can_id = 0x001;  //CentralLock

  canMsg9.can_dlc = 1;

  canMsg9.data[0] = 0x06;

 

  canMsg10.can_id = 0x001;  //TheftAlarm

  canMsg10.can_dlc = 1;

  canMsg10.data[0] = 0x11;

 

  canMsg11.can_id = 0x001;  //Driver_Door

  canMsg11.can_dlc = 1;

  canMsg11.data[0] = 0x17;

 

  canMsg12.can_id = 0x001;  //Front_Left

  canMsg12.can_dlc = 1;

  canMsg12.data[0] = 0x18;

 

 

  canMsg13.can_id = 0x001;  //Rear_Right

  canMsg13.can_dlc = 1 ;

  canMsg13.data[0] = 0x19;

 

  canMsg14.can_id = 0x001;  //Rear_Left

  canMsg14.can_dlc = 1 ;

  canMsg14.data[0] = 0x23;

 

  canMsg15.can_id = 0x001;  //Cylinder_OFF

  canMsg15.can_dlc = 1;

  canMsg15.data[0] = 0x01;

 

  canMsg16.can_id = 0x001;  //Cylinder_ACC

  canMsg16.can_dlc = 1;

  canMsg16.data[0] = 0x02;

 

  canMsg17.can_id = 0x001;  //Cylinder_ON

  canMsg17.can_dlc = 1;

  canMsg17.data[0] = 0x04;

 

  canMsg18.can_id = 0x001;  //Cylinder_CRANK

  canMsg18.can_dlc = 1;

  canMsg18.data[0] = 0x08;

 

  

  canMsg19.can_id = 0x001;  //Emergency_Unlocking

  canMsg19.can_dlc = 1;

  canMsg19.data[0] = 0x20;

 

  canMsg20.can_id = 0x001;  //Special_Circumstances

  canMsg20.can_dlc = 1;

  canMsg20.data[0] = 0x13;

 

  canMsg21.can_id = 0x001;  //Mute_Function

  canMsg21.can_dlc = 1;

  canMsg21.data[0] = 0x21;

 

  canMsg22.can_id = 0x001;  //Beep_Function

  canMsg22.can_dlc = 1;

  canMsg22.data[0] = 0x22;

 

  canMsg23.can_id = 0x001;  //Airbag_Function

  canMsg23.can_dlc = 1;

  canMsg23.data[0] = 0x16;

 

  canMsg24.can_id = 0x001;  //Feedback-1_Function

  canMsg24.can_dlc = 1;

  canMsg24.data[0] = 0x24;

 

 

  canMsg25.can_id = 0x001;  //Feedback-2_Function

  canMsg25.can_dlc = 1;

  canMsg25.data[0] = 0x25;

 

  canMsg26.can_id = 0x001;  //Feedback-3_Function

  canMsg26.can_dlc = 1;

  canMsg26.data[0] = 0x26;

 

  canMsg27.can_id = 0x001;  //Feedback-4_Function

  canMsg27.can_dlc = 1;

  canMsg27.data[0] = 0x27;

}

void loop() {

  if (mcp2515.readMessage(&canMsg) == MCP2515::ERROR_OK) { //To Read CAN Message

    switch (canMsg.can_id) {           //Switchcase Implementation For CAN MSG ID

      

      //=====================CAN MSG_ID - 110==================

     

      case (0x110):

        for (int i = 0; i < canMsg.can_dlc; i++) {

          id_110_value[i] = (canMsg.data[i]);

          Serial.println(id_110_value[0]);

        }

        switch (id_110_value[0]) {  //Switchcase Implementation For CAN MSG ID VALUE

          case 1:

            CylinderStatus = CylinderStatus_OFF; //assigning cylinder status to cylinder off

            Serial.println("CylinderStatus_OFF");// SERIAL MONITOR OUTPUT

            AutoUnLock();//calling Auto locking function

            Serial.println();//Empty line

            mcp2515.sendMessage(&canMsg15);//declaration of a CAN message

            break;

          case 2:

            CylinderStatus = CylinderStatus_Acc;//assigning cylinder status to cylinder Acc

            Serial.println("CylinderStatus_Acc");// SERIAL MONITOR OUTPUT

            PanicAlarm(); //calling PanicAlarm function

            CentralLock();//calling CenterLock function

            Serial.println();//Empty line

            mcp2515.sendMessage(&canMsg16);//declaration of a CAN message

            break;

          case 3:

            CylinderStatus = CylinderStatus_ON;//assigning cylinder status to cylinder ON

            Serial.println("CylinderStatus_ON");//SERIAL MONITOR OUTPUT

            AutoLock(); //calling AutoLock function

            Emergency_UnLock(); //calling Emergency UnLock function

            Serial.println();//Empty line

            mcp2515.sendMessage(&canMsg17);//declaration of a CAN message

            break;

          case 4:

            CylinderStatus = CylinderStatus_Crank;//assigning cylinder status to cylinder Crank

            Serial.println("CylinderStatus_Crank");//SERIAL MONITOR OUTPUT

            Serial.println();//Empty line

            mcp2515.sendMessage(&canMsg18);//declaration of a CAN message

            break;

          case 5:

            d_door = LOW;//initialize driver door is closed

            Serial.println("DoorStatus_DD");//SERIAL MONITOR OUTPUT

            Serial.println();//Empty line

            mcp2515.sendMessage(&canMsg11);//declaration of a CAN message

            break;

          case 6:

            fl_door = LOW;//initialize front passenger door is closed

            Serial.println("DoorStatus_FL");//SERIAL MONITOR OUTPUT

            Serial.println();//Empty line

            mcp2515.sendMessage(&canMsg12);//declaration of a CAN message

            break;

          case 7:

            rr_door = LOW;//initialize rear right door is closed

            Serial.println("DoorStatus_RR"); //SERIAL MONITOR OUTPUT

            Serial.println();//Empty line

            mcp2515.sendMessage(&canMsg13);//declaration of a CAN message

            break;

          case 8:

            rl_door = LOW;//initialize rear left door is closed

            Serial.println("DoorStatus_RL");//SERIAL MONITOR OUTPUT

            Serial.println();//Empty line

            mcp2515.sendMessage(&canMsg14);//declaration of a CAN message

            break;

          case 9:

            (k_lock = 1);//When lock button is pressed

            Lock();//Activates lock function

            TheftAlarm(); //Activates Theft Alarm function

            Special_Circumstances();//Activates Special Circumstances function

            Serial.println("Lock");//SERIAL MONITOR OUTPUT

            Serial.println();//Empty line

            break;

          case 10:

            (k_unlock = 1); //When unlock button is pressed

            UnLock();//Activates Unlock function

            AutoRelock(); //Activates AutoRelock function

            Search(); //Activates Search function

            Serial.println("UnLock");//SERIAL MONITOR OUTPUT

            Serial.println();//Empty line

            break;

          case 11:

            (k_trunk == 1); //When unlock button is pressed

            Trunk();//Activates Trunk function

            Serial.println("Trunk");//SERIAL MONITOR OUTPUT

            Serial.println();//Empty line

            break;

          default:

            Serial.println("Invalid");//SERIAL MONITOR OUTPUT

            Serial.println();//Empty line

            break;

        }

    }

  }

}

void Lock() {//To lock the vehicle

  D_sv = HIGH;

  FL_sv = HIGH;

  RR_sv = HIGH;

  RL_sv = HIGH;

  Trunk_sv = HIGH;

  Door_Switch_Status = LOW;  // Door Closed Stage

  Door_Valve_Status = HIGH;  // Valve lock stage

  Serial.println("01 Door lock");//SERIAL MONITOR OUTPUT

  mcp2515.sendMessage(&canMsg1);//declaration of a CAN message

  Feedback_1_Function(); // Calling Feedback_1_Function

  //Below functions are checked simultaneously

          //TheftAlarm();

          //Emergency_UnLock();

          //Special_Circumstances ();

          //Feedback_1_Function();

}

void UnLock() {//To Unlock the vehicle

  D_sv = LOW;

  FL_sv = LOW;

  RR_sv = LOW;

  RL_sv = LOW;

  Feedback_2_Function();// Calling Feedback_2_Function

  Serial.println("02 Door unlock");//SERIAL MONITOR OUTPUT

  mcp2515.sendMessage(&canMsg2);//declaration of a CAN message

  Door_Switch_Status = LOW;  // Door Closed Stage

  Door_Valve_Status = LOW;   // Valve Unlock stage

  //Below functions are checked simultaneously

            //UnLock();

            //AutoRelock();

            //Search();

}

void Trunk() {//To Unlock the Trunk

  Trunk_sv = LOW;

  Feedback_3_Function();// Calling Feedback_3_Function

  Serial.println("03 Trunk unlock");//SERIAL MONITOR OUTPUT

  mcp2515.sendMessage(&canMsg4);//declaration of a CAN message

  Beep_Function();//Calling Beep Function

  Door_Switch_Status = LOW;  // Door Closed Stage

  Door_Valve_Status = LOW;   // Valve Unlock stage

}

void Search() {//To Search the vehicle

 

  // Times should be included (>=3sec)

 

  if (k_unlock_timer >= 3) {  //pressing k_unlock for 3seconds

    Feedback_4_Function();//Calling Feedback_4_Function

    Serial.println("04 Search function ON");//SERIAL MONITOR OUTPUT

    mcp2515.sendMessage(&canMsg3);//declaration of a CAN message

    Mute_Function();//Calling Mute Function

  }

}

int timer = 5;

void AutoRelock() {//To AutoRelock the vehicle

 

  // Times should be included (>=45sec)

 

  if (timer >= 5)  //assume as 45 sec

    if (d_door == LOW && fl_door == LOW && rr_door == LOW && rl_door == LOW && t_door == LOW) {

      Door_Switch_Status = LOW;// Door Closed Stage

      Door_Valve_Status = HIGH;// Valve lock stage

      Serial.println("05 AutoRelock");//SERIAL MONITOR OUTPUT

      mcp2515.sendMessage(&canMsg5);//declaration of a CAN message

      return;

    }

    else {

      Serial.println("5 No_AutoRelock");//SERIAL MONITOR OUTPUT

      Door_Switch_Status = HIGH;// Door opened Stage

      Door_Valve_Status = LOW;// Valve Unlock stage

      Mute_Function();//Calling Mute Function

      Beep_Function();//Calling Beep Function

      mcp2515.sendMessage(&canMsg5);//declaration of a CAN message

      return;

    }

}

//WHILE KEY IS INSERTED IN MASTER KEYCYLINDER

void AutoLock() {//To Autolock the vehicle

  if (CylinderStatus == CylinderStatus_ON)

    if (VehicleSpeed >= 20)

      Door_Valve_Status = HIGH;  // Valve lock stage

  mcp2515.sendMessage(&canMsg6);//declaration of a CAN message

  Serial.println("06 Autolock");//SERIAL MONITOR OUTPUT

}

void AutoUnLock() {//To AutoUnlock the vehicle

  if (CylinderStatus == CylinderStatus_Acc) {

    if (VehicleSpeed == 0)

      Door_Valve_Status = LOW;  // Valve Unlock stage

    mcp2515.sendMessage(&canMsg7);//declaration of a CAN message

    Serial.println(" 07 AutoUnlocking");//SERIAL MONITOR OUTPUT

  }

}

void PanicAlarm() {//To Activate The Panic Alarm

  if (CylinderStatus == CylinderStatus_Acc) {

    //Should initilize timer for >= 3 sec while pressing unlock button

    Serial.println("08 PanicAlarm");//SERIAL MONITOR OUTPUT

    Feedback_4_Function();//Calling Feedback_4_Function

    mcp2515.sendMessage(&canMsg8);//declaration of a CAN message

  }

}

void CentralLock() {//To Activate The CentralLock

  if (Door_Switch_Status == LOW) {

    if (D_sv == HIGH)

      Door_Valve_Status = HIGH;  // Valve lock stage

    Serial.println("09 CenterLock");//SERIAL MONITOR OUTPUT

    mcp2515.sendMessage(&canMsg9);//declaration of a CAN message

  }

  if (Door_Switch_Status == HIGH) {

    if (D_sv == LOW)

      Door_Valve_Status = LOW;  // Valve Unlock stage

    Serial.println("09 CenterLock");//SERIAL MONITOR OUTPUT

    mcp2515.sendMessage(&canMsg9);//declaration of a CAN message

  }

}

void TheftAlarm() {//To Activate The TheftAlarm

  if (k_lock == HIGH) {//(THIS IS A VALID CONDITION CHANGE THE HIGH/LOW STATUS BELOW FOR OUTPUT VERIFICATION)

    if (D_sv == LOW || FL_sv == LOW || RR_sv == LOW || RL_sv == LOW || Trunk_sv == LOW || d_door == HIGH || fl_door == HIGH || rr_door == HIGH || rl_door == HIGH || t_door == HIGH) {

     

      Feedback_4_Function();//Calling Feedback_4_Function

      Beep_Function();//Calling Beep Function

      Mute_Function();//Calling Mute Function

      Serial.println("10 TheftAlarm");//SERIAL MONITOR OUTPUT

      mcp2515.sendMessage(&canMsg10);//declaration of a CAN message

      //Alarm activates

    }

  }

}

void Emergency_UnLock() {//To Activate Emergency_UnLock

  if (Airbag == HIGH) {

    Door_Valve_Status = LOW;// Valve Unlock stage

  }

  else {

    Door_Valve_Status = HIGH;// Valve lock stage

  }

  Serial.println("11 Emergency_Unlocking");//SERIAL MONITOR OUTPUT

  Feedback_4_Function();//Calling Feedback_4_Function

  Mute_Function();//Calling Mute Function

  mcp2515.sendMessage(&canMsg19);//declaration of a CAN message

  mcp2515.sendMessage(&canMsg23);//declaration of a CAN message

 

}

 

void Special_Circumstances() {//To Activate Special_Circumstances

  if (k_lock == 1) {  //(THIS IS A VALID CONDITION CHANGE THE HIGH/LOW STATUS BELOW FOR OUTPUT VERIFICATION)

    if (d_door == HIGH || fl_door == HIGH || rr_door == HIGH || rl_door == HIGH || t_door == HIGH) {

      Beep_Function();//Calling Beep Function

      Feedback_3_Function();//Calling Feedback_3_Function

      Serial.println("12 SpecialCircumstances");//SERIAL MONITOR OUTPUT

      mcp2515.sendMessage(&canMsg20);//declaration of a CAN message

      Mute_Function();//Calling Mute Function

    }

    if (d_door == LOW) {

      D_sv = HIGH;

    }

    if (fl_door == LOW) {

      FL_sv = HIGH;

    }

    if (rr_door == LOW) {

      RR_sv = HIGH;

    }

    if (rl_door == LOW) {

      RL_sv = HIGH;

    }

    if (t_door == LOW) {

      Trunk_sv = HIGH;

    }

  }

}

 

void Mute_Function() {//To Activate Mute_Function

  if (k_lock >= 3) {  // Holding lock button for 3sec

    //Beep and Alarm muted

    Serial.println("13 Mute_Function");//SERIAL MONITOR OUTPUT

    Beep = LOW;

    Feedback = LOW;

    mcp2515.sendMessage(&canMsg21);//declaration of a CAN message

  }

}

void Beep_Function() {//To Activate Beep_Function

  if (CylinderStatus == CylinderStatus_Acc) {//assigning cylinder status to cylinder Acc

   if (Vehicle_Speed == 0) { // stops after a drive

  if (d_door == HIGH || fl_door == HIGH || rr_door == HIGH || rl_door == HIGH || t_door == HIGH) {

  

    Beep = HIGH;

    Serial.print("14 Beep ON");//SERIAL MONITOR OUTPUT

    mcp2515.sendMessage(&canMsg22);//declaration of a CAN message

     }

    }

  }

  else

  Door_Switch_Status == LOW;  // No Beep

  Serial.print("14 NO Beep");//SERIAL MONITOR OUTPUT

  mcp2515.sendMessage(&canMsg22);//declaration of a CAN message

}

void Feedback_1_Function() {//To Activate Feedback_1_Function

  //TO BLINK THE LED ONCE

  digitalWrite(ledPin, HIGH);

  delay(500);

  digitalWrite(ledPin, LOW);

  delay(500);

  Serial.println("15 Hazard-1 Function");//SERIAL MONITOR OUTPUT

  Serial.println("16 Alarm Honking-1");//SERIAL MONITOR OUTPUT

  mcp2515.sendMessage(&canMsg24);//declaration of a CAN message

}

void Feedback_2_Function() {//To Activate Feedback_2_Function

  //TO BLINK THE LED TWICE

  for (i = 0; i <= 2; i++) {

    digitalWrite(ledPin, HIGH);

    delay(500);

    digitalWrite(ledPin, LOW);

    delay(500);

    Serial.println("15 Hazard-2 Function");//SERIAL MONITOR OUTPUT

    Serial.println("16 Alarm Honking-2");//SERIAL MONITOR OUTPUT

    mcp2515.sendMessage(&canMsg25);//declaration of a CAN message

  }

}

void Feedback_3_Function() {//To Activate Feedback_3_Function

  //TO BLINK THE LED THRICE

  for (i = 0; i <= 3; i++) {

    digitalWrite(ledPin, HIGH);

    delay(500);

    digitalWrite(ledPin, LOW);

    delay(500);

    Serial.println("15 Hazard-3 Function");//SERIAL MONITOR OUTPUT

    Serial.println("16 Alarm Honking-3");//SERIAL MONITOR OUTPUT

    mcp2515.sendMessage(&canMsg26);//declaration of a CAN message

  }

}

void Feedback_4_Function() {//To Activate Feedback_4_Function

  //TO BLINK THE LED FOUR TIMES

  for (i = 0; i <= 4; i++) {

    digitalWrite(ledPin, HIGH);

    delay(500);

    digitalWrite(ledPin, LOW);

    delay(500);

    Serial.println("15 Hazard-4 Function");//SERIAL MONITOR OUTPUT

    Serial.println("16 Alarm Honking-4");//SERIAL MONITOR OUTPUT

    mcp2515.sendMessage(&canMsg27);//declaration of a CAN message

  }

}

//**********************************************************************************

   Development of Instrument Cluster

The tell-Tles in the instrument cluster is given below


CREATED BY              :  AKASH.K

CREATED ON DATE  : 27October,2022.

SOFTWARE               :  ARDUINO

 

#include <Arduino_FreeRTOS.h>//Arduino Library used for implementation of FreeRTOS

#include <EasyNextionLibrary.h>//Arduino Library used for implementation of Nextion

#include <SPI.h>//Arduino Library used for Communication Process

#include <mcp2515.h>//Arduino Library used for CAN Message implementation

 

//=================================Declaration of Task Handler==========================

TaskHandle_t TaskSerial_Handler1;// Task Handler for Airbag

TaskHandle_t TaskSerial_Handler2;// Task Handler for Seatbelt

TaskHandle_t TaskSerial_Handler3;// Task Handler for Hazard

TaskHandle_t TaskSerial_Handler4;// Task Handler for FogLamp

TaskHandle_t TaskSerial_Handler5;// Task Handler for Battery

TaskHandle_t TaskSerial_Handler6;// Task Handler for PowerBrake

TaskHandle_t TaskSerial_Handler7;// Task Handler for BrakePedal

TaskHandle_t TaskSerial_Handler8;// Task Handler for WasherFluid

TaskHandle_t TaskSerial_Handler9;// Task Handler for ABSStatus

TaskHandle_t TaskSerial_Handler10;// Task Handler for PowerSteering

TaskHandle_t TaskSerial_Handler11;// Task Handler for RightTurn

TaskHandle_t TaskSerial_Handler12;// Task Handler for LeftTurn

TaskHandle_t TaskSerial_Handler13;// Task Handler for TyrePressure

TaskHandle_t TaskSerial_Handler14;// Task Handler for TractionControl

TaskHandle_t TaskSerial_Handler15;// Task Handler for OilLevel

TaskHandle_t TaskSerial_Handler16;// Task Handler for EngineCheck

TaskHandle_t TaskSerial_Handler17;// Task Handler for OpenDoor

 

//===========================Declaration of CAN Message Structure=========================

 

struct can_frame canMsg;//Receiver Message using CAN

 

struct can_frame canMsg1;//Transmission Message for Airbag_Status using CAN

struct can_frame canMsg2;//Transmission Message for Seatbelt_Status using CAN

struct can_frame canMsg3;//Transmission Message for Hazard_Status using CAN

struct can_frame canMsg4;//Transmission Message for Fog_Lamp using CAN

struct can_frame canMsg5;//Transmission Message for Battery_Status using CAN

struct can_frame canMsg6;//Transmission Message for Power_Brake using CAN

struct can_frame canMsg7;//Transmission Message for Brake_Pedal using CAN

struct can_frame canMsg8;//Transmission Message for Washer_Fluid using CAN

struct can_frame canMsg9;//Transmission Message for ABS_Status using CAN

struct can_frame canMsg10;//Transmission Message for Power_Steering using CAN

struct can_frame canMsg11;//Transmission Message for Right_Turn using CAN

struct can_frame canMsg12;//Transmission Message for Left_Turn using CAN

struct can_frame canMsg13;//Transmission Message for Tyre_Pressure using CAN

struct can_frame canMsg14;//Transmission Message for Traction_Control using CAN

struct can_frame canMsg15;//Transmission Message for Oil_Level using CAN

struct can_frame canMsg16;//Transmission Message for Engine_Check using CAN

struct can_frame canMsg17;//Transmission Message for Open_Door using CAN

 

MCP2515 mcp2515(10);//Declaration of specified Arduino board

 

//========================Declaration of Void Parameters==================================

 

void Airbag(void *pvParameters);//Void Parameter of Airbag                                            

void Seatbelt(void *pvParameters);//Void Parameter of Seatbelt

void Hazard(void *pvParameters);//Void Parameter of Hazard

void Fog_Light(void *pvParameters);//Void Parameter of Fog_Light

void Battery(void *pvParameters);//Void Parameter of Battery

void PowerBrake(void *pvParameters);//Void Parameter of PowerBrake

void BrakePedal(void *pvParameters);//Void Parameter of BrakePedal

void WasherFluid(void *pvParameters);//Void Parameter of WasherFluid

void ABSStatus(void *pvParameters);//Void Parameter of WasherFluid

void PowerSteering(void *pvParameters);//Void Parameter of PowerSteering

void RightTurn(void *pvParameters);//Void Parameter of RightTurn

void LeftTurn(void *pvParameters);//Void Parameter of LeftTurn

void TyrePressure(void *pvParameters);//Void Parameter of TyrePressure

void TractionControl(void *pvParameters);//Void Parameter of TractionControl

void OilLevel(void *pvParameters);//Void Parameter of OilLevel

void CheckEngine(void *pvParameters);//Void Parameter of CheckEngine

void DoorOpen(void *pvParameters);//Void Parameter of DoorOpen

 

EasyNex myNex(Serial); //Initialising Parameter the HArdware Serial you are going to Use

 

 

//=============================Variable Declaration of warning Lamps=======================

 

bool Airbag_Status   = HIGH; //Declaration of Airbag_Status

bool Seatbelt_Status = HIGH;//Declaration of Seatbelt_Status

bool Hazard_Status   = HIGH;//Declaration of Hazard_Status

bool Fog_Lamp        = LOW; //Declaration of Fog_Lamp

bool Battery_Status  = HIGH;//Declaration of Battery_Status 

bool Power_Brake     = LOW; //Declaration of Power_Brake

bool Brake_Pedal     = HIGH;//Declaration of Brake_Pedal

bool Washer_Fluid    = HIGH;//Declaration of Washer_Fluid

bool ABS_Status      = LOW; //Declaration of ABS_Status

bool Power_Steering  = LOW; //Declaration of Power_Steering

bool Right_Turn      = LOW; //Declaration of Right_Turn

bool Left_Turn       = LOW; //Declaration of Left_Turn

bool Tyre_Pressure   = HIGH;//Declaration of Tyre_Pressure

bool Traction_Control= LOW; //Declaration of Traction_Control

bool Oil_Level         = HIGH;//Declaration of Oil_Level

bool Engine_Check    = HIGH;//Declaration of Engine_Check

bool Open_Door       = LOW; //Declaration of Open_Door

 

 

 

void setup() {

 

  myNex.begin(9600); // To initialise Nextion communication at (9600 baud rate)

 

//=====================Declaration of Function Calling========================

 

//===Task===== Name of Function = Stack Size = Parameters = Priority = Task Handle===========

 

  xTaskCreate( Airbag                     , "1" , 128, NULL, 1, &TaskSerial_Handler1);

  xTaskCreate( Seatbelt                   , "2" , 128, NULL, 2, &TaskSerial_Handler2);

  xTaskCreate( Hazard                     , "3" , 128, NULL, 3, &TaskSerial_Handler3);

  xTaskCreate( Fog_Light                 , "4" , 128, NULL, 1, &TaskSerial_Handler4);

  xTaskCreate( Battery                     , "5" , 128, NULL, 2, &TaskSerial_Handler5);

  xTaskCreate( PowerBrake             , "6" , 128, NULL, 3, &TaskSerial_Handler6);

  xTaskCreate( Brake_Pedal            , "7" , 128, NULL, 1, &TaskSerial_Handler7);

  xTaskCreate( WasherFluid            , "8" , 128, NULL, 1, &TaskSerial_Handler8);

  xTaskCreate( ABSStatus                , "9" , 128, NULL, 1, &TaskSerial_Handler9);

  xTaskCreate( PowerSteering       , "10", 128, NULL, 1, &TaskSerial_Handler10);

  xTaskCreate( RightTurn                , "11", 128, NULL, 1, &TaskSerial_Handler11);

  xTaskCreate( Left_Turn                , "12", 128, NULL, 2, &TaskSerial_Handler12);

  xTaskCreate( Tyre_Pressure        , "13", 128, NULL, 3, &TaskSerial_Handler13);

  xTaskCreate( Traction_Control   , "14", 128, NULL, 3, &TaskSerial_Handler14);

  xTaskCreate( Oil_Level                 , "15", 128, NULL, 2, &TaskSerial_Handler15);

  xTaskCreate( Engine_Check        , "16", 128, NULL, 3, &TaskSerial_Handler16);

  xTaskCreate( Open_Door            , "17", 128, NULL, 1, &TaskSerial_Handler17);

}

 

 

  mcp2515.reset();//Initialising reset function

  mcp2515.setBitrate(CAN_500KBPS, MCP_8MHZ);//Setting bitrate for CAN protocol

  mcp2515.setNormalMode();//Initialising NormalMode

 

//===============Declaration of CAN ID,CAN DATA LENGTH and CAN DATA======================

 

  canMsg1.can_id = 0x001; // Airbag_Status

  canMsg1.can_dlc = 1;

  canMsg1.data[0] = 0x01;

 

  canMsg2.can_id = 0x001; // Seatbelt_Status

  canMsg2.can_dlc = 1;

  canMsg2.data[0] = 0x02;

 

  canMsg3.can_id = 0x001; // Hazard_Status

  canMsg3.can_dlc = 1;

  canMsg3.data[0] = 0x03;

 

  canMsg4.can_id = 0x001; // Fog_Lamp

  canMsg4.can_dlc = 1;

  canMsg4.data[0] = 0x04;

 

  canMsg5.can_id = 0x001; // Battery_Status

  canMsg5.can_dlc = 1;

  canMsg5.data[0] = 0x05;

 

  canMsg6.can_id = 0x001; // Power_Brake

  canMsg6.can_dlc = 1;

  canMsg6.data[0] = 0x06;

 

  canMsg7.can_id = 0x001; // Brake_Pedal

  canMsg7.can_dlc = 1;

  canMsg7.data[0] = 0x07;

 

  canMsg8.can_id = 0x001; // Washer_Fluid

  canMsg8.can_dlc = 1;

  canMsg8.data[0] = 0x08;

 

  canMsg9.can_id = 0x001; // ABS_Status

  canMsg9.can_dlc = 1;

  canMsg9.data[0] = 0x09;

 

  canMsg10.can_id = 0x001; // Power_Steering

  canMsg10.can_dlc = 1;

  canMsg10.data[0] = 0x10;

 

  canMsg11.can_id = 0x001; // Right_Turn

  canMsg11.can_dlc = 1;

  canMsg11.data[0] = 0x11;

 

  canMsg12.can_id = 0x001; // Left_Turn

  canMsg12.can_dlc = 1;

  canMsg12.data[0] = 0x12;

 

  canMsg13.can_id = 0x001; // Tyre_Pressure

  canMsg13.can_dlc = 1 ;

  canMsg13.data[0] = 0x13;

 

  canMsg14.can_id = 0x001; // Traction_Control

  canMsg14.can_dlc = 1 ;

  canMsg14.data[0] = 0x14;

 

  canMsg15.can_id = 0x001; // Oil_Level

  canMsg15.can_dlc = 1;

  canMsg15.data[0] = 0x15;

 

  canMsg16.can_id = 0x001; // Engine_Check

  canMsg16.can_dlc = 1;

  canMsg16.data[0] = 0x16;

 

  canMsg17.can_id = 0x001; // Open_Door

  canMsg17.can_dlc = 1;

  canMsg17.data[0] = 0x17;

 

}

 

void loop() {

 

  if (mcp2515.readMessage(&canMsg) == MCP2515::ERROR_OK) {{ //To Read CAN Message

   

}

 

}

 

  void Battery(void *pvParameters) {//To Define a PowerBrake Function

    for(;;)//A Task shall never return or exit.

    {

    if (Battery_Status == LOW) {//To Check The Required Status

      myNex.writeStr("vis p4,1");//Command to Show Picture

      mcp2515.sendMessage(&canMsg5);//Declaration of CAN Message

    } else {

      myNex.writeStr("vis p4,0");//Command to Hide Picture

      mcp2515.sendMessage(&canMsg5);//Declaration of CAN Message

    }

    Serial.write(0xff);

    Serial.write(0xff);

    Serial.write(0xff);

  }

  }

 

 

  void PowerBrake(void *pvParameters) {//To Define a PowerBrake Function

    for(;;)//A Task shall never return or exit.

    {

    if (Power_Brake == HIGH) {//To Check The Required Status

      myNex.writeStr("vis p5,1");//Command to Show Picture

      mcp2515.sendMessage(&canMsg6);//Declaration of CAN Message

    } else {

      myNex.writeStr("vis p5,0");//Command to Hide Picture

      mcp2515.sendMessage(&canMsg6);//Declaration of CAN Message

    }

    Serial.write(0xff);

    Serial.write(0xff);

    Serial.write(0xff);

  }

  }

 

  void BrakePedal(void *pvParameters) {//To Define a BrakePedal Function

    for(;;)//A Task shall never return or exit.

    {

    if (Brake_Pedal == LOW) {//To Check The Required Status

      myNex.writeStr("vis p6,1");//Command to Show Picture

      mcp2515.sendMessage(&canMsg7);//Declaration of CAN Message

    } else {

      myNex.writeStr("vis p6,0");//Command to Hide Picture

      mcp2515.sendMessage(&canMsg7);//Declaration of CAN Message

    }

    Serial.write(0xff);

    Serial.write(0xff);

    Serial.write(0xff);

  }

  }

 

  void WasherFluid(void *pvParameters) {//To Define a WasherFluid Function

    for(;;)//A Task shall never return or exit.

    {

    if (Washer_Fluid == LOW) {//To Check The Required Status

      myNex.writeStr("vis p7,1");// Command to Show Picture

      mcp2515.sendMessage(&canMsg8);//Declaration of CAN Message

    } else {

      myNex.writeStr("vis p7,0");//Command to Hide Picture

      mcp2515.sendMessage(&canMsg8);//Declaration of CAN Message

    }

    Serial.write(0xff);

    Serial.write(0xff);

    Serial.write(0xff);

  }

  }

 

  void Fog_Light(void *pvParameters) {//To Define a Fog_Light Function

    for(;;)//A Task shall never return or exit.

    {

    myNex.writeStr("vis p8,0");//Command to Hide Picture

    if (Fog_Lamp == HIGH) {//To Check The Required Status

      myNex.writeStr("vis p8,1");//Command to Show Picture

      mcp2515.sendMessage(&canMsg4);//Declaration of CAN Message

    } else {

      myNex.writeStr("vis p8,0");//Command to Hide Picture

      mcp2515.sendMessage(&canMsg4);//Declaration of CAN Message

    }

    Serial.write(0xff);

    Serial.write(0xff);

    Serial.write(0xff);

  }

  }

 

  void ABSStatus(void *pvParameters) {//To Define a ABSStatus Function

    for(;;)//A Task shall never return or exit.

    {

    if (ABS_Status == HIGH) {//To Check The Required Status

      myNex.writeStr("vis p9,1");//Command to Show Picture

      mcp2515.sendMessage(&canMsg9);//Declaration of CAN Message

    } else {

      myNex.writeStr("vis p9,0");//Command to Hide Picture

      mcp2515.sendMessage(&canMsg9);//Declaration of CAN Message

    }

    Serial.write(0xff);

    Serial.write(0xff);

    Serial.write(0xff);

  }

  }

 

  void PowerSteering(void *pvParameters) {//To Define a PowerSteering Function

    for(;;)//A Task shall never return or exit.

    {

    if (Power_Steering == HIGH) {//To Check The Required Status

      myNex.writeStr("vis p10,1");//Command to Show Picture

      mcp2515.sendMessage(&canMsg10);//Declaration of CAN Message

    } else {

      myNex.writeStr("vis p10,0");//Command to Hide Picture

      mcp2515.sendMessage(&canMsg10);//Declaration of CAN Message

    }

    Serial.write(0xff);

    Serial.write(0xff);

    Serial.write(0xff);

  }

  }

 

  void RightTurn(void *pvParameters) {//To Define a RightTurn Function

    for(;;)//A Task shall never return or exit.

    {

    if (Right_Turn == HIGH) {//To Check The Required Status

      myNex.writeStr("vis p11,1");//Command to Show Picture

      mcp2515.sendMessage(&canMsg11);//Declaration of CAN Message

    } else {

      myNex.writeStr("vis p11,0");//Command to Hide Picture

      mcp2515.sendMessage(&canMsg11);//Declaration of CAN Message

    }

 

    Serial.write(0xff);

    Serial.write(0xff);

    Serial.write(0xff);

  }

  }

 

  void LeftTurn(void *pvParameters) {//To Define a LeftTurn Function

    for(;;)//A Task shall never return or exit.

    {

    if (Left_Turn == HIGH) {//To Check The Required Status

      myNex.writeStr("vis p12,1");//Command to Show Picture

      mcp2515.sendMessage(&canMsg12);//Declaration of CAN Message

    } else {

      myNex.writeStr("vis p12,0");//Command to Hide Picture

      mcp2515.sendMessage(&canMsg12);//Declaration of CAN Message

    }

    Serial.write(0xff);

    Serial.write(0xff);

    Serial.write(0xff);

  }

  }

 

  void TyrePressure(void *pvParameters) {//To Define a TyrePressure Function

    for(;;)//A Task shall never return or exit.

    {

    if (Tyre_Pressure == LOW) {//To Check The Required Status

      myNex.writeStr("vis p13,1");// Command to Show Picture

      mcp2515.sendMessage(&canMsg13);//Declaration of CAN Message

    } else {

      myNex.writeStr("vis p13,0");//Command to Hide Picture

      mcp2515.sendMessage(&canMsg13);//Declaration of CAN Message

    }

    Serial.write(0xff);

    Serial.write(0xff);

    Serial.write(0xff);

  }

  }

 

  void TractionControl(void *pvParameters) {//To Define a TractionControl Function

    for(;;)//A Task shall never return or exit.

    {

    if (Traction_Control == HIGH) {//To Check The Required Status

      myNex.writeStr("vis p14,1");// Command to Show Picture

      mcp2515.sendMessage(&canMsg14);//Declaration of CAN Message

    } else {

      myNex.writeStr("vis p14,0");//Command to Hide Picture

      mcp2515.sendMessage(&canMsg14);//Declaration of CAN Message

    }

    Serial.write(0xff);

    Serial.write(0xff);

    Serial.write(0xff);

  }

  }

 

  void Airbag(void *pvParameters) {//To Define a Airbag Function

    for(;;)//A Task shall never return or exit.

    {

    if (Airbag_Status == HIGH) {//To Check The Required Status

      myNex.writeStr("vis p15,0");//Command to Hide Picture

      myNex.writeStr("t0.pco=2024");// Command to Show Text in Green colour

      myNex.writeStr("t0.txt", "AIRBAG ACTIVATED");//Visual Feedback

      mcp2515.sendMessage(&canMsg1);//Declaration of CAN Message

    }

 

    else if (Airbag_Status == LOW) {//To Check The Required Status

      myNex.writeStr("vis p15,1");// Command to Show Picture

      myNex.writeStr("t0.pco=63496");// Command to Show Text in Red colour

      myNex.writeStr("t0.txt", "AIRBAG DE-ACTIVATED");//Visual Feedback

      mcp2515.sendMessage(&canMsg1);//Declaration of CAN Message

    }

    Serial.write(0xff);

    Serial.write(0xff);

    Serial.write(0xff);

  }

  }

 

  void OilLevel(void *pvParameters) {//To Define a OilLevel Function

     for(;;)//A Task shall never return or exit.

    {

    if (Oil_Level == LOW) {//To Check The Required Status

      myNex.writeStr("vis p16,1");// Command to Show Picture

      mcp2515.sendMessage(&canMsg15);//Declaration of CAN Message

    } else {

      myNex.writeStr("vis p16,0");//Command to Hide Picture

      mcp2515.sendMessage(&canMsg15);//Declaration of CAN Message

    }

    Serial.write(0xff);

    Serial.write(0xff);

    Serial.write(0xff);

  }

  }

 

  void CheckEngine(void *pvParameters) {//To Define a CheckEngine Function

    for(;;)//A Task shall never return or exit.

    {

    if (CheckEngine == HIGH) {//To Check The Required Status

      myNex.writeStr("vis p17,1");//Command to Show Picture

      mcp2515.sendMessage(&canMsg16);//Declaration of CAN Message

    } else {

      myNex.writeStr("vis p17,0");//Command to Hide Picture

      mcp2515.sendMessage(&canMsg16);//Declaration of CAN Message

    }

    Serial.write(0xff);

    Serial.write(0xff);

    Serial.write(0xff);

  }

  }

 

  void DoorOpen(void *pvParameters) {//To Define a DoorOpen Function

    for(;;)//A Task shall never return or exit.

    {

    if (DoorOpen == LOW) {//To Check The Required Status

      myNex.writeStr("vis p18,1");//Command to Show Picture

      mcp2515.sendMessage(&canMsg17);//Declaration of CAN Message

    } else {

      myNex.writeStr("vis p18,0");//Command to Hide Picture

      mcp2515.sendMessage(&canMsg17);//Declaration of CAN Message

    }

    Serial.write(0xff);

    Serial.write(0xff);

    Serial.write(0xff);

  }

  }

 

  void Hazard(void *pvParameters) {//To Define a Hazard Function

    for(;;)//A Task shall never return or exit.

 {

  

    if (Hazard_Status == HIGH) {//To Check The Required Status

      myNex.writeStr("vis p19,1");//Command to Show Picture

      vTaskDelay( 1000 / portTICK_PERIOD_MS );// Used to wait for one second

      myNex.writeStr("vis p19,0");//Command to Hide Picture

      vTaskDelay( 1000 / portTICK_PERIOD_MS );// Used to wait for one second

      mcp2515.sendMessage(&canMsg3);//Declaration of CAN Message

    } else {

      myNex.writeStr("vis p19,0");//Command to Hide Picture

      mcp2515.sendMessage(&canMsg3);//Declaration of CAN Message

    }

    Serial.write(0xff);

    Serial.write(0xff);

    Serial.write(0xff);

  }

  }

  void Seatbelt(void *pvParameters) {//To Define a Seatbelt Function

    for(;;)//A Task shall never return or exit.

    {

      if (Seatbelt_Status == HIGH) {//To Check The Required Status

      myNex.writeStr("vis p20,0");// Command to Hide Picture

      myNex.writeStr("t1.pco=2024");//Command to Show Text in Green colour

      myNex.writeStr("t1.txt", "SEATBELT BUCKLED");// Visual Feedback

      mcp2515.sendMessage(&canMsg2);//Declaration of CAN Message

    } else if (Seatbelt_Status == LOW) {//To Check The Required Status

      myNex.writeStr("vis p20,1");//Command to Show Picture

      myNex.writeStr("t1.pco=63496");//Command to Show Text in Red colour

      myNex.writeStr("t1.txt", "SEATBELT NOT BUCKLED");//Visual Feedback

      mcp2515.sendMessage(&canMsg2);//Declaration of CAN Message

    }

    Serial.write(0xff);

    Serial.write(0xff);

    Serial.write(0xff);

  }

  }

//********************************************************************************

SEATBELT REMINDER

 // Created by  : Akash.k

   // Created on  :September 30,2022.

  //  Software     : Arduino IDE

   

#include <SPI.h> //Arduino Library  used for communication between Ardunio amd MCP2515 CAn Controller                                      

#include <mcp2515.h>//Arduino Library used for CAN message Implementation

 

// ===================Declaration of CAN Message Structure=========================

 

struct can_frame canMsg;//Receiver Message using CAN

struct can_frame canMsg1;//Transmission Message for DRIVER _SEAT  using CAN

struct can_frame canMsg2;//Transmission Message for  FRONTPASS_SEAT using CAN

struct can_frame canMsg3;//Transmission Message for REARLEFT_SEAT using CAN

struct can_frame canMsg4;//Transmission Message for REARRIGHT_SEAT using CAN

 

MCP2515 mcp2515(10);//Declaration of specified Arduino board

 

 

//==================SeatBelt_Status======================================

// [0=close/Low][1=opened/High]

bool SeatBelt_DR; //Declaration of Seatbelt status for Driver seat

bool SeatBelt_FL; //Declaration of Seatbelt status for FrontLeft Seat

bool SeatBelt_RL; //Declaration of Seatbelt status for RearLeft Seat

bool SeatBelt_RR; //Declaration of Seatbelt status for RearRight Seat

 

//======================Ignition_Status===================================== //[0=Off/Low][1=On/High]

bool Ignition_Status; Declaration of IgnitionStatus

 

//========================Door_Status ====================================

//[0=closed/Low][1=opened/High]

bool Door_Status;//Declaration of door status common for all four passenger doors

 

//=================SeatOccupant_Status==================================

//[0=absence/Low][1=presence/High]

bool Seat_Occupant_DR; //Declaration of Seat Occupant Status for Driver Seat

bool Seat_Occupant_FL; //Declaration of Seat Occupant Status for Front Left

bool Seat_Occupant_RL; //Declaration of Seat Occupant Status for RearLeft

bool Seat_Occupant_RR; //Declaration of Seat Occupant Status for RearRight

 

//=============Airbag_Status======================================

//[0=Deactivated/Low][1=Activated/High]

bool AirbagStatus_DR; //Declaration of AirbagStatus for Driver Seat

bool AirbagStatus_FL; //Declaration of AirbagStatus for Front Left

bool AirbagStatus_RL; //Declaration of AirbagStatus for RearLeft

bool AirbagStatus_RR; //Declaration of AirbagStatus for RearRight

 

==============Vehicle_Speed_Status=========================================

int Vehicle_Speed;// Declaration if Vehicle Speed                       

 

===========Feedback===================================================

int Audio_Status; //Declaration of AudioStatus

 

int Visual_Status; // Declaration of VideoStatus

 

int Warning_Lamp;//Declaration of Warning Lamp

                                  //condition:On ,Off ,Low frequency ,High frequency

int Buzzer_Status; //Declaration of BuzzerStatus

                                 //condition:On ,Off ,Low frequency,High frequency

 

void setup() {

  Serial.begin(9600);// To initialise Serial communication at (9600 baud rate)

 

//=======Declaration of CAN ID,CAN DATA LENGTH and CAN DATA==================

  canMsg1.can_id  = 0x010;//DRIVER_SEAT

  canMsg1.can_dlc = 1;

  canMsg1.data[0] = 0x1;

 

  canMsg2.can_id  = 0x020;//FRONTPASS_SEAT

  canMsg2.can_dlc = 1;

  canMsg2.data[0] = 0x2;

 

  canMsg3.can_id  = 0x030;//REARLEFT_SEAT

  canMsg3.can_dlc = 1;

  canMsg3.data[0] = 0x4;

 

  canMsg4.can_id  = 0x040;//REARRIGHT_SEAT

  canMsg4.can_dlc = 1;

  canMsg4.data[0] = 0x8;

  mcp2515.reset();//Initialising reset function

  mcp2515.setBitrate(CAN_500KBPS, MCP_8MHZ);//Setting bitrate for CAN protocol

  mcp2515.setNormalMode();//Initialising NormalMode

}

//============MAIN LOOP========================================

void loop() {

  // put your main code here, to run repeatedly:

  if (mcp2515.readMessage(&canMsg) == MCP2515::ERROR_OK) { //To Read CAN Message

    switch ((canMsg.can_id) ) {  //Switchcase Implementation

      case (0x001) :

        Driver_Seat();//calling Driver_Seat function

        FrontPass_Seat();//calling Front Left function

        RearRight_Seat();//calling RearRight function

        RearLeft_Seat();//calling Rear Left function

    }

  }

}

//============DRIVER-SEAT========================================

void Driver_Seat () {

 if (SeatBelt_DR  == LOW && Ignition_Status == LOW && Door_Status == LOW && Seat_Occupant_DR == LOW) {

    Serial.println("NO ERROR DR1"); //Serial Monitor output

    Serial.println("Airbag_DeActivated");//Serial Monitor output

    AirbagStatus_DR = LOW;   //Airbag Status for Driver

    mcp2515.sendMessage(&canMsg1);  //Declaration of CAN Message

  }

  else if (SeatBelt_DR  == HIGH && Ignition_Status == HIGH && Door_Status == HIGH && Seat_Occupant_DR == HIGH) {

    Serial.println("NO ERROR DR2");//Serial Monitor output

    Serial.println("Airbag_Activated");//Serial Monitor output

    AirbagStatus_DR = HIGH; //Airbag Status for Driver

    mcp2515.sendMessage(&canMsg1); //Declaration of CAN Message

  }

  else if (SeatBelt_DR  == LOW && Ignition_Status == LOW && Door_Status == LOW && Seat_Occupant_DR == HIGH) {

    Serial.println("NO ERROR DR3");//Serial Monitor output

    Serial.println("Airbag_DeActivated");//Serial Monitor output

    AirbagStatus_DR = LOW; //Airbag Status for Driver

    mcp2515.sendMessage(&canMsg1); //Declaration of CAN Message

 

  }

  else if (SeatBelt_DR  == LOW && Ignition_Status == LOW && Door_Status == HIGH && Seat_Occupant_DR == LOW) {

    Serial.println("NO ERROR DR4");//Serial Monitor output

    Serial.println("Airbag_DeActivated");//Serial Monitor output

    AirbagStatus_DR = LOW; //Airbag Status for Driver

    mcp2515.sendMessage(&canMsg1); //Declaration of CAN Message

  }

  else if (SeatBelt_DR  == LOW && Ignition_Status == HIGH && Door_Status == LOW && Seat_Occupant_DR == LOW) {

    Serial.println("Buckle Seatbelt DR5");//Serial Monitor output

    Serial.println("Airbag_DeActivated");//Serial Monitor output

    Audio_Feedback(); //Audio Feedback function is called

    Visual_Feedback();Visual Feedback function is called

    Beep_Function();Beep function is called

    AirbagStatus_DR = LOW; //Airbag Status for Driver

    mcp2515.sendMessage(&canMsg1); //Declaration of CAN Message

 

  }

  else if (SeatBelt_DR  == HIGH && Ignition_Status == LOW && Door_Status == LOW && Seat_Occupant_DR == LOW) {

    Serial.println("NO ERROR DR6");//Serial Monitor output

    Serial.println("Airbag_DeActivated");//Serial Monitor output

    AirbagStatus_DR = LOW; //Airbag Status for Driver

    mcp2515.sendMessage(&canMsg1); //Declaration of CAN Message

 

  }

  else if (SeatBelt_DR  == LOW && Ignition_Status == LOW && Door_Status == HIGH && Seat_Occupant_DR == HIGH) {

    Serial.println("Buckle Seatbelt DR7");//Serial Monitor output

    Serial.println("Airbag_DeActivated");//Serial Monitor output

    Audio_Feedback();//Audio Feedback function is called

    Visual_Feedback(); //Visual Feedback function is called

    Beep_Function();Beep function is called

    AirbagStatus_DR = LOW; //Airbag Status for Driver

    mcp2515.sendMessage(&canMsg1); //Declaration of CAN Message

 

  }

  else if (SeatBelt_DR  == LOW && Ignition_Status == HIGH && Door_Status == HIGH && Seat_Occupant_DR == LOW) {

    Serial.println("NO ERROR DR8");//Serial Monitor output

    Serial.println("Airbag_DeActivated");//Serial Monitor output

    AirbagStatus_DR = LOW; //Airbag Status for Driver

    mcp2515.sendMessage(&canMsg1); //Declaration of CAN Message

 

  }

  else if (SeatBelt_DR  == HIGH && Ignition_Status == HIGH && Door_Status == LOW && Seat_Occupant_DR == LOW) {

    Serial.println("Buckle Seatbelt 9");//Serial Monitor output

    Serial.println("Airbag_DeActivated");//Serial Monitor output

    Audio_Feedback();//Audio Feedback function is called

    Visual_Feedback();//Visual Feedback function is called

    Beep_Function();Beep function is called

    AirbagStatus_DR = LOW; //Airbag Status for Driver

    mcp2515.sendMessage(&canMsg1); //Declaration of CAN Message

 

  }

  else if (SeatBelt_DR  == HIGH && Ignition_Status == LOW && Door_Status == HIGH && Seat_Occupant_DR == LOW) {

    Serial.println("NO ERROR DR10");//Serial Monitor output

    Serial.println("Airbag_DeActivated");//Serial Monitor output

    AirbagStatus_DR = LOW; //Airbag Status for Driver

    mcp2515.sendMessage(&canMsg1); //Declaration of CAN Message

 

  }

  else if (SeatBelt_DR  == LOW && Ignition_Status == HIGH && Door_Status == LOW && Seat_Occupant_DR == HIGH) {

    Serial.println("NO ERROR DR11");//Serial Monitor output

    Serial.println("Airbag_DeActivated");//Serial Monitor output

    AirbagStatus_DR = LOW; //Airbag Status for Driver

    mcp2515.sendMessage(&canMsg1); //Declaration of CAN Message

 

  }

  else if (SeatBelt_DR  == HIGH && Ignition_Status == LOW && Door_Status == LOW && Seat_Occupant_DR == HIGH) {

    Serial.println("NO ERROR DR12");//Serial Monitor output

    Serial.println("Airbag_Activated");//Serial Monitor output

    AirbagStatus_DR = HIGH; //Airbag Status for Driver

    mcp2515.sendMessage(&canMsg1); //Declaration of CAN Message

 

  }

  else if (SeatBelt_DR  == HIGH && Ignition_Status == HIGH && Door_Status == HIGH && Seat_Occupant_DR == LOW) {

    Serial.println("NO ERROR DR13");//Serial Monitor output

    Serial.println("Airbag_DeActivated");//Serial Monitor output

    AirbagStatus_DR = LOW; //Airbag Status for Driver

    mcp2515.sendMessage(&canMsg1); //Declaration of CAN Message

 

  }

  else if (SeatBelt_DR  == HIGH && Ignition_Status == HIGH && Door_Status == LOW && Seat_Occupant_DR == HIGH) {

    Serial.println("NO ERROR DR14");//Serial Monitor output

    Serial.println("Airbag_Activated");//Serial Monitor output

    AirbagStatus_DR = HIGH; //Airbag Status for Driver

    mcp2515.sendMessage(&canMsg1); //Declaration of CAN Message

 

  }

  else if (SeatBelt_DR  == HIGH && Ignition_Status == LOW && Door_Status == HIGH && Seat_Occupant_DR == HIGH) {

    Serial.println("NO ERROR DR15");//Serial Monitor output

    Serial.println("Airbag_Activated");//Serial Monitor output

    AirbagStatus_DR = HIGH; //Airbag Status for Driver

    mcp2515.sendMessage(&canMsg1); //Declaration of CAN Message

 

  }

  else if (SeatBelt_DR  == LOW && Ignition_Status == HIGH && Door_Status == HIGH && Seat_Occupant_DR == HIGH) {

    Serial.println("Buckle Seatbelt DR16");//Serial Monitor output

    Serial.println("Airbag_DeActivated");//Serial Monitor output

    Audio_Feedback();//Audio Feedback function is called

    Visual_Feedback();//Visual Feedback function is called

    Beep_Function();Beep function is called

    AirbagStatus_DR = LOW; //Airbag Status for Driver

    mcp2515.sendMessage(&canMsg1); //Declaration of CAN Message

 

  }

  Serial.println();

}

//============FRONT-PASSENGER-SEAT================================

void FrontPass_Seat() {

  if (SeatBelt_FL  == LOW && Ignition_Status == LOW && Door_Status == LOW && Seat_Occupant_FL == LOW) {

    Serial.println("NO ERROR FL1");//Serial Monitor output

    Serial.println("Airbag_DeActivated");//Serial Monitor output

    AirbagStatus_FL = LOW; //Airbag Status for Front Left Passenger

    mcp2515.sendMessage(&canMsg2); //Declaration of CAN Message

 

  }

  else if (SeatBelt_FL  == HIGH && Ignition_Status == HIGH && Door_Status == HIGH && Seat_Occupant_FL == HIGH) {

    Serial.println("NO ERROR FL2");//Serial Monitor output

    Serial.println("Airbag_Activated");//Serial Monitor output

    AirbagStatus_FL = HIGH; //Airbag Status for Front Left Passenger

    mcp2515.sendMessage(&canMsg2); //Declaration of CAN Message

 

  }

  else if (SeatBelt_FL  == LOW && Ignition_Status == LOW && Door_Status == LOW && Seat_Occupant_FL == HIGH) {

    Serial.println("NO ERROR FL3");//Serial Monitor output

    Serial.println("Airbag_DeActivated");//Serial Monitor output

    AirbagStatus_FL = LOW; //Airbag Status for Front Left Passenger

    mcp2515.sendMessage(&canMsg2); //Declaration of CAN Message

 

  }

  else if (SeatBelt_FL == LOW && Ignition_Status == LOW && Door_Status == HIGH && Seat_Occupant_FL == LOW) {

    Serial.println("NO ERROR FL4");//Serial Monitor output

    Serial.println("Airbag_DeActivated");//Serial Monitor output

    AirbagStatus_FL = LOW; //Airbag Status for Front Left Passenger

    mcp2515.sendMessage(&canMsg2); //Declaration of CAN Message

 

  }

  else if (SeatBelt_FL == LOW && Ignition_Status == HIGH && Door_Status == LOW && Seat_Occupant_FL == LOW) {

    Serial.println("Buckle Seatbelt FL5");//Serial Monitor output

    Serial.println("Airbag_DeActivated");//Serial Monitor output

    Audio_Feedback();//Audio Feedback function is called

    Visual_Feedback();//Visual Feedback function is called

    Beep_Function();Beep function is called

    AirbagStatus_FL = LOW; //Airbag Status for Front Left Passenger

    mcp2515.sendMessage(&canMsg2); //Declaration of CAN Message

 

  }

  else if (SeatBelt_FL  == HIGH && Ignition_Status == LOW && Door_Status == LOW && Seat_Occupant_FL == LOW) {

    Serial.println("NO ERROR FL6");//Serial Monitor output

    Serial.println("Airbag_DeActivated");//Serial Monitor output

    AirbagStatus_FL = LOW; //Airbag Status for Front Left Passenger

    mcp2515.sendMessage(&canMsg2); //Declaration of CAN Message

 

  }

  else if (SeatBelt_FL  == LOW && Ignition_Status == LOW && Door_Status == HIGH && Seat_Occupant_FL == HIGH) {

    Serial.println("Buckle Seatbelt FL7");//Serial Monitor output

    Serial.println("Airbag_Activated");//Serial Monitor output

    Audio_Feedback();//Audio Feedback function is called

    Visual_Feedback();//Visual Feedback function is called

    Beep_Function();Beep function is called

    AirbagStatus_FL = HIGH; //Airbag Status for Front Left Passenger

    mcp2515.sendMessage(&canMsg2); //Declaration of CAN Message

 

  }

  else if (SeatBelt_FL == LOW && Ignition_Status == HIGH && Door_Status == HIGH && Seat_Occupant_FL == LOW) {

    Serial.println("NO ERROR FL8");//Serial Monitor output

    Serial.println("Airbag_DeActivated");//Serial Monitor output

    AirbagStatus_FL = LOW; //Airbag Status for Front Left Passenger

    mcp2515.sendMessage(&canMsg2); //Declaration of CAN Message

 

  }

  else if (SeatBelt_FL  == HIGH && Ignition_Status == HIGH && Door_Status == LOW && Seat_Occupant_FL == LOW) {

    Serial.println("Buckle Seatbelt 9");//Serial Monitor output

    Serial.println("Airbag_DeActivated");//Serial Monitor output

    Audio_Feedback();//Audio Feedback function is called

    Visual_Feedback();//Visual Feedback function is called

    Beep_Function();Beep function is called

    AirbagStatus_FL = LOW; //Airbag Status for Front Left Passenger

    mcp2515.sendMessage(&canMsg2); //Declaration of CAN Message

 

  }

  else if (SeatBelt_FL == HIGH && Ignition_Status == LOW && Door_Status == HIGH && Seat_Occupant_FL == LOW) {

    Serial.println("NO ERROR FL10");//Serial Monitor output

    Serial.println("Airbag_DeActivated");//Serial Monitor output

    AirbagStatus_FL = LOW; //Airbag Status for Front Left Passenger

    mcp2515.sendMessage(&canMsg2); //Declaration of CAN Message

 

  }

  else if (SeatBelt_FL  == LOW && Ignition_Status == HIGH && Door_Status == LOW && Seat_Occupant_FL == HIGH) {

    Serial.println("NO ERROR FL11");//Serial Monitor output

    Serial.println("Airbag_DeActivated");//Serial Monitor output

    AirbagStatus_FL = LOW; //Airbag Status for Front Left Passenger

    mcp2515.sendMessage(&canMsg2); //Declaration of CAN Message

 

  }

  else if (SeatBelt_FL  == HIGH && Ignition_Status == LOW && Door_Status == LOW && Seat_Occupant_FL == HIGH) {

    Serial.println("NO ERROR FL12");//Serial Monitor output

    Serial.println("Airbag_Activated");//Serial Monitor output

    AirbagStatus_FL = HIGH; //Airbag Status for Front Left Passenger

    mcp2515.sendMessage(&canMsg2); //Declaration of CAN Message

 

  }

  else if (SeatBelt_FL  == HIGH && Ignition_Status == HIGH && Door_Status == HIGH && Seat_Occupant_FL == LOW) {

    Serial.println("NO ERROR FL13");//Serial Monitor output

    Serial.println("Airbag_DeActivated");//Serial Monitor output

    AirbagStatus_FL = LOW; //Airbag Status for Front Left Passenger

    mcp2515.sendMessage(&canMsg2); //Declaration of CAN Message

 

  }

  else if (SeatBelt_FL  == HIGH && Ignition_Status == HIGH && Door_Status == LOW && Seat_Occupant_FL == HIGH) {

    Serial.println("NO ERROR FL14");//Serial Monitor output

    Serial.println("Airbag_Activated");//Serial Monitor output

    AirbagStatus_FL = HIGH; //Airbag Status for Front Left Passenger

    mcp2515.sendMessage(&canMsg2); //Declaration of CAN Message

 

  }

  else if (SeatBelt_FL == HIGH && Ignition_Status == LOW && Door_Status == HIGH && Seat_Occupant_FL == HIGH) {

    Serial.println("NO ERROR FL15");//Serial Monitor output

    Serial.println("Airbag_Activated");//Serial Monitor output

    AirbagStatus_FL = 1; //Airbag Status for Front Left Passenger

    mcp2515.sendMessage(&canMsg2); //Declaration of CAN Message

 

  }

  else if (SeatBelt_FL  == LOW && Ignition_Status == HIGH && Door_Status == HIGH && Seat_Occupant_FL == HIGH) {

    Serial.println("Buckle Seatbelt FL16");//Serial Monitor output

    Serial.println("Airbag_DeActivated");//Serial Monitor output

    Audio_Feedback();//Audio Feedback function is called

    Visual_Feedback();//Visual Feedback function is called

    Beep_Function();Beep function is called

    AirbagStatus_FL = LOW; //Airbag Status for Front Left Passenger

    mcp2515.sendMessage(&canMsg2); //Declaration of CAN Message

 

  }

  Serial.println();

}

//===========REARLEFT-PASSENGER-SEAT===================================

void RearLeft_Seat () {

  if (SeatBelt_RL  == LOW && Ignition_Status == LOW && Door_Status == LOW && Seat_Occupant_RL == LOW) {

    Serial.println("NO ERROR RL1");//Serial Monitor output

    Serial.println("Airbag_DeActivated");//Serial Monitor output

    AirbagStatus_RL = LOW; //Airbag Status for Rear Left Passenger

    mcp2515.sendMessage(&canMsg3); //Declaration of CAN Message

 

  }

  else if (SeatBelt_RL  == HIGH && Ignition_Status == HIGH && Door_Status == HIGH && Seat_Occupant_RL == HIGH) {

    Serial.println("NO ERROR RL2");//Serial Monitor output

    Serial.println("Airbag_Activated");//Serial Monitor output

    AirbagStatus_RL = HIGH; //Airbag Status for Rear Left Passenger

    mcp2515.sendMessage(&canMsg3); //Declaration of CAN Message

 

  }

  else if (SeatBelt_RL == LOW && Ignition_Status == LOW && Door_Status == LOW && Seat_Occupant_RL == HIGH) {

    Serial.println("NO ERROR RL3");//Serial Monitor output

    Serial.println("Airbag_DeActivated");//Serial Monitor output

    AirbagStatus_RL = LOW; //Airbag Status for Rear Left Passenger

    mcp2515.sendMessage(&canMsg3); //Declaration of CAN Message

 

  }

  else if (SeatBelt_RL  == LOW && Ignition_Status == LOW && Door_Status == HIGH && Seat_Occupant_RL == LOW) {

    Serial.println("NO ERROR RL4");//Serial Monitor output

    Serial.println("Airbag_DeActivated");//Serial Monitor output

    AirbagStatus_RL = LOW; //Airbag Status for Rear Left Passenger

    mcp2515.sendMessage(&canMsg3); //Declaration of CAN Message

 

  }

  else if (SeatBelt_RL == LOW && Ignition_Status == HIGH && Door_Status == LOW && Seat_Occupant_RL == LOW) {

    Serial.println("Buckle Seatbelt RL5");//Serial Monitor output

    Serial.println("Airbag_DeActivated");//Serial Monitor output

    Audio_Feedback();//Audio Feedback function is called

    Visual_Feedback();//Visual Feedback function is called

    Beep_Function();Beep function is called

    AirbagStatus_RL = LOW; //Airbag Status for Rear Left Passenger

    mcp2515.sendMessage(&canMsg3); //Declaration of CAN Message

 

  }

  else if (SeatBelt_RL  == HIGH && Ignition_Status == LOW && Door_Status == LOW && Seat_Occupant_RL == LOW) {

    Serial.println("NO ERROR RL6");//Serial Monitor output

    Serial.println("Airbag_DeActivated");//Serial Monitor output

    AirbagStatus_RL = LOW; //Airbag Status for Rear Left Passenger

    mcp2515.sendMessage(&canMsg3); //Declaration of CAN Message

 

  }

  else if (SeatBelt_RL  == LOW && Ignition_Status == LOW && Door_Status == HIGH && Seat_Occupant_RL == HIGH) {

    Serial.println("Buckle Seatbelt RL7");//Serial Monitor output

    Serial.println("Airbag_DeActivated");//Serial Monitor output

    Audio_Feedback();//Audio Feedback function is called

    Visual_Feedback();//Visual Feedback function is called

    Beep_Function();Beep function is called

    AirbagStatus_RL = LOW; //Airbag Status for Rear Left Passenger

    mcp2515.sendMessage(&canMsg3); //Declaration of CAN Message

 

  }

  else if (SeatBelt_RL == LOW && Ignition_Status == HIGH && Door_Status == HIGH && Seat_Occupant_RL == LOW) {

    Serial.println("NO ERROR RL8");//Serial Monitor output

    Serial.println("Airbag_DeActivated");//Serial Monitor output

    AirbagStatus_RL = LOW; //Airbag Status for Rear Left Passenger

    mcp2515.sendMessage(&canMsg3); //Declaration of CAN Message

 

  }

  else if (SeatBelt_RL  == HIGH && Ignition_Status == HIGH && Door_Status == LOW && Seat_Occupant_RL == LOW) {

    Serial.println("Buckle Seatbelt 9");//Serial Monitor output

    Serial.println("Airbag_DeActivated");//Serial Monitor output

    Audio_Feedback();//Audio Feedback function is called

    Visual_Feedback();//Visual Feedback function is called

    Beep_Function();Beep function is called

    AirbagStatus_RL = LOW; //Airbag Status for Rear Left Passenger

    mcp2515.sendMessage(&canMsg3); //Declaration of CAN Message

 

  }

  else if (SeatBelt_RL == HIGH && Ignition_Status == LOW && Door_Status == HIGH && Seat_Occupant_RL == LOW) {

    Serial.println("NO ERROR RL10");//Serial Monitor output

    Serial.println("Airbag_DeActivated");//Serial Monitor output

    AirbagStatus_RL = LOW; //Airbag Status for Rear Left Passenger

    mcp2515.sendMessage(&canMsg3); //Declaration of CAN Message

 

  }

  else if (SeatBelt_RL  == LOW && Ignition_Status == HIGH && Door_Status == LOW && Seat_Occupant_RL == HIGH) {

    Serial.println("NO ERROR RL11");//Serial Monitor output

    Serial.println("Airbag_DeActivated");//Serial Monitor output

    AirbagStatus_RL = LOW; //Airbag Status for Rear Left Passenger

    mcp2515.sendMessage(&canMsg3); //Declaration of CAN Message

 

  }

  else if (SeatBelt_RL == HIGH && Ignition_Status == LOW && Door_Status == LOW && Seat_Occupant_RL == HIGH) {

    Serial.println("NO ERROR RL12");//Serial Monitor output

    Serial.println("Airbag_Activated");//Serial Monitor output

    AirbagStatus_RL = HIGH; //Airbag Status for Rear Left Passenger

    mcp2515.sendMessage(&canMsg3); //Declaration of CAN Message

 

  }

  else if (SeatBelt_RL  == HIGH && Ignition_Status == HIGH && Door_Status == HIGH && Seat_Occupant_RL == LOW) {

    Serial.println("NO ERROR RL13");//Serial Monitor output

    Serial.println("Airbag_DeActivated");//Serial Monitor output

    AirbagStatus_RL = LOW; //Airbag Status for Rear Left Passenger

    mcp2515.sendMessage(&canMsg3); //Declaration of CAN Message

 

  }

  else if (SeatBelt_RL  == HIGH && Ignition_Status == HIGH && Door_Status == LOW && Seat_Occupant_RL == HIGH) {

    Serial.println("NO ERROR RL14");//Serial Monitor output

    Serial.println("Airbag_Activated");//Serial Monitor output

    AirbagStatus_RL = HIGH; //Airbag Status for Rear Left Passenger

    mcp2515.sendMessage(&canMsg3); //Declaration of CAN Message

 

  }

  else if (SeatBelt_RL == HIGH && Ignition_Status == LOW && Door_Status == HIGH && Seat_Occupant_RL == HIGH) {

    Serial.println("NO ERROR RL15");//Serial Monitor output

    Serial.println("Airbag_Activated");//Serial Monitor output

    AirbagStatus_RL = HIGH; //Airbag Status for Rear Left Passenger

    mcp2515.sendMessage(&canMsg3); //Declaration of CAN Message

 

  }

  else if (SeatBelt_RL  == LOW && Ignition_Status == HIGH && Door_Status == HIGH && Seat_Occupant_RL == HIGH) {

    Serial.println("Buckle Seatbelt RL16");//Serial Monitor output

    Serial.println("Airbag_DeActivated");//Serial Monitor output

    Audio_Feedback();//Audio Feedback function is called

    Visual_Feedback();//Visual Feedback function is called

    Beep_Function();Beep function is called

    AirbagStatus_RL = LOW; //Airbag Status for Rear Left Passenger

    mcp2515.sendMessage(&canMsg3); //Declaration of CAN Message

 

  }

  Serial.println();

}

 

//======REARRIGHT-PASSENGER-SEAT===============================

void RearRight_Seat() {

  if (SeatBelt_RR  == LOW && Ignition_Status == LOW && Door_Status == LOW && Seat_Occupant_RR == LOW) {

    Serial.println("NO ERROR RR1");//Serial Monitor output

    Serial.println("Airbag_DeActivated");//Serial Monitor output

    AirbagStatus_RR = LOW; //Airbag Status for Rear Right Passenger

    mcp2515.sendMessage(&canMsg4); //Declaration of CAN Message

 

  }

  else if (SeatBelt_RR  == HIGH && Ignition_Status == HIGH && Door_Status == HIGH && Seat_Occupant_RR == HIGH) {

    Serial.println("NO ERROR RR2");//Serial Monitor output

    Serial.println("Airbag_Activated");//Serial Monitor output

    AirbagStatus_RR = HIGH; //Airbag Status for Rear Right Passenger

    mcp2515.sendMessage(&canMsg4); //Declaration of CAN Message

 

  }

  else if (SeatBelt_RR  == LOW && Ignition_Status == LOW && Door_Status == LOW && Seat_Occupant_DR == HIGH) {

    Serial.println("NO ERROR RR3");//Serial Monitor output

    Serial.println("Airbag_DeActivated");//Serial Monitor output

    AirbagStatus_RR = LOW; //Airbag Status for Rear Right Passenger

    mcp2515.sendMessage(&canMsg4); //Declaration of CAN Message

 

  }

  else if (SeatBelt_DR  == LOW && Ignition_Status == LOW && Door_Status == HIGH && Seat_Occupant_DR == LOW) {

    Serial.println("NO ERROR RR4");//Serial Monitor output

    Serial.println("Airbag_DeActivated");//Serial Monitor output

    AirbagStatus_RR = LOW; //Airbag Status for Rear Right Passenger

    mcp2515.sendMessage(&canMsg4); //Declaration of CAN Message

 

  }

  else if (SeatBelt_DR  == LOW && Ignition_Status == HIGH && Door_Status == LOW && Seat_Occupant_DR == LOW) {

    Serial.println("Buckle Seatbelt RR5");//Serial Monitor output

    Serial.println("Airbag_DeActivated");//Serial Monitor output

    Audio_Feedback();//Audio Feedback function is called

    Visual_Feedback();//Visual Feedback function is called

    Beep_Function();Beep function is called

    AirbagStatus_RR = LOW; //Airbag Status for Rear Right Passenger

    mcp2515.sendMessage(&canMsg4); //Declaration of CAN Message

 

  }

  else if (SeatBelt_DR  == HIGH && Ignition_Status == LOW && Door_Status == LOW && Seat_Occupant_DR == LOW) {

    Serial.println("NO ERROR RR6");//Serial Monitor output

    Serial.println("Airbag_DeActivated");//Serial Monitor output

    AirbagStatus_RR = LOW; //Airbag Status for Rear Right Passenger

    mcp2515.sendMessage(&canMsg4); //Declaration of CAN Message

 

  }

  else if (SeatBelt_DR  == LOW && Ignition_Status == LOW && Door_Status == HIGH && Seat_Occupant_DR == HIGH) {

    Serial.println("Buckle Seatbelt RR7");//Serial Monitor output

    Serial.println("Airbag_DeActivated");//Serial Monitor output

    Audio_Feedback();//Audio Feedback function is called

    Visual_Feedback();//Visual Feedback function is called

    Beep_Function();Beep function is called

    AirbagStatus_RR = LOW; //Airbag Status for Rear Right Passenger

    mcp2515.sendMessage(&canMsg4); //Declaration of CAN Message

 

  }

  else if (SeatBelt_DR  == LOW && Ignition_Status == HIGH && Door_Status == HIGH && Seat_Occupant_DR == LOW) {

    Serial.println("NO ERROR RR8");//Serial Monitor output

    Serial.println("Airbag_DeActivated");//Serial Monitor output

    AirbagStatus_RR = LOW; //Airbag Status for Rear Right Passenger

    mcp2515.sendMessage(&canMsg4); //Declaration of CAN Message

 

  }

  else if (SeatBelt_DR  == HIGH && Ignition_Status == HIGH && Door_Status == LOW && Seat_Occupant_DR == LOW) {

    Serial.println("Buckle Seatbelt 9");//Serial Monitor output

    Serial.println("Airbag_DeActivated");//Serial Monitor output

    Audio_Feedback();//Audio Feedback function is called

    Visual_Feedback();//Visual Feedback function is called

    Beep_Function();Beep function is called

    AirbagStatus_RR = LOW; //Airbag Status for Rear Right Passenger

    mcp2515.sendMessage(&canMsg4); //Declaration of CAN Message

 

  }

  else if (SeatBelt_DR  == HIGH && Ignition_Status == LOW && Door_Status == HIGH && Seat_Occupant_DR == LOW) {

    Serial.println("NO ERROR RR10");//Serial Monitor output

    Serial.println("Airbag_DeActivated");//Serial Monitor output

    AirbagStatus_RR = LOW; //Airbag Status for Rear Right Passenger

    mcp2515.sendMessage(&canMsg4); //Declaration of CAN Message

 

  }

  else if (SeatBelt_DR  == LOW && Ignition_Status == HIGH && Door_Status == LOW && Seat_Occupant_DR == HIGH) {

    Serial.println("NO ERROR RR11");//Serial Monitor output

    Serial.println("Airbag_DeActivated");//Serial Monitor output

    AirbagStatus_RR = LOW; //Airbag Status for Rear Right Passenger

    mcp2515.sendMessage(&canMsg4); //Declaration of CAN Message

 

  }

  else if (SeatBelt_DR  == HIGH && Ignition_Status == LOW && Door_Status == LOW && Seat_Occupant_DR == HIGH) {

    Serial.println("NO ERROR RR12");//Serial Monitor output

    Serial.println("Airbag_Activated");//Serial Monitor output

    AirbagStatus_RR = HIGH; //Airbag Status for Rear Right Passenger

    mcp2515.sendMessage(&canMsg4); //Declaration of CAN Message

 

  }

  else if (SeatBelt_DR  == HIGH && Ignition_Status == HIGH && Door_Status == HIGH && Seat_Occupant_DR == LOW) {

    Serial.println("NO ERROR RR13");//Serial Monitor output

    Serial.println("Airbag_DeActivated");//Serial Monitor output

    AirbagStatus_RR = LOW; //Airbag Status for Rear Right Passenger

    mcp2515.sendMessage(&canMsg4); //Declaration of CAN Message

 

  }

  else if (SeatBelt_DR  == HIGH && Ignition_Status == HIGH && Door_Status == LOW &&       Seat_Occupant_DR == HIGH) {

 

    Serial.println("NO ERROR RR14");//Serial Monitor output

    Serial.println("Airbag_Activated");//Serial Monitor output

    AirbagStatus_RR = HIGH; //Airbag Status for Rear Right Passenger

    mcp2515.sendMessage(&canMsg4); //Declaration of CAN Message

 

  }

  else if (SeatBelt_DR  == HIGH && Ignition_Status == LOW && Door_Status == HIGH && Seat_Occupant_DR == HIGH) {

    Serial.println("NO ERROR RR15");//Serial Monitor output

    Serial.println("Airbag_Activated");//Serial Monitor output

    AirbagStatus_RR = HIGH; //Airbag Status for Rear Right Passenger

    mcp2515.sendMessage(&canMsg4); //Declaration of CAN Message

 

  } else if (SeatBelt_DR  == LOW && Ignition_Status == HIGH && Door_Status == HIGH && Seat_Occupant_DR == HIGH) {

    Serial.println("Buckle Seatbelt RR16");//Serial Monitor output

    Serial.println("Airbag_DeActivated");//Serial Monitor output

    Audio_Feedback();//Audio Feedback function is called

    Visual_Feedback();//Visual Feedback function is called

    Beep_Function();Beep function is called

    AirbagStatus_RR = LOW; //Airbag Status for Rear Right Passenger

    mcp2515.sendMessage(&canMsg4); //Declaration of CAN Message

  }

  Serial.println();// printing empty line in Serial Monitor

}

//=============FEEDBACKS=====================================

void Audio_Feedback() { 

  Serial.println("BUCKLE YOUR RESPECTIVE SEATBELTS");//Serial Monitor output

}

void Visual_Feedback() {

  Serial.println("BUCKLE YOUR RESPECTIVE SEATBELTS");//Serial Monitor output

}

void Beep_Function(){

  Serial.println("BEEEEEEEP ON");//Serial Monitor output

}

//*******************************************************************************

CAN COMMUNIATION MATRIX

                     USING CANdB++

 

//CREATED BY : AKASH.K

// CREATED ON DATE :20,october2022.

//SOFTWARE :  VECTOR CANdB++

 

 INTRODUCTION :

                                           The Communication matrix or CAN Matrix is a table structure, essentially defining some of the basic informations about which ECU sends which message under which conditions and with which cycle time and which ECU receives the corresponding message or signal.

OVERVIEW :

                                  Here,in this DBC I have implemented Sixty signals which are converted into Eight functional messages.These are the some of the major requirements which are needed to develop a communication matrix which plays a vital role in the CAN communication.

                      In such case the above mentioned sixty signals are the required messages for transmitting and receiving that could be the inputs which are given to the ECU systems to do work  on a progress.

 

STRUCTURE OF CAN MATRIX