Ultrasonic sensorHC-SR04 with Automotive relay ( Vehicle ignition relay S1122P )

Hi,

I am a newbie here and not expert into programming thing. Appreciate if I can have valuable advice and guidance from experts in this forum.

My intention/idea is to de-energised vehicle ignition relay when the ultrasonic sensor is not detecting driver presence in the vehicle when the vehicle engine is still running.

I managed to have source code online to for "ultrasonic sensor" but I have no idea about code to de-energise the relay and how to do wire connection from Arduino to the ignition relay.

Additional concerns: I also wonder whether using the ultrasonic sensor to detect human presence is practical? In fact, recently I also found there is a grid eye evaluation breakout board to detect human presence. I really appreciate your help. May God Bless You all.

Code below for ultrasonic sensor(Credit to owner Oleesa)

...
#include <Servo.h>
#include <LiquidCrystal.h>

Servo robotNeck; //servo variable with name robotNeck

LiquidCrystal lcd(1, 2, 4, 5, 6, 7); // Creates an LCD object with parameters: (rs, enable, d4, d5, d6, d7)

//assign pin numbers
//const int trigPin = 9; //Pin 9 where ultrasonic distance sensor trig is connected
//const int echoPin = 10; //Pin 10 where ultrasonic distance sensor echo is connected
const int sigPin = 13;

int distanceCm, distanceIn;
long timeVal;
const int speedOfSound = 0.0343; //sets the speed of sound to a constant value

void setup() {
robotNeck.attach(3); //Servo is connected to arduino pin ~3

//pinMode(echoPin, INPUT); //sets echoPin as input
//pinMode(trigPin, OUTPUT); //sets trigPin as output

lcd.begin(16, 2); //Initializes the lcd and specifies the dimension (width and height, respectively) of the display

lcd.setCursor(3,0);
lcd.print("Welcome to");
delay(1000);
lcd.clear();
lcd.setCursor(4,0);
lcd.print("OLEESA'S");
lcd.setCursor(1,1);
lcd.print("Distance Meter");
delay(2500);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Booting.");
delay(500);
lcd.clear();
lcd.print("Booting..");
delay(1000);
lcd.clear();
lcd.print("Booting...");
delay(1500);
lcd.clear();

}

void loop() {
//Rotate robotNeck from 15 to 165 because of limits which might draw too much current
for(int j=15; j<=165; j++){
robotNeck.write(j);
delay(10);

distanceCm = distCalc();
distanceIn = distCalc();

//To display value on the lcd
lcd.setCursor(0,0); // Sets the location at which subsequent text written to the LCD will be displayed
lcd.print("Distance: "); // Prints string "Distance: " on the LCD
lcd.print(distanceCm); // Prints the distance value from the sensor
lcd.print("cm"); // Prints the unit of measurement
delay(10); //waits for 10 milliseconds

lcd.setCursor(0,1); // Sets the location at which subsequent text written to the LCD will be displayed
lcd.print("Distance: "); // Prints string "Distance: " on the LCD
lcd.print(distanceIn); // Prints the distance value from the sensor
lcd.print("in"); // Prints the unit of measurement
delay(100); //waits for 100 milliseconds
}

for(int j=165; j>=15; j--){
robotNeck.write(j);
delay(10);

distanceCm = distCalc();
distanceIn = distCalc();

//To display value on the lcd
lcd.setCursor(0,0); // Sets the location at which subsequent text written to the LCD will be displayed
lcd.print("Distance: "); // Prints string "Distance: " on the LCD
lcd.print(distanceCm); // Prints the distance value from the sensor
lcd.print("cm"); // Prints the unit of measurement
delay(100); //waits for 100 milliseconds

lcd.setCursor(0,1); // Sets the location at which subsequent text written to the LCD will be displayed
lcd.print("Distance: "); // Prints string "Distance: " on the LCD
lcd.print(distanceIn); // Prints the distance value from the sensor
lcd.print("in"); // Prints the unit of measurement
delay(100); //waits for 100 milliseconds
}
}

int distCalc(){
pinMode(sigPin, OUTPUT);

digitalWrite(sigPin, LOW);
delayMicroseconds(2);

digitalWrite(sigPin, HIGH);
delayMicroseconds(10);
digitalWrite(sigPin, LOW);

// The same pin is used to read the signal from the PING))): a HIGH pulse
// whose duration is the time (in microseconds) from the sending of the ping
// to the reception of its echo off of an object.
pinMode(sigPin, INPUT);
timeVal = pulseIn(sigPin, HIGH);

//converts time to distance
distanceCm = timeVal / 29 / 2;
distanceIn = timeVal / 74 / 2;

return distanceCm, distanceIn;
}

My intention/idea is to de-energised vehicle ignition relay when the ultrasonic sensor is not detecting driver presence in the vehicle when the vehicle engine is still running.

Excuse me, but quite a stupid idea. Imagine you ultrasonic sensor has a malfunction and interrupts the ignition while you're driving. No insurance would pay for an accident caused by a grossly negligent or even intentional reduction of vehicle safety.

What are you trying to solve with this project? Do you leave your car without turning the key and taking it with you?

Hi,

I am aware of the safety concerns as mentioned by you and, I also doubt that the ultrasonic sensor is practical for this application.

I am in a filed of vehicle fleet management, and I have drivers who actually forget to turn off the ignition (engine is idling) on manual transmission vehicle but the vehicle moved and collide into a building.

At the current stage, this is a concept in order to prevent such an unfortunate incident from happening.

For your information, my company only deploy a vehicle within our premises only and not a public on-the-road vehicle. Vehicles are not registered to travel on the public road.

I am aware that I need to incorporate with additional sensors or devices to ensure in case sensor faulty vehicle won't stop suddenly as u mentioned.

Additional info is that, if I am not wrong there are some vehicle came with an integrated driver seat with a sensor which engine will cut off if the driver is not presence at the driver cabin for few seconds. ( some of the forklift seats has this features)

Take it as I am exposing myself to learn about sensors and programming which is also new to me.
Currently, I just wanna know that this concept whether can work? Thank you.

I hope this stupid idea will prevent an accident or save someone in the future. To be honest I have no idea but I still insist to try out.

If the driver must set in a seat in order to drive, use a switch under the seat, like newer vehicles use.

Paul

Just a thought: I like the switch under the seat. Couldn't be much simpler. I might add a time delay of a second or two. What if the driver hits a bump and comes off seat? What if the driver raises off the seat for a moment to readjust how they are sitting?