Sreedharan Shanmugamsundram

  Remote Keyless Entry - RKE 

September 30, 2022 

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


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

//Created by SREEDHARAN S 

//Created on date:

//Software – Arduino IDE 

//=================Program for Remote Keyless Entry=============

#include <SPI.h>          // communicates using SPI

#include <mcp2515.h> //CAN interface library 

struct can_frame canMsg;  //Message used to receive a CAN message

//Message used to transmit an CAN message

struct can_frame canMsg1;   //T-Key Fob Lock

struct can_frame canMsg2;   //T-Key Fob  UnLock

struct can_frame canMsg3;   //T- Key Fob  Search

struct can_frame canMsg4;   //T-Key Fob Trunk

struct can_frame canMsg5;   //T-For Auto Relock Function

struct can_frame canMsg6;   //T-Auto Lock Function

struct can_frame canMsg7;   //T-Auto Unlock Function

struct can_frame canMsg8;   //T-Panic Alarm Function

struct can_frame canMsg9;   //T-Center Lock Function

struct can_frame canMsg10;  //T-Theft Alarm Function

struct can_frame canMsg11;  //T-DoorStatus_DriverDoor

struct can_frame canMsg12;  //T-DoorStatus_FrontPassenger

struct can_frame canMsg13;  //T-DoorStatus_RearRight

struct can_frame canMsg14;  //T-DoorStatus_RearLeft

struct can_frame canMsg15;  //Transmission-cylinder  OFF

struct can_frame canMsg16;  //T- cylinder  Acc

struct can_frame canMsg17;  //T- cylinder  ON 

struct can_frame canMsg18;  //T- cylinder  Crank 

struct can_frame canMsg19;  //T-Emergency unlocking Function 

struct can_frame canMsg20;  //T-Special Circumstances 

 struct can_frame canMsg21;  //T-Mute Function 

struct can_frame canMsg22;  //T-Beep Function 

struct can_frame canMsg23;  //T-Airbag Function

struct can_frame canMsg24;  //T-Hazard_Function1

struct can_frame canMsg25;  // T-Hazard_Function2

struct can_frame canMsg26;  // T-Hazard_Function 3

struct can_frame canMsg27;  // T-Hazard_Function4

MCP2515 mcp2515(10);      //Setting to Arduino UNO 

//Declaration of ID for CAN communication         

int id_110_value[0];  //canMsg_id_1

//Initializing the variable for remote keyless entry Button 

bool keyfob;

bool k_lock;     //Keyfob lock 

bool k_unlock; //Keyfob Unlock 

bool k_trunk;   //Keyfob Trunk 

//Initializing the variable for Cylinder Status  

bool CylinderStatus;

bool CylinderStatus_OFF;

bool CylinderStatus_Acc;

bool CylinderStatus_ON;

bool CylinderStatus_Crank;

//Initializing the variable for the Door Switch 

//Door switch status 

bool Driver_door;

bool FrontLest_door;

bool RearRight_Door;

bool RearLeft_Door;

bool trunk_door;

//Initializing the variable for the Solenoid Valves 

//solenoid valve status 

bool Driver_sv;

bool FrontPassenger_sv;

bool RearRight_sv;

bool RearLeft_sv;

bool Trunk_sv;

// initializing the variable for the Airbag Status

bool Airbag_Status;

// initializing the variable for the Hazard Status

bool Feedback;

// initializing the variable for the Beep Status

bool Beep;

//variable declaration of Ledpin 

int ledPin = 13;

//Declaration of initialize stages 

bool Door_Switch_Statu=LOWs;  // 1 = HIGH

bool Door_Valve_Status=HIGH;   //1 = HIGH

//For timer

int k_unlock_timer = 3;  //3sec

// Initializing the variable for the Vehicle speed status

int VehicleSpeed;

//For loop

int i;

byte byte_data[8];         //to read the byte data

//========================  Setup  ================================ 

void setup() {

  Serial.begin(9600); //To initialize serial communication at 9600bps 

  mcp2515.reset();

  mcp2515.setBitrate(CAN_500KBPS, MCP_8MHZ); //setting bitrate for can protocol 

  mcp2515.setNormalMode(); //initialization of normal mode 

//declaration of CAN ID, CAN data length and CAN data 

  canMsg1.can_id = 0x300;  //Lock

  canMsg1.can_dlc = 1;

  canMsg1.data[0] = 0x09;

  canMsg2.can_id = 0x300;  //UnLock

  canMsg2.can_dlc = 1;

  canMsg2.data[0] = 0x10;

  canMsg3.can_id = 0x300;  //Search

  canMsg3.can_dlc = 1;

  canMsg3.data[0] = 0x15;

  canMsg4.can_id = 0x300;  //Trunk

  canMsg4.can_dlc = 1;

  canMsg4.data[0] = 0x12;

 canMsg5.can_id = 0x300;  //AutoReLock

  canMsg5.can_dlc = 1;

  canMsg5.data[0] = 0x14;

 canMsg6.can_id = 0x300;  //AutoLock

  canMsg6.can_dlc = 1;

  canMsg6.data[0] = 0x07;

 canMsg7.can_id = 0x300;  //AutoUnLock

  canMsg7.can_dlc = 1;

  canMsg7.data[0] = 0x03;

 canMsg8.can_id = 0x300;  //PanicAlarm

  canMsg8.can_dlc = 1;

  canMsg8.data[0] = 0x05;

  canMsg9.can_id = 0x300;  //CentralLock

  canMsg9.can_dlc = 1;

  canMsg9.data[0] = 0x06;

  canMsg10.can_id = 0x300;  //TheftAlarm

  canMsg10.can_dlc = 1;

  canMsg10.data[0] = 0x11;

  canMsg11.can_id = 0x300;  //Driver_Door

  canMsg11.can_dlc = 1;

  canMsg11.data[0] = 0x17;

  canMsg12.can_id = 0x300;  //Front_Left

  canMsg12.can_dlc = 1;

  canMsg12.data[0] = 0x18;

  canMsg13.can_id = 0x300;  //Rear_Right

  canMsg13.can_dlc = 1;

  canMsg13.data[0] = 0x19;

  canMsg14.can_id = 0x300;  //Rear_Left

  canMsg14.can_dlc = 1;

  canMsg14.data[0] = 0x23;

  canMsg15.can_id = 0x300;  //Cylinder_OFF

  canMsg15.can_dlc = 1;

  canMsg15.data[0] = 0x01;

  canMsg16.can_id = 0x300;  //Cylinder_ACC

  canMsg16.can_dlc = 1;

  canMsg16.data[0] = 0x02;

 canMsg17.can_id = 0x300;  //Cylinder_ON

  canMsg17.can_dlc = 1;

  canMsg17.data[0] = 0x04;

  canMsg18.can_id = 0x300;  //Cylinder_CRANK

  canMsg18.can_dlc = 1;

  canMsg18.data[0] = 0x08;

  canMsg19.can_id = 0x300;  //Emergency_Unlocking

  canMsg19.can_dlc = 1;

  canMsg19.data[0] = 0x20;

  canMsg20.can_id = 0x300;  //Special_Circumstances

  canMsg20.can_dlc = 1;

  canMsg20.data[0] = 0x13;

  canMsg21.can_id = 0x300;  //Mute_Function

  canMsg21.can_dlc = 1;

  canMsg21.data[0] = 0x21;

  canMsg22.can_id = 0x300;  //Beep_Function

  canMsg22.can_dlc = 1;

  canMsg22.data[0] = 0x22;

  canMsg23.can_id = 0x300;  //Airbag_Function

  canMsg23.can_dlc = 1;

  canMsg23.data[0] = 0x16;

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

  canMsg24.can_dlc = 1;

  canMsg24.data[0] = 0x24;

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

  canMsg25.can_dlc = 1;

  canMsg25.data[0] = 0x25;

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

  canMsg26.can_dlc = 1;

  canMsg26.data[0] = 0x26;

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

  canMsg27.can_dlc = 1;

  canMsg27.data[0] = 0x27;

}

// =====================Main Loop ============================ 

void loop() {

//To read CAN message 

  if (mcp2515.readMessage(&canMsg) == MCP2515::ERROR_OK) {

    if (canMsg.can_id == 0x100) {

      Serial.println("MESSAGE ID:0x100");

      for (int i = 0; i < canMsg.can_dlc; i++) {  // print the data

        Serial.print(" ");

        byte_data[i] = canMsg.data[i]; //Assigning CAN ID to byte data

        Serial.println(byte_data[i]);

        Serial.println("================byte0=======================");

        Serial.println(byte_data[0], HEX);

        int bit_1 = byte_data[0] & 0b00000111; //using AND operator to clear the remaining bits

        Serial.println("output of  bit_1");

        Serial.println(bit_1);          //To print the bit_1

        Serial.println(bit_1,HEX); //To print the bit_1 in HEX format

 

        switch (bit_1) {

          case 1:

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

            Serial.println("CylinderStatus_OFF");

            AutoUnLock(); //calling Auto locking function  

            Serial.println();

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

            break;

          case 2:

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

            Serial.println("CylinderStatus_Acc");

            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");

            AutoLock();      //calling AutoLock function 

            Emergency_UnLock();  //calling Emergency_UnLock function 

            Serial.println();

            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.println();

            mcp2515.sendMessage(&canMsg18);

            break;

          case 5:

            (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.println();

            break;

          case 6:

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

            UnLock();         //Activates Unlock function 

            AutoRelock();   //Activates AutoRelock function 

            Search();           //Activates Search function 

            Serial.println();

            break;

          case 7:

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

            Trunk(); //Activates Trunk function 

            Serial.println("Trunk");

            Serial.println();

            break;

          default:

            Serial.println("Invalid");

            Serial.println();

            break;

        }

        Serial.println("-----------------------");

      }

    }

  }

}

//*=================Function to lock all the door ================== 

void Lock() {

  Driver_sv = HIGH;

  FrontPassenger_sv = HIGH;

  RearRight_sv = HIGH;

  RearLeft_sv = HIGH;

  Trunk_sv = HIGH;

 

  Door_Switch_Status = LOW;  // Door Closed Stage 

  Door_Valve_Status = HIGH;  // In Valve lock stage 

  Serial.println("1.All doors are locked successfully ");

  mcp2515.sendMessage(&canMsg1);

  Feedback_1_Function();

//Below functions are checked simultaneously 

  //TheftAlarm(); 

  //Emergency_UnLock(); 

  //Special_Circumstances (); 

}

//*===========Function to Unlock all the door ================== 

void UnLock() {

  Driver_sv = LOW;

  FrontPassenger_sv = LOW;

  RearRight_sv = LOW;

  RearLeft_sv = LOW;

  Feedback_2_Function();

  Serial.println("02 All doors are Unlocked successfully ");

  mcp2515.sendMessage(&canMsg2);

  Door_Switch_Status = LOW;  // In Door closed stage 

  Door_Valve_Status = LOW;   // Valve locked stage 

}

//*=====Function to Unlock the trunk door ================= 

void Trunk() {

  Trunk_sv = LOW;      //trunk door valve is low 

  Feedback_3_Function();          //Activates Feedback function

  Serial.println("03 Trunk unlock");

  mcp2515.sendMessage(&canMsg4);

  Beep_Function();

  Door_Switch_Status = LOW;  // In Unlock stage

  Door_Valve_Status = LOW;   // Switch in Low status

}

//*============Function to Search the vehicle =================== 

void Search() {

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

    Feedback_4_Function(); //Hazard functions activated for 30sec 

    Serial.println("04 Search function ON");

    mcp2515.sendMessage(&canMsg3);

    Mute_Function();      //Mute functions activated for 30sec 

  }

}

//*===========Function to AutoRelock the vehicle =============== 

void AutoRelock() {     //Vehicle get unlocked after 45 sec if no doors are opened 

  if (mills >= 45000)  //assume as 45 sec

         if (Driver_door == LOW && FrontLest_door == LOW && RearRight_Door == LOW && RearLeft_Door == LOW && trunk_door == LOW) {

      Door_Switch_Status = LOW;

      Door_Valve_Status = HIGH;

      Serial.println("05 AutoRelock");

      mcp2515.sendMessage(&canMsg5);

      return;

} else {//If any door are opened 

      Serial.println("5 No_AutoRelock");

      Door_Switch_Status = HIGH;

      Door_Valve_Status = LOW;

      Mute_Function(); //activates mute function

      Beep_Function(); //activates beep function

      mcp2515.sendMessage(&canMsg5);

      return;

    }

}

//*===========Function to AutoLock the vehicle ================== 

void AutoLock() {

  if (CylinderStatus == CylinderStatus_ON){

    if (VehicleSpeed >= 20){ //vehicle speed is more than 20kmph 

  Door_Valve_Status = HIGH;  //valve is high (Door is Locked) 

  mcp2515.sendMessage(&canMsg6);

  Serial.println("06 Autolock");

    }

  }

}

//*==========Function to AutoUnLock the vehicle ================= 

void AutoUnLock() {

  if (CylinderStatus == CylinderStatus_Acc) {

    if (VehicleSpeed == 0)

    Door_Valve_Status = LOW;  //valve in low condition(doors are closed) 

    mcp2515.sendMessage(&canMsg7);

    Serial.println(" 07 AutoUnlocking");

  }

}

//*=================Function to Panic Alarm the vehicle ============ 

void PanicAlarm() {

  if (CylinderStatus == CylinderStatus_Acc) {

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

    Serial.println("8 PanicAlarm Activated ");

    Feedback_4_Function(); //Feedback function activated

    mcp2515.sendMessage(&canMsg8);

  }

}

//*==============Function to CenterLock the vehicle ================= 

void CentralLock() {

  if (Door_Switch_Status == LOW) {     //All doors are closed 

    if (Driver_sv == HIGH)        //if driver door is locked 

      Door_Valve_Status = HIGH;  //All the valves become high 

    Serial.println("09 CenterLock");

    mcp2515.sendMessage(&canMsg9);

  }

  if (Door_Switch_Status == HIGH) {    //All doors are closed 

    if (Driver_sv == LOW) //if driver door is locked 

      Door_Valve_Status = LOW;  //All the valves become high 

    Serial.println("9 CenterLock is Activated ");

    mcp2515.sendMessage(&canMsg9); // CenterLock CAN message 

  }

}

//*=============Function to TheftAlarm the vehicle ================== 

void TheftAlarm() {

  if (k_lock == HIGH) {  //when keyfob is high 

//Anti-theft alarm activation while opening of any doors after vehicle armed 

    if (Driver_sv == LOW || FrontPassenger_sv == LOW || RearRight_sv == LOW || RearLeft_sv == LOW || Trunk_sv == LOW || Driver_door == HIGH || FrontLest_door == HIGH || RearRight_Door == HIGH || RearLeft_Door == HIGH || trunk_door == HIGH) {

      Feedback_4_Function(); //Feedback function activated

      Beep_Function();    //Beep function activated

      Mute_Function();    //Mute function activated

      Serial.println("10 TheftAlarm Activated ");

      mcp2515.sendMessage(&canMsg10);

      //Alarm activates

    }

  }

}

//========================Mute function======================== 

void Mute_Function() {

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

    Serial.println("13 Mute_Function");

    Beep = LOW;           //Beep and Alarm muted

    Feedback = LOW;

    mcp2515.sendMessage(&canMsg21);

  }

}

//========================Beep function======================== 

void Beep_Function() {

                        //If any door is opened beep activated

  if (Driver_door == HIGH || FrontLeft_door == HIGH || RearRight_Door == HIGH || RearLeft_Door == HIGH || trunk_door == HIGH) {

    Beep = HIGH;

    Serial.print("14 Beep ON");

    mcp2515.sendMessage(&canMsg22);

  }

 if(Door_Switch_Status == LOW;)

   // No Beep 

  Serial.print("14 NO Beep"); 

Beep = HIGH;

  mcp2515.sendMessage(&canMsg22); 

} 

//========================Feedback  function======================== 

void Feedback_1_Function() {

   while (millis() <= 30000) {

  digitalWrite(ledPin, HIGH); 

  delay (500); 

  digitalWrite(ledPin, LOW); 

  delay (500); 

  Serial.println("15 Hazard-1 Function");

  Serial.println("16 Alarm Honking-1");

  mcp2515.sendMessage(&canMsg24);

}

}

//========================Feedback  function======================== 

void Feedback_2_Function() {

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

    digitalWrite(ledPin, HIGH);

    delay(500);

    digitalWrite(ledPin, LOW);

    delay(500);

    Serial.println("15 Hazard-2 Function");

    Serial.println("16 Alarm Honking-2");

    mcp2515.sendMessage(&canMsg25);

  }

}

//========================Feedback  function======================== 

void Feedback_3_Function() {

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

    digitalWrite(ledPin, HIGH);

    delay(500);

    digitalWrite(ledPin, LOW);

    delay(500);

    Serial.println("15 Hazard-3 Function");

    Serial.println("16 Alarm Honking-3");

    mcp2515.sendMessage(&canMsg26);

  }

}

//========================Feedback  function======================== 

void Feedback_4_Function() {

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

    digitalWrite(ledPin, HIGH);

    delay(500);

    digitalWrite(ledPin, LOW);

    delay(500);

    Serial.println("15 Hazard-4 Function");

    Serial.println("16 Alarm Honking-4");

    mcp2515.sendMessage(&canMsg27);

  }

}

//=================Emergency Unlocking function=============== 

void Emergency_UnLock() {

  if (Airbag_Status == HIGH) { //checking the Airbag status

    Door_Valve_Status = LOW;

  } else {

    Door_Valve_Status = HIGH;

  }

  Serial.println("11 Emergency_Unlocking");

  Feedback_4_Function(); //Feedback function activated

  Mute_Function();       //Mute function activated

  mcp2515.sendMessage(&canMsg19);

}

//======================Special Circumstances======================  

/=== if any doors opened with RKE locked hazard lamp flash for five times with alarm====

void Special_Circumstances() {

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

    if (Driver_door == HIGH || FrontLest_door == HIGH || RearRight_Door == HIGH || RearLeft_Door == HIGH || trunk_door == HIGH) {

      Beep_Function();    //Beep function activated

      Feedback_3_Function(); //Feedback function activated

      Serial.println("12 SpecialCircumstances");

      mcp2515.sendMessage(&canMsg20);

      Mute_Function();

    }

//===Condition to lock the door if driver door closed but any other door opened ======= 

    if (Driver_door == LOW) {

      Driver_sv = HIGH;

    }

    if (FrontLest_door == LOW) {

      FrontPassenger_sv = HIGH;

    }

    if (RearRight_Door == LOW) {

      RearRight_sv = HIGH;

    }

    if (RearLeft_Door == LOW) {

      RearLeft_sv = HIGH;

    }

    if (trunk_door == LOW) {

      Trunk_sv = HIGH;

    }

  }

}

//==============================End========================= 

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

SEAT BELT REMINDER (SBR)

October 15, 2022 

    We at CruizByte Mobility Solution (www.cruizbyte.co.in) implemented SBR logic based on SBR requirements from https://cruizbyte.co.in/training-blog/f/seat-belt-warning---an-overview-and-its-ncap-requirements.  

The source for the project is given below. 

 

//Created by SREEDHARAN S 

//Created on date:

//Software – Arduino IDE 

 

//==========Program for Seatbelt Reminder========================

#include <SPI.h>          // communicates using SPI, so include the library

#include <mcp2515.h> //CAN interface library 

struct can_frame canMsg;   //Message used to receive a CAN message

 

//Message used to transmit an CAN message

struct can_frame canMsg1;  //T-DriverSeat

struct can_frame canMsg2;  //T-FrontPassenger_Seat

struct can_frame canMsg3;  //T-RearLeft_Seat

struct can_frame canMsg4;  //T-RearRight_Seat

            //Setting to Arduino UNO 

MCP2515 mcp2515(10);

//Declaration of ID for CAN communication         

int id_100_value[0];

//Initializing the variable for Seatbelt Reminder 

//SeatBelt_Status

bool DR_SeatBelt;        //Driver SeatBelt         

bool FL_SeatBelt;        //FrontPassenger_SeatBelt

bool RL_SeatBelt;        //RearLeft_SeatBelt

bool RR_SeatBelt;        //RearRight_SeatBelt

//Initializing the variable for Cylinder Status  

bool Ignition_Status;

 

//Initializing the variable for the Door Switch 

bool Door_Status;

//Initializing the variable for SeatOccupant 

bool DR_SeatOccupant;

bool FL_SeatOccupant;

bool RL_SeatOccupant;

bool RR_SeatOccupant;

//Initializing the variable for Airbag Status

bool Dr_Airbag;

bool FL_Airbag;

bool RL_Airbag;

bool RR_Airbag;

//Initializing the variable for vehicle speed

int Vehicle_Speed;

//Feedback

bool Audio_Status;

int Visual_Status;

bool Warning_Lamp;  

bool Buzzer_Status; 

 

byte byte_data[0];   //To read the byte

//========================  Setup  ================================ 

void setup() {

  Serial.begin(9600);     //To initialize serial communication at 9600bps 

  mcp2515.reset();

  mcp2515.setBitrate(CAN_500KBPS, MCP_8MHZ);    //setting bitrate for can protocol 

  mcp2515.setNormalMode();    //initialization of normal mode 

//declaration of CAN ID, CAN data length and CAN data 

  canMsg1.can_id = 0x200;  //Driver_Seat

  canMsg1.can_dlc = 1;

  canMsg1.data[0] = 0x1;

  canMsg2.can_id = 0x200;  //FrontPassenger_Seat

  canMsg2.can_dlc = 1;

  canMsg2.data[0] = 0x2;

  canMsg3.can_id = 0x200;  //RearLeft_Seat

  canMsg3.can_dlc = 1;

  canMsg3.data[0] = 0x3;

  canMsg4.can_id = 0x200;  //RearRight_Seat

  canMsg4.can_dlc = 1;

  canMsg4.data[0] = 0x4;

}

// =====================Main Loop ============================ 

void loop() {

//To read CAN message 

  if (mcp2515.readMessage(&canMsg) == MCP2515::ERROR_OK) {

    if (canMsg.can_id == 0x100) { //checking for CAN id 100

      Serial.println("MESSAGE ID:0x100");

      for (int i = 0; i < canMsg.can_dlc; i++) {  // print the data

        byte_data[i] = canMsg.data[i];       //Assigning CAN ID to byte data

 

        Serial.println(byte_data[i]);

        Serial.println("================byte0=======================");

        Serial.println(byte_data[0], HEX);

        int bit_1 = byte_data[0] & 0b00000011;     //using AND operator to clear the remaining bits

        Serial.println("output of bit_1");

        Serial.println(bit_1);          //To print the bit_1

        Serial.println(bit_1,HEX); //To print the bit_1 in HEX format

 

        switch (bit_1) {

          case 1:

            Driver_Seat();               //calling DriverSeat  function  

            break;

          case 2:

            FrontPassenger_Seat();  //calling FrontPassenger_Seat  function  

            break;

          case 3:

            RearRight_Seat();          //calling RearRight_Seat  function  

            break;

          case 4:

            RearLeft_Seat();            //calling RearLeft_Seat  function  

            break;

        }

      }

    }

  }

}

 

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

void Driver_Seat() {

  if (DR_SeatBelt == LOW && Ignition_Status == LOW && Door_Status == LOW && DR_SeatOccupant == LOW) {

    Serial.println("NO ERROR DR1");

    Serial.println("Airbag_DeActivated");           

    Dr_Airbag = LOW;   //assigning value of Driver Airbag to low

    mcp2515.sendMessage(&canMsg1);

  } else if (DR_SeatBelt == HIGH && Ignition_Status == HIGH && Door_Status == HIGH && DR_SeatOccupant == HIGH) {

    Serial.println("NO ERROR DR2");

    Serial.println("Airbag_Activated");   

    Dr_Airbag = HIGH;  //assigning value of Driver Airbag to high

    mcp2515.sendMessage(&canMsg1);

  } else if (DR_SeatBelt == LOW && Ignition_Status == LOW && Door_Status == LOW && DR_SeatOccupant == HIGH) {

    Serial.println("NO ERROR DR3");

    Serial.println("Airbag_DeActivated");

    Dr_Airbag = LOW;   //assigning value of Driver Airbag to low

    mcp2515.sendMessage(&canMsg1);

 

  } else if (DR_SeatBelt == LOW && Ignition_Status == LOW && Door_Status == HIGH && DR_SeatOccupant == LOW) {

    Serial.println("NO ERROR DR4");

    Serial.println("Airbag_DeActivated");

    Dr_Airbag = LOW;   //assigning value of Driver Airbag to low

    mcp2515.sendMessage(&canMsg1);

  } else if (DR_SeatBelt == LOW && Ignition_Status == HIGH && Door_Status == LOW && DR_SeatOccupant == LOW) {

    Serial.println("Buckle Seatbelt DR5");

    Serial.println("Airbag_DeActivated");

 

    Audio_Feedback();   //Audio function activated

    Visual_Feedback();   //Visual function Activated

    Beep_Function();      //Beep function Activated

    Dr_Airbag = LOW;   //assigning value of Driver Airbag to low

    mcp2515.sendMessage(&canMsg1);

 

  } else if (DR_SeatBelt == HIGH && Ignition_Status == LOW && Door_Status == LOW && DR_SeatOccupant == LOW) {

    Serial.println("NO ERROR DR6");

    Serial.println("Airbag_DeActivated");

    Dr_Airbag = LOW;   //assigning value of Driver Airbag to low

    mcp2515.sendMessage(&canMsg1);

 

  } else if (DR_SeatBelt == LOW && Ignition_Status == LOW && Door_Status == HIGH && DR_SeatOccupant == HIGH) {

    Serial.println("Buckle Seatbelt DR7");

    Serial.println("Airbag_DeActivated");

    Audio_Feedback();   //Audio function activated

    Visual_Feedback();   //Visual function Activated

    Beep_Function();      //Beep function Activated

    Dr_Airbag = LOW;   //assigning value of Driver Airbag to low

    mcp2515.sendMessage(&canMsg1);

 

  } else if (DR_SeatBelt == LOW && Ignition_Status == HIGH && Door_Status == HIGH && DR_SeatOccupant == LOW) {

    Serial.println("NO ERROR DR8");

    Serial.println("Airbag_DeActivated");

    Dr_Airbag = LOW;   //assigning value of Driver Airbag to low

    mcp2515.sendMessage(&canMsg1);

 

  } else if (DR_SeatBelt == HIGH && Ignition_Status == HIGH && Door_Status == LOW && DR_SeatOccupant == LOW) {

    Serial.println("Buckle Seatbelt 9");

    Serial.println("Airbag_DeActivated");

    Audio_Feedback();   //Audio function activated

    Visual_Feedback();   //Visual function Activated

    Beep_Function();      //Beep function Activated

    Dr_Airbag = LOW;   //assigning value of Driver Airbag to low

    mcp2515.sendMessage(&canMsg1);

 

  } else if (DR_SeatBelt == HIGH && Ignition_Status == LOW && Door_Status == HIGH && DR_SeatOccupant == LOW) {

    Serial.println("NO ERROR DR10");

    Serial.println("Airbag_DeActivated");

    Dr_Airbag = LOW;   //assigning value of Driver Airbag to low

    mcp2515.sendMessage(&canMsg1);

 

  } else if (DR_SeatBelt == LOW && Ignition_Status == HIGH && Door_Status == LOW && DR_SeatOccupant == HIGH) {

    Serial.println("NO ERROR DR11");

    Serial.println("Airbag_DeActivated");

    Dr_Airbag = LOW;   //assigning value of Driver Airbag to low

    mcp2515.sendMessage(&canMsg1);

 

  } else if (DR_SeatBelt == HIGH && Ignition_Status == LOW && Door_Status == LOW && DR_SeatOccupant == HIGH) {

    Serial.println("NO ERROR DR12");

    Serial.println("Airbag_Activated");

    Dr_Airbag = HIGH;  //assigning value of Driver Airbag to HIGH

    mcp2515.sendMessage(&canMsg1);

 

  } else if (DR_SeatBelt == HIGH && Ignition_Status == HIGH && Door_Status == HIGH && DR_SeatOccupant == LOW) {

    Serial.println("NO ERROR DR13");

    Serial.println("Airbag_DeActivated");

    Dr_Airbag = LOW;   //assigning value of Driver Airbag to low

    mcp2515.sendMessage(&canMsg1);

 

  } else if (DR_SeatBelt == HIGH && Ignition_Status == HIGH && Door_Status == LOW && DR_SeatOccupant == HIGH) {

    Serial.println("NO ERROR DR14");

    Serial.println("Airbag_Activated");

    Dr_Airbag = HIGH;  //assigning value of Driver Airbag to HIGH

    mcp2515.sendMessage(&canMsg1);

 

  } else if (DR_SeatBelt == HIGH && Ignition_Status == LOW && Door_Status == HIGH && DR_SeatOccupant == HIGH) {

    Serial.println("NO ERROR DR15");

    Serial.println("Airbag_Activated");

    Dr_Airbag = HIGH;  //assigning value of Driver Airbag to HIGH

    mcp2515.sendMessage(&canMsg1);

 

  } else if (DR_SeatBelt == LOW && Ignition_Status == HIGH && Door_Status == HIGH && DR_SeatOccupant == HIGH) {

    Serial.println("Buckle Seatbelt DR16");

    Serial.println("Airbag_DeActivated");

    Audio_Feedback();   //Audio function Activated

    Visual_Feedback();   //visual function Activated

    Beep_Function();      //Beep function Activated

    Dr_Airbag = LOW;   //assigning value of Driver Airbag to low

    mcp2515.sendMessage(&canMsg1);

  }

  Serial.println();

}

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

void FrontPassenger_Seat() {

  if (FL_SeatBelt == LOW && Ignition_Status == LOW && Door_Status == LOW && FL_SeatOccupant == LOW) {

    Serial.println("NO ERROR FL1");

    Serial.println("Airbag_DeActivated");

    FL_Airbag = LOW;   //assigning value of Front passenger  Airbag to low

    mcp2515.sendMessage(&canMsg2);

 

  } else if (FL_SeatBelt == HIGH && Ignition_Status == HIGH && Door_Status == HIGH && FL_SeatOccupant == HIGH) {

    Serial.println("NO ERROR FL2");

    Serial.println("Airbag_Activated");

    FL_Airbag = HIGH;  //assigning value of Front passenger  Airbag to high

    mcp2515.sendMessage(&canMsg2);

 

  } else if (FL_SeatBelt == LOW && Ignition_Status == LOW && Door_Status == LOW && FL_SeatOccupant == HIGH) {

    Serial.println("NO ERROR FL3");

    Serial.println("Airbag_DeActivated");

    FL_Airbag = LOW;   //assigning value of Front passenger  Airbag to low

    mcp2515.sendMessage(&canMsg2);

 

  } else if (FL_SeatBelt == LOW && Ignition_Status == LOW && Door_Status == HIGH && FL_SeatOccupant == LOW) {

    Serial.println("NO ERROR FL4");

    Serial.println("Airbag_DeActivated");

    FL_Airbag = LOW;   //assigning value of Front passenger  Airbag to low

    mcp2515.sendMessage(&canMsg2);

 

  } else if (FL_SeatBelt == LOW && Ignition_Status == HIGH && Door_Status == LOW && FL_SeatOccupant == LOW) {

    Serial.println("Buckle Seatbelt FL5");

    Serial.println("Airbag_DeActivated");

    Audio_Feedback();   //Audio function Activated

    Visual_Feedback();   //visual function Activated

    Beep_Function();      //Beep function Activated

    FL_Airbag = LOW;   //assigning value of Front passenger  Airbag to low

    mcp2515.sendMessage(&canMsg2);

 

  } else if (FL_SeatBelt == HIGH && Ignition_Status == LOW && Door_Status == LOW && FL_SeatOccupant == LOW) {

    Serial.println("NO ERROR FL6");

    Serial.println("Airbag_DeActivated");

    FL_Airbag = LOW;   //assigning value of Front passenger  Airbag to low

    mcp2515.sendMessage(&canMsg2);

 

  } else if (FL_SeatBelt == LOW && Ignition_Status == LOW && Door_Status == HIGH && FL_SeatOccupant == HIGH) {

    Serial.println("Buckle Seatbelt FL7");

    Serial.println("Airbag_Activated");

    Audio_Feedback();   //Audio Function Activated

    Visual_Feedback();   //Visual function Activated

    Beep_Function();      //Beep function Activated

    FL_Airbag = HIGH;  //assigning value of Front passenger  Airbag to low

    mcp2515.sendMessage(&canMsg2);

 

  } else if (FL_SeatBelt == LOW && Ignition_Status == HIGH && Door_Status == HIGH && FL_SeatOccupant == LOW) {

    Serial.println("NO ERROR FL8");

    Serial.println("Airbag_DeActivated");

    FL_Airbag = LOW;   //assigning value of Front passenger  Airbag to low

    mcp2515.sendMessage(&canMsg2);

 

  } else if (FL_SeatBelt == HIGH && Ignition_Status == HIGH && Door_Status == LOW && FL_SeatOccupant == LOW) {

    Serial.println("Buckle Seatbelt 9");

    Serial.println("Airbag_DeActivated");

    Audio_Feedback();   //Audio Function Activated

    Visual_Feedback();   //Visual function Activated

    Beep_Function();      //Beep function Activated

    FL_Airbag = LOW;   //assigning value of Front passenger  Airbag to low

    mcp2515.sendMessage(&canMsg2);

 

  } else if (FL_SeatBelt == HIGH && Ignition_Status == LOW && Door_Status == HIGH && FL_SeatOccupant == LOW) {

    Serial.println("NO ERROR FL10");

    Serial.println("Airbag_DeActivated");

    FL_Airbag = LOW;   //assigning value of Front passenger  Airbag to low

    mcp2515.sendMessage(&canMsg2);

 

  } else if (FL_SeatBelt == LOW && Ignition_Status == HIGH && Door_Status == LOW && FL_SeatOccupant == HIGH) {

    Serial.println("NO ERROR FL11");

    Serial.println("Airbag_DeActivated");

    FL_Airbag = LOW;   //assigning value of Front passenger Airbag to low

    mcp2515.sendMessage(&canMsg2);

 

  } else if (FL_SeatBelt == HIGH && Ignition_Status == LOW && Door_Status == LOW && FL_SeatOccupant == HIGH) {

    Serial.println("NO ERROR FL12");

    Serial.println("Airbag_Activated");

    FL_Airbag = HIGH;  //assigning value of Front passenger Airbag to high

    mcp2515.sendMessage(&canMsg2);

 

  } else if (FL_SeatBelt == HIGH && Ignition_Status == HIGH && Door_Status == HIGH && FL_SeatOccupant == LOW) {

    Serial.println("NO ERROR FL13");

    Serial.println("Airbag_DeActivated");

    FL_Airbag = LOW;   //assigning value of Front passenger Airbag to low

    mcp2515.sendMessage(&canMsg2);

 

  } else if (FL_SeatBelt == HIGH && Ignition_Status == HIGH && Door_Status == LOW && FL_SeatOccupant == HIGH) {

    Serial.println("NO ERROR FL14");

    Serial.println("Airbag_Activated");

    FL_Airbag = HIGH;  //assigning value of Front passenger Airbag to high

    mcp2515.sendMessage(&canMsg2);

 

  } else if (FL_SeatBelt == HIGH && Ignition_Status == LOW && Door_Status == HIGH && FL_SeatOccupant == HIGH) {

    Serial.println("NO ERROR FL15");

    Serial.println("Airbag_Activated");

    FL_Airbag = HIGH;  //assigning value of Front passenger Airbag to high

    mcp2515.sendMessage(&canMsg2);

 

  } else if (FL_SeatBelt == LOW && Ignition_Status == HIGH && Door_Status == HIGH && FL_SeatOccupant == HIGH) {

    Serial.println("Buckle Seatbelt FL16");

    Serial.println("Airbag_DeActivated");

    Audio_Feedback();   //Audio function Activated

    Visual_Feedback();   //visual function Activated

    Beep_Function();      //Beep function Activated

    FL_Airbag = LOW;   //assigning value of Front passenger Airbag to low

    mcp2515.sendMessage(&canMsg2);

  }

  Serial.println();

}

 

//==============REAR LEFT-PASSENGER-SEAT=========================

void RearLeft_Seat() {

  if (RL_SeatBelt == LOW && Ignition_Status == LOW && Door_Status == LOW && RL_SeatOccupant == LOW) {

    Serial.println("NO ERROR RL1");

    Serial.println("Airbag_DeActivated");

    RL_Airbag = LOW;  //assigning value of Front passenger Airbag to low

    mcp2515.sendMessage(&canMsg3);

 

  } else if (RL_SeatBelt == HIGH && Ignition_Status == HIGH && Door_Status == HIGH && RL_SeatOccupant == HIGH) {

    Serial.println("NO ERROR RL2");

    Serial.println("Airbag_Activated");

    RL_Airbag = HIGH; //assigning value of Front passenger Airbag to high

    mcp2515.sendMessage(&canMsg3);

 

  } else if (RL_SeatBelt == LOW && Ignition_Status == LOW && Door_Status == LOW && RL_SeatOccupant == HIGH) {

    Serial.println("NO ERROR RL3");

    Serial.println("Airbag_DeActivated");

    RL_Airbag = LOW;  //assigning value of Front passenger Airbag to low

    mcp2515.sendMessage(&canMsg3);

 

  } else if (RL_SeatBelt == LOW && Ignition_Status == LOW && Door_Status == HIGH && RL_SeatOccupant == LOW) {

    Serial.println("NO ERROR RL4");

    Serial.println("Airbag_DeActivated");

    RL_Airbag = LOW;  //assigning value of Front passenger Airbag to low

    mcp2515.sendMessage(&canMsg3);

 

  } else if (RL_SeatBelt == LOW && Ignition_Status == HIGH && Door_Status == LOW && RL_SeatOccupant == LOW) {

    Serial.println("Buckle Seatbelt RL5");

    Serial.println("Airbag_DeActivated");

    Audio_Feedback();   //Audio function Activated

    Visual_Feedback();   //visual function Activated

    Beep_Function();      //Beep function Activated

    RL_Airbag = LOW;  //assigning value of Front passenger Airbag to low

    mcp2515.sendMessage(&canMsg3);

 

  } else if (RL_SeatBelt == HIGH && Ignition_Status == LOW && Door_Status == LOW && RL_SeatOccupant == LOW) {

    Serial.println("NO ERROR RL6");

    Serial.println("Airbag_DeActivated");

    RL_Airbag = LOW;  //assigning value of Front passenger Airbag to low

    mcp2515.sendMessage(&canMsg3);

 

  } else if (RL_SeatBelt == LOW && Ignition_Status == LOW && Door_Status == HIGH && RL_SeatOccupant == HIGH) {

    Serial.println("Buckle Seatbelt RL7");

    Serial.println("Airbag_DeActivated");

    Audio_Feedback();   //Audio function Activated

    Visual_Feedback();   //visual function Activated

    Beep_Function();      //Beep function Activated

    RL_Airbag = LOW;  //assigning value of Front passenger Airbag to low

    mcp2515.sendMessage(&canMsg3);

 

  } else if (RL_SeatBelt == LOW && Ignition_Status == HIGH && Door_Status == HIGH && RL_SeatOccupant == LOW) {

    Serial.println("NO ERROR RL8");

    Serial.println("Airbag_DeActivated");

    RL_Airbag = LOW;  //assigning value of Front passenger Airbag to low

    mcp2515.sendMessage(&canMsg3);

 

  } else if (RL_SeatBelt == HIGH && Ignition_Status == HIGH && Door_Status == LOW && RL_SeatOccupant == LOW) {

    Serial.println("Buckle Seatbelt 9");

    Serial.println("Airbag_DeActivated");

    Audio_Feedback();   //Audio function Activated

    Visual_Feedback();   //visual function Activated

    Beep_Function();      //Beep function Activated

    RL_Airbag = LOW;  //assigning value of Front passenger Airbag to low

    mcp2515.sendMessage(&canMsg3);

 

  } else if (RL_SeatBelt == HIGH && Ignition_Status == LOW && Door_Status == HIGH && RL_SeatOccupant == LOW) {

    Serial.println("NO ERROR RL10");

    Serial.println("Airbag_DeActivated");

    RL_Airbag = LOW;  //assigning value of Front passenger Airbag to low

    mcp2515.sendMessage(&canMsg3);

 

  } else if (RL_SeatBelt == LOW && Ignition_Status == HIGH && Door_Status == LOW && RL_SeatOccupant == HIGH) {

    Serial.println("NO ERROR RL11");

    Serial.println("Airbag_DeActivated");

    RL_Airbag = LOW;  //assigning value of Front passenger Airbag to low

    mcp2515.sendMessage(&canMsg3);

 

  } else if (RL_SeatBelt == HIGH && Ignition_Status == LOW && Door_Status == LOW && RL_SeatOccupant == HIGH) {

    Serial.println("NO ERROR RL12");

    Serial.println("Airbag_Activated");

    RL_Airbag = HIGH; //assigning value of Front passenger Airbag to high

    mcp2515.sendMessage(&canMsg3);

 

  } else if (RL_SeatBelt == HIGH && Ignition_Status == HIGH && Door_Status == HIGH && RL_SeatOccupant == LOW) {

    Serial.println("NO ERROR RL13");

    Serial.println("Airbag_DeActivated");

    RL_Airbag = LOW;  //assigning value of Front passenger Airbag to low

    mcp2515.sendMessage(&canMsg3);

 

  } else if (RL_SeatBelt == HIGH && Ignition_Status == HIGH && Door_Status == LOW && RL_SeatOccupant == HIGH) {

    Serial.println("NO ERROR RL14");

    Serial.println("Airbag_Activated");

    RL_Airbag = HIGH; //assigning value of Front passenger Airbag to high

    mcp2515.sendMessage(&canMsg3);

 

  } else if (RL_SeatBelt == HIGH && Ignition_Status == LOW && Door_Status == HIGH && RL_SeatOccupant == HIGH) {

    Serial.println("NO ERROR RL15");

    Serial.println("Airbag_Activated");

    RL_Airbag = HIGH; //assigning value of Front passenger Airbag to high

    mcp2515.sendMessage(&canMsg3);

 

  } else if (RL_SeatBelt == LOW && Ignition_Status == HIGH && Door_Status == HIGH && RL_SeatOccupant == HIGH) {

    Serial.println("Buckle Seatbelt RL16");

    Serial.println("Airbag_DeActivated");

    Audio_Feedback();   //Audio function Activated

    Visual_Feedback();   //visual function Activated

    Beep_Function();      //Beep function Activated

    RL_Airbag = LOW;  //assigning value of Front passenger Airbag to low

    mcp2515.sendMessage(&canMsg3);

  }

  Serial.println();

}

 

//============REAR RIGHT-PASSENGER-SEAT======================

void RearRight_Seat() {

  if (RR_SeatBelt == LOW && Ignition_Status == LOW && Door_Status == LOW && RR_SeatOccupant == LOW) {

    Serial.println("NO ERROR RR1");

    Serial.println("Airbag_DeActivated");

    RR_Airbag = LOW;  //assigning value of Front passenger Airbag to low

    mcp2515.sendMessage(&canMsg4);

 

  } else if (RR_SeatBelt == HIGH && Ignition_Status == HIGH && Door_Status == HIGH && RR_SeatOccupant == HIGH) {

    Serial.println("NO ERROR RR2");

    Serial.println("Airbag_Activated");

    RR_Airbag = HIGH; //assigning value of Front passenger Airbag to high

    mcp2515.sendMessage(&canMsg4);

 

  } else if (RR_SeatBelt == LOW && Ignition_Status == LOW && Door_Status == LOW && DR_SeatOccupant == HIGH) {

    Serial.println("NO ERROR RR3");

    Serial.println("Airbag_DeActivated");

    RR_Airbag = LOW;  //assigning value of Front passenger Airbag to low

    mcp2515.sendMessage(&canMsg4);

 

  } else if (DR_SeatBelt == LOW && Ignition_Status == LOW && Door_Status == HIGH && DR_SeatOccupant == LOW) {

    Serial.println("NO ERROR RR4");

    Serial.println("Airbag_DeActivated");

    RR_Airbag = LOW;  //assigning value of Front passenger Airbag to low

    mcp2515.sendMessage(&canMsg4);

 

  } else if (DR_SeatBelt == LOW && Ignition_Status == HIGH && Door_Status == LOW && DR_SeatOccupant == LOW) {

    Serial.println("Buckle Seatbelt RR5");

    Serial.println("Airbag_DeActivated");

    Audio_Feedback();   //Audio function Activated

    Visual_Feedback();   //visual function Activated

    Beep_Function();      //Beep function Activated

    RR_Airbag = LOW;  //assigning value of Front passenger Airbag to low

    mcp2515.sendMessage(&canMsg4);

 

  } else if (DR_SeatBelt == HIGH && Ignition_Status == LOW && Door_Status == LOW && DR_SeatOccupant == LOW) {

    Serial.println("NO ERROR RR6");

    Serial.println("Airbag_DeActivated");

    RR_Airbag = LOW;  //assigning value of Front passenger Airbag to low

    mcp2515.sendMessage(&canMsg4);

 

  } else if (DR_SeatBelt == LOW && Ignition_Status == LOW && Door_Status == HIGH && DR_SeatOccupant == HIGH) {

    Serial.println("Buckle Seatbelt RR7");

    Serial.println("Airbag_DeActivated");

    Audio_Feedback();   //Audio function Activated

    Visual_Feedback();   //visual function Activated

    Beep_Function();      //Beep function Activated

    RR_Airbag = LOW;  //assigning value of Front passenger Airbag to low

    mcp2515.sendMessage(&canMsg4);

 

  } else if (DR_SeatBelt == LOW && Ignition_Status == HIGH && Door_Status == HIGH && DR_SeatOccupant == LOW) {

    Serial.println("NO ERROR RR8");

    Serial.println("Airbag_DeActivated");

    RR_Airbag = LOW;  //assigning value of Front passenger Airbag to low

    mcp2515.sendMessage(&canMsg4);

 

  } else if (DR_SeatBelt == HIGH && Ignition_Status == HIGH && Door_Status == LOW && DR_SeatOccupant == LOW) {

    Serial.println("Buckle Seatbelt 9");

    Serial.println("Airbag_DeActivated");

    Audio_Feedback();   //Audio function Activated

    Visual_Feedback();   //visual function Activated

    Beep_Function();      //Beep function Activated

    RR_Airbag = LOW;  //assigning value of Front passenger Airbag to low

    mcp2515.sendMessage(&canMsg4);

 

  } else if (DR_SeatBelt == HIGH && Ignition_Status == LOW && Door_Status == HIGH && DR_SeatOccupant == LOW) {

    Serial.println("NO ERROR RR10");

    Serial.println("Airbag_DeActivated");

    RR_Airbag = LOW;  //assigning value of Front passenger Airbag to low

    mcp2515.sendMessage(&canMsg4);

 

  } else if (DR_SeatBelt == LOW && Ignition_Status == HIGH && Door_Status == LOW && DR_SeatOccupant == HIGH) {

    Serial.println("NO ERROR RR11");

    Serial.println("Airbag_DeActivated");

    RR_Airbag = LOW;  //assigning value of Front passenger Airbag to low

    mcp2515.sendMessage(&canMsg4);

 

  } else if (DR_SeatBelt == HIGH && Ignition_Status == LOW && Door_Status == LOW && DR_SeatOccupant == HIGH) {

    Serial.println("NO ERROR RR12");

    Serial.println("Airbag_Activated");

    RR_Airbag = HIGH; //assigning value of Front passenger Airbag to high

    mcp2515.sendMessage(&canMsg4);

 

  } else if (DR_SeatBelt == HIGH && Ignition_Status == HIGH && Door_Status == HIGH && DR_SeatOccupant == LOW) {

    Serial.println("NO ERROR RR13");

    Serial.println("Airbag_DeActivated");

    RR_Airbag = LOW;  //assigning value of Front passenger Airbag to low

    mcp2515.sendMessage(&canMsg4);

 

  } else if (DR_SeatBelt == HIGH && Ignition_Status == HIGH && Door_Status == LOW && DR_SeatOccupant == HIGH) {

    Serial.println("NO ERROR RR14");

    Serial.println("Airbag_Activated");

    RR_Airbag = HIGH; //assigning value of Front passenger Airbag to high

    mcp2515.sendMessage(&canMsg4);

 

  } else if (DR_SeatBelt == HIGH && Ignition_Status == LOW && Door_Status == HIGH && DR_SeatOccupant == HIGH) {

    Serial.println("NO ERROR RR15");

    Serial.println("Airbag_Activated");

    RR_Airbag = HIGH; //assigning value of Front passenger Airbag to high

    mcp2515.sendMessage(&canMsg4);

 

  } else if (DR_SeatBelt == LOW && Ignition_Status == HIGH && Door_Status == HIGH && DR_SeatOccupant == HIGH) {

    Serial.println("Buckle Seatbelt RR16");

    Serial.println("Airbag_DeActivated");

    Audio_Feedback();   //Audio function Activated

    Visual_Feedback();   //visual function Activated

    Beep_Function();      //Beep function Activated

    RR_Airbag = LOW;  //assigning value of Front passenger Airbag to low

    mcp2515.sendMessage(&canMsg4);

  }

  Serial.println();

}

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

void Audio_Feedback() {

  Serial.println("SEAT BELT NOT BUCKLED");

}

void Visual_Feedback() {

  Serial.println("SEAT BELT NOT BUCKLED ");

}

void Beep_Function() {

Beep = HIGH;

  Serial.println("BEEEEEEEP ON");

}

//========================End===========================

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


INSTRUMENT CLUSTER

The requirements for IC implementation is taken form https://cruizbyte.co.in/training-blog/f/instrument-cluster-tell-tales-and-warning-lights

The warning light summary as given below



//=================Program for Instrument cluster================

 

#include <Arduino_FreeRTOS.h>         //included library to use FreeRTOS

#include <EasyNextionLibrary.h>         //included library to work with Nextion HMI

 

//define task handles for each task

TaskHandle_t TaskSerial_Handler1;      //Airbag

TaskHandle_t TaskSerial_Handler2;      //Power Brake

TaskHandle_t TaskSerial_Handler3;      //Check Engine

TaskHandle_t TaskSerial_Handler4;      //Battery

TaskHandle_t TaskSerial_Handler5;      //Fog lamp

TaskHandle_t TaskSerial_Handler6;      //Seatbelt

TaskHandle_t TaskSerial_Handler7;      //Power Steering

TaskHandle_t TaskSerial_Handler8;      //Tyre pressure

TaskHandle_t TaskSerial_Handler9;      //ABS

TaskHandle_t TaskSerial_Handler10;    //open door

TaskHandle_t TaskSerial_Handler11;    //ESP

TaskHandle_t TaskSerial_Handler12;    //Gauge

TaskHandle_t TaskSerial_Handler13;    //Left Indicator

TaskHandle_t TaskSerial_Handler14;    //Right Indicator

TaskHandle_t TaskSerial_Handler15;    //Hazard lamp

 

// defining  tasks

void Airbag(void *pvParameters);         //Airbag

void PowerBreak(void *pvParameters); //Power Brake

void CheckEngine(void *pvParameters); //Check Engine

void Battery(void *pvParameters);        //Battery

void FogLamp(void *pvParameters);     //Fog Lamp

void Seatbelt(void *pvParameters);       //Seatbelt

void PowerSteering(void *pvParameters);//Power Steering

void TyrePressure(void *pvParameters); //Tyre Pressure

void ABS(void *pvParameters);            //ABS

void OpenDoor(void *pvParameters);    //open door

void ESP(void *pvParameters);             //ESP

void Gauge(void *pvParameters);          //Gauge

void LeftIndicator(void *pvParameters); // Left Indicator

void RightIndicator(void *pvParameters);//Right Indicator

void Hazard(void *pvParameters);         //Hazard lamp

 

 

EasyNex myNex(Serial);          //Created an object of EasyNex class with the name myNEx

                                                //Set as parameter the Hardware serial which going to use

//declaring the initialize status of each lamp

bool Airbag_Status = LOW;                  //Airbag status

bool PowerBreak_Status = LOW;          //Power brake status

bool CheckEngine_Status = LOW;        //Check Engine Status

bool Battery_Status = LOW;                 //Battery Status

bool FogLamp_Status = LOW;              //Fog Lamp Status

bool Seatbelt_Status = LOW;                //Seatbelt Status

bool PowerSteering_Status = LOW;       //Power Steering Status

bool TyrePressure_Status = LOW;         //Tyre Pressure Status

bool ABS_Status = LOW;                     //ABS Status

bool OpenDoor_Status = LOW;             //Open-door Status

bool ESP_Status = LOW;                      //ESP Status

bool LeftIndicator_Status = LOW;         //Left Indicator Status

bool RightIndicator_Status = LOW;       //Right Indicator Status

bool Hazard_Status = LOW;                  //Hazard Status

//======================== Setup ============================= 

void setup() {

  myNex.begin(9600);   //To initialize serial communication at 9600bps 

  while (!Serial) { //if not serial

    ; // wait for serial port to connect.

  }

  // Now set up tasks to run independently including stack size, parameter passed, Priority &Handler   

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

  xTaskCreate(PowerBreak, "2", 128, NULL, 2, &TaskSerial_Handler2); //for Power brake

  xTaskCreate(CheckEngine, "3", 128, NULL, 3, &TaskSerial_Handler3);//for Check engine

  xTaskCreate(Battery, "4", 128, NULL, 1, &TaskSerial_Handler4);        //for Battery

  xTaskCreate(FogLamp, "5", 128, NULL, 2, &TaskSerial_Handler5);    //for Fog Lamp

  xTaskCreate(Seatbelt, "6", 128, NULL, 3, &TaskSerial_Handler6);       //for Seatbelt

  xTaskCreate(PowerSteering, "7", 128, NULL, 1, &TaskSerial_Handler7);//for Power Steering

  xTaskCreate(TyrePressure, "8", 128, NULL, 1, &TaskSerial_Handler8);//for Tyre pressure

  xTaskCreate(ABS, "9", 128, NULL, 1, &TaskSerial_Handler9);           //for ABS

  xTaskCreate(OpenDoor, "10", 128, NULL, 1, &TaskSerial_Handler10);//for open door

  xTaskCreate(ESP, "11", 128, NULL, 1, &TaskSerial_Handler11);        //for ESP

  xTaskCreate(Gauge, "12", 128, NULL, 1, &TaskSerial_Handler12);     //for Gauge

  xTaskCreate(LeftIndicator, "12", 128, NULL, 2, &TaskSerial_Handler13); //for Left indicator

  xTaskCreate(RightIndicator, "13", 128, NULL, 3, &TaskSerial_Handler14); //for Right indicator4

  xTaskCreate(Hazard, "14", 128, NULL, 3, &TaskSerial_Handler15);      //for hazard

}

// =====================Main Loop ============================ 

void loop() {

  // Empty. Things are done in Tasks.

}

// =====================Airbag ============================ 

void Airbag(void *pvParameters) {

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

  {

    if (Airbag_Status == HIGH) {            //checking whether Airbag status is high

      myNex.writeStr("vis p1,0");            //changing the picture visibility to 0(hide)

      myNex.writeStr("t0.pco=2024");      //changing the text ‘t0’ colour to Green      

      myNex.writeStr("t0.txt", "AIRBAG ACTIVATED"); //changing the text ‘t0’-AirbagActivated

    } else if (Airbag_Status == LOW) {   //checking whether Airbag status is low

      myNex.writeStr("vis p1,1");             //changing the picture visibility to 1(show)

      myNex.writeStr("t0.pco=63496");    //changing the text ‘t0’ colour to red

//changing the text ‘t0’-AirbagActivated

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

      vTaskDelay(1000 / portTICK_PERIOD_MS);          //using delay of 1sec

      myNex.writeStr("vis p1,1");             //changing the picture visibility to 1(show)

      myNex.writeStr("t0.pco=63496");     //changing the text ‘t0’ colour to red

                        //changing the text ‘t0’-AirbagActivated

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

      vTaskDelay(1000 / portTICK_PERIOD_MS);          //using delay of 1sec

    }

    Serial.write(0xff);     //end of command

    Serial.write(0xff);

    Serial.write(0xff);

  }

}

// ===================== Power Brake ========================== 

void PowerBrake(void *pvParameters) {

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

  {

    if (PowerBreak_Status == HIGH) {    //checking whether Power Break status is high

      myNex.writeStr("vis p2,1");             //changing the picture visibility to 1(show)

    } else {

      myNex.writeStr("vis p2,0");             //changing the picture visibility to 0(hide)

    }

    Serial.write(0xff);                             //end of command

    Serial.write(0xff);

    Serial.write(0xff);

  }

}

// =================== Check Engine ============================ 

  void CheckEngine(void *pvParameters) {

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

  {

    if (CheckEngine_Status == HIGH) {  //checking whether Check Engine status is high

      myNex.writeStr("vis p3,1");             //changing the picture visibility to 1(show)

    } else {

      myNex.writeStr("vis p3,0");             //changing the picture visibility to 0(hide)

    }

    Serial.write(0xff);                             //end of command

    Serial.write(0xff);

    Serial.write(0xff);

  }

  }

// ===================== Battery ============================ 

  void Battery(void *pvParameters) {

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

  {

    if (Battery_Status == HIGH) {           //checking whether Battery status is high

      myNex.writeStr("vis p4,1");             //changing the picture visibility to 1(show)

    } else {

      myNex.writeStr("vis p4,0");             //changing the picture visibility to 0(hide)

    }

    Serial.write(0xff);                             //end of command

    Serial.write(0xff);

    Serial.write(0xff);

  }

  }

// ===================== Fog Lamp ====================

  void FogLamp(void *pvParameters) {

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

  {

    if (FogLamp_Status == HIGH) {        //checking whether Fog Lamp status is high

      myNex.writeStr("vis p5,1");             //changing the picture visibility to 1(show)

    } else {

      myNex.writeStr("vis p5,0");             //changing the picture visibility to 0(hide)

    }

    Serial.write(0xff);                             //end of command

    Serial.write(0xff);

    Serial.write(0xff);

  }

  }

// ===================== Seatbelt ================== 

  void Seatbelt(void *pvParameters) {

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

  {

    if (Seatbelt_Status == HIGH) {          //checking whether Seatbelt status is high

      myNex.writeStr("vis p6,0");             //changing the picture visibility to 1(show)

      myNex.writeStr("t1.pco=2024");      //changing the text ‘t0’ colour to Green

                        //changing the text ‘t0’-Seatbelt Buckled

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

    } else if (Seatbelt_Status == LOW) {

      myNex.writeStr("vis p6,1");            //changing the picture visibility to 1(show)

      myNex.writeStr("t1.pco=63496");    //changing the text ‘t0’ colour to red

                        //changing the text ‘t0’- Seatbelt Not Buckled    

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

      vTaskDelay(1000 / portTICK_PERIOD_MS);          //using delay of 1sec

      myNex.writeStr("vis p6,0");            //changing the picture visibility to 0(hide)

      myNex.writeStr("t1.pco=63496");    //changing the text ‘t0’ colour to red

                        //changing the text ‘t0’- Seatbelt Not Buckled

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

      vTaskDelay(1000 / portTICK_PERIOD_MS);          //using delay of 1sec

    }

    Serial.write(0xff);     //end of command

    Serial.write(0xff);

    Serial.write(0xff);

  }

  }

// ===================== Power Steering ===============

  void PowerSteering((void *pvParameters) {

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

  {

    if (PowerSteering_Status == HIGH) { //checking whether Power Steering status is high

      myNex.writeStr("vis p7,1");            //changing the picture visibility to 1(show)

    } else {

      myNex.writeStr("vis p7,0");            //changing the picture visibility to 0(hide)

    }

    Serial.write(0xff);                             //end of command

    Serial.write(0xff);

    Serial.write(0xff);

  }

  }

// ==================== Tyre Pressure =========

  void TyrePressure(void *pvParameters) {

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

  {

    if (TyrePressure_Status == HIGH) {  //checking whether Tyre Pressure status is high

      myNex.writeStr("vis p8,1");            //changing the picture visibility to 1(show)

    } else {

      myNex.writeStr("vis p8,0");            //changing the picture visibility to 0(hide)

    }

    Serial.write(0xff);                             //end of command

    Serial.write(0xff);

    Serial.write(0xff);

  }

  }

// =====================ABS =================

  void ABS(void *pvParameters) {

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

  {

    if (ABS_Status == HIGH) {               //checking whether ABS status is high

      myNex.writeStr("vis p9,1");            //changing the picture visibility to 1(show)

    } else {

      myNex.writeStr("vis p9,0");            //changing the picture visibility to 0(hide)

    }

    Serial.write(0xff);                             //end of command

    Serial.write(0xff);

    Serial.write(0xff);

  }

  }

// ===================== Open-door ============

void OpenDoor(void *pvParameters) {

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

  {

    if (OpenDoor_Status == HIGH) {      //checking whether Open-door status is high

      myNex.writeStr("vis p10,1");          //changing the picture visibility to 1(show)

    } else {

      myNex.writeStr("vis p10,0");          //changing the picture visibility to 0(hide)

    }

    Serial.write(0xff);                             //end of command

    Serial.write(0xff);

    Serial.write(0xff);

  }

  }

// =====================ESP ==================

  void ESP(void *pvParameters) {

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

  {

    if (ESP_Status == HIGH) {                //checking whether ESP status is high

      myNex.writeStr("vis p11,1");          //changing the picture visibility to 1(show)

    } else {

      myNex.writeStr("vis p11,0");          //changing the picture visibility to 0(hide)

    }

    Serial.write(0xff);                             //end of command

    Serial.write(0xff);

    Serial.write(0xff);

  }

  }

// ================= Gauge =====================

void Gauge(void *pvParameters) {

int number;

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

  {

     number++;

     if(number == 250){

     number = 0;

}

   Serial.print(“z0.val=”);

   Serial.print(number);

   vTaskDelay(10/ portTICK_PERIOD_MS);       //using delay of 10ms

   Serial.write(0xff);                                          //end of command

    Serial.write(0xff);

    Serial.write(0xff);

}

// ================= Left Indicator ===================

 void LeftIndicator(void *pvParameters) {

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

  {

    if (LeftIndicator_Status == HIGH) {  //checking whether Left Indicator status is high

      myNex.writeStr("vis p12,1");          //changing the picture visibility to 1(show)

      vTaskDelay(800 / portTICK_PERIOD_MS);   //using delay of 800ms

      myNex.writeStr("vis p12,0");          //changing the picture visibility to 0(hide)

      vTaskDelay(800 / portTICK_PERIOD_MS);   //using delay of 800ms

    } else if (LeftIndicator_Status == LOW) {      //checking whether Left Indicator status is low

      myNex.writeStr("vis p12,0");          //changing the picture visibility to 0(hide)

    }

    Serial.write(0xff);                             //end of command

    Serial.write(0xff);

    Serial.write(0xff);

  }

  }

// =================== Right Indicator ==================

  void RightIndicator(void *pvParameters) {

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

  {

    if (RightIndicator_Status == HIGH) { //checking whether Right Indicator  status is high

      myNex.writeStr("vis p13,1");          //changing the picture visibility to 1(show)

      vTaskDelay(800 / portTICK_PERIOD_MS); //using delay of 800ms

      myNex.writeStr("vis p13,0");          //changing the picture visibility to 0(hide)

      vTaskDelay(800 / portTICK_PERIOD_MS); //using delay of 800ms

    } else if (RightIndicator_Status == LOW) {    //checking whether Right Indicator status is low

      //Right_Indicator = HIGH;

      myNex.writeStr("vis p13,0");                      //changing the picture visibility to 0(hide)

    }

    Serial.write(0xff);                                         //end of command

    Serial.write(0xff);

    Serial.write(0xff);

  }

  }

// ===================== Hazard =================

  void Hazard(void *pvParameters) {

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

  {

    if (Hazard_Status == HIGH) {           //checking whether Hazard  status is high

      myNex.writeStr("vis p12,1");          //changing the picture visibility to 1(show)

      myNex.writeStr("vis p13,1");          //changing the picture visibility to 1(show)

      vTaskDelay(800 / portTICK_PERIOD_MS);             //using delay of 800ms

      myNex.writeStr("vis p12,0");          //changing the picture visibility to 0(hide)

      myNex.writeStr("vis p13,0");          //changing the picture visibility to 0(hide)

      vTaskDelay(800 / portTICK_PERIOD_MS);             //using delay of 800ms

    } else {

      myNex.writeStr("vis p12,0");          //changing the picture visibility to 0(hide)

      myNex.writeStr("vis p13,0");          //changing the picture visibility to 0(hide)

    }

    Serial.write(0xff);                             //end of command

    Serial.write(0xff);

    Serial.write(0xff);

  }

  }

//============================End=========================