Categories
TUTORIALS

DRIVER GUARD: SOS SIGNAL WITH BUZZER + LED BLINKING AND MOTOR DECELERATION

In this tutorial, we will learn how to use button, DC Motor, LED and Piezo buzzer with the Arduino board to prototype an opioid-impaired driving guard system for vehicles. This system is part of our Driver Guard SOS project, I am working on this project with my group mates Gil and Jacey, who each is working on  tutorials on the pulse oximeter detection and  making sure the driver is wearing the pulse oximeter sensor when driving. This tutorial will focus on the alarm system and response for opioid impaired driving.

The Components

To simulate the automobile operating mode with Arduino, we use the DC motor to represent the car engine, the piezo buzzer to represent the car horn and the LED to represent the car lamp. When the alarm system is triggered, the buzzer will sound SOS notes and the LED will blink.

Since Jacey’s tutorial will give detailed introduction to the pulse oximeter sensor, the pulse oximeter detection process is replaced with a push button. The button that represents whether or not breathing is abnormal is button 1. When we’re pushing button 1, it means the pulse oximeter sensor detect the abnormal breathing of the driver, the alarm system will be triggered. If the driver is driving, the abnormal breathing input will active the emergency braking, if the driver is going to driver, the car won’t be started. When we’re not pushing button 1, it means the driver’s breathing is normal.

We use another button to represent whether the car is started or not. This is button 2. When we’re pushing button 2, it means the driver is driving.

Wiring

The images below show how the circuit should be wired in real.

For the pulse oximeter sensor, firstly connect the 3.3 V and GND to the breadboard. Then, connect the VIN pin to 3.3V on the breadboard, connect the SDA to the A4 on the Arduino, connect the SCL to A5 on the Arduino, connect the ground pin to GND on the breadboard.

For the button 1 and button 2, connect the Arduino digital pin 2 (pin 3 for button 2) to the one end of the button, the connect a 10K ohm resistor to the button, connect the other end of the resistor to the 3.3 V on the breadboard. Connect the other end of the button to the GND on the breadboard.

For the LED, connect the LED to the Arduino digital pin 13 with a 330 Ohm resistor in the middle, connect the other end of the resistor to GND on the breadboard.

For the buzzer, connect the buzzer to the Arduino digital pin 10 and GND on the breadboard.

For the DC motor, connectthe DC motor to transistor, connect the other end of the DC motor to 3.3 V on the breadboard, connect the diode to the DC motor in parallel. Note that the transistor we used is MPS2222A, the pins of MPS2222A go: emitter, base, collector. Make sure connect the collector pin to the DC motor, connect the emitter pin to the GND on the breadboard, connect the base pin to the Arduino digital pin 9 with a 330 Ohm resistor in the middle.

Schematic

Circuit with Pulse Oximeter Sensor

Circuit that the button replaces the sensor

Sending SOS Signal

SOS is a Morse code emergency distress signal, comprised of three dots, three dashes, and three dots without space between them. A dot is a short staccato sound and a dash is a longer sound. What does an SOS signal sound like? Check out this link to listen to it https://www.youtube.com/watch?v=9A3tBINRdiE

The SOS system includes a Piezo Buzzer and a LED. Here is the code to make the buzzer sound SOS notes and LED blink.

int Buzzer = 10; // The buzzer simulates the car's horn
int LED = 13; // The LED simulates the car's lamp
int pause = 100; // Set the time the buzzer pause 
int note = 400;  // Set the time the buzzer's note

void setup()
{  pinMode(LED, OUTPUT); // Set up the LED pin to be an output
   pinMode(Buzzer, OUTPUT); // Set up the buzzer pin to be an output
}

void loop()
{ digitalWrite(LED, HIGH);   // Turn on the LED 
  for (int i=0; i<3; i++){
  tone(Buzzer, note, 100);
  delay(200);
  noTone(Buzzer);
  }
  delay(200);
  
  digitalWrite(LED, LOW);    // Turn off the LED
  for (int i=0; i<3; i++){
  tone(Buzzer, note, 300);
  delay(400);
  noTone(Buzzer);
  }
  delay(200);
  
  digitalWrite(LED, HIGH);   // Turn on the LED 
  for (int i=0; i<3; i++){
  tone(Buzzer, note, 100);
  delay(200);
  noTone(Buzzer);
  }
  delay(600);
 }

Scenarios

There are three scenarios for our project.

  • The driver is going to start the car, but the pulse oximeter sensor detects abnormal breathing in the driver, the alarm will be triggered and send SOS signal, the car can’t be started.
  • The driver is going to start the car, the driver’s breathing is normal, the car can be started.
  • The driver is driving on the road, the pulse oximeter sensor detects abnormal breathing in the driver, the alarm will be triggered and send SOS signal, the emergency braking will be activated, the car will slow down to stop.

Here is the video I made to show the three scenarios.

Code

Here is the code for the tutorial.

int ButtonOximeter = 2;
// Button 1 simulates pulse oximeter sensor,
// when button 1 is pushed, it means the breath is lower than the normal value.
int ButtonRunCar = 3;
// Button 2 simulates the process of run the car,
// when button 2 is pushed, it means the driver start the car.
int Buzzer = 10; // The buzzer simulates the car's horn
int LED = 13; // The LED simulates the car's lamp
int Motor = 9; // The motor simulates the car's engine
int pause = 100; // Set the time the buzzer pause 
int note = 400;  // Set the time the buzzer's note 


void setup()
{ 
   pinMode(ButtonOximeter, INPUT); // Set up the pushbutton pins to be an input
   pinMode(ButtonRunCar, INPUT); // Set up the pushbutton pins to be an input
  
   pinMode(LED, OUTPUT); // Set up the LED pin to be an output
   pinMode(Buzzer, OUTPUT); // Set up the buzzer pin to be an output
   pinMode(Motor, OUTPUT); // Set up the motor pin to be an output
}


void loop()
{
  int ButtonOximeterState, ButtonRunCarState;
  ButtonOximeterState = digitalRead(ButtonOximeter);
  ButtonRunCarState = digitalRead(ButtonRunCar);
  int speed;

if ((ButtonOximeterState == LOW) && (ButtonRunCarState == HIGH))
// If we're pushing the button 1 and we'are not pushing button 2,
// which means the driver's breathing is slower than normal,
// the driver is going to start the car and potentially opioid overdose,
// the alert is triggered and the driver can not run the car 
 {
  digitalWrite(Motor, LOW); // Turn off the motor
  digitalWrite(LED, HIGH);   // Turn on the LED 
  for (int i=0; i<3; i++){
  tone(Buzzer, note, 100);
  delay(200);
  noTone(Buzzer);
  }
  delay(200);
  
  digitalWrite(LED, LOW);    // Turn off the LED
  for (int i=0; i<3; i++){
  tone(Buzzer, note, 300);
  delay(400);
  noTone(Buzzer);
  }
  delay(200);
  
  digitalWrite(LED, HIGH);   // Turn on the LED 
  for (int i=0; i<3; i++){
  tone(Buzzer, note, 100);
  delay(200);
  noTone(Buzzer);
  }
  delay(600);
 }
 
if ((ButtonOximeterState == LOW) && (ButtonRunCarState == LOW))
// If we're pushing the two buttons at the same time, 
// which means the driver's breathing is slower than normal,
// the driver is potentially opioid overdose, the car is running at the same time
// the alarm will be triggered, the buzzer sound SOS signal and the car will slow down to stop
  {
  digitalWrite(LED, HIGH);   // Turn on the LED 
  for (int i=0; i<3; i++){   // Turn on the Buzzer, make it sound three short notes
  tone(Buzzer, note, 100);
  delay(200);
  noTone(Buzzer);
  }
  delay(200);
  
  digitalWrite(LED, LOW);    // Turn off the LED
  for (int i=0; i<3; i++){   // Turn on the Buzzer, make it sound three long notes
  tone(Buzzer, note, 300);
  delay(400);
  noTone(Buzzer);
  }
  delay(200);
  
  digitalWrite(LED, HIGH);   // Turn on the LED 
  for (int i=0; i<3; i++){   // Turn on the Buzzer, make it sound three short notes
  tone(Buzzer, note, 100);
  delay(200);
  noTone(Buzzer);
  }
  delay(400);
  
  for(speed = 200; speed >= 0; speed--) // Slow down a running motor
  {
    analogWrite(Motor,speed);  // Set the new speed
  }
  }
  
if ((ButtonOximeterState == HIGH) && (ButtonRunCarState == LOW))
// If we're pushing the button 2 and we'are not pushing button 1, 
// which means the driver is driving and the driver's breathing is normal
// the car can run properly
  {
    digitalWrite(Buzzer, LOW); // Turn off the buzzer
    digitalWrite(LED, LOW);    // Turn off the LED
    digitalWrite(Motor, HIGH); // Turn on the motor
    delay(1000); 
  }

if ((ButtonOximeterState == HIGH) && (ButtonRunCarState == HIGH))
// If we're not pushing the buttons, 
// which means the car didn't start
  {
  digitalWrite(Buzzer, LOW); // Turn off the buzzer
  digitalWrite(LED, LOW);    // Turn off the LED
  digitalWrite(Motor, LOW); // Turn off the motor
  }
 }

Thanks for reading. Hope you enjoy this tutorial! Please let me know if you have any questions!

Leave a Reply

Your email address will not be published. Required fields are marked *