Categories
TUTORIALS

Tutorial: driverguard car ignition Protection

This tutorial will teach you how to code for circumstances where a condition needs to be set before further action can be taken: in this case, we are preventing a car from starting until an oximeter sensor in a glove registers a blood oxygen saturation in the drivers hand. However, due to the limitations set by the COVID-19 Pandemic, we will be approximating both of these as push-buttons for the purpose of this tutorial. This will, however, make it easier for you to apply it to your own projects.

Parts

For this particular tutorial, all the parts you will need are included in the Arduino Uno Starter Pack. They are:

  • Arduino Uno with breadboard
  • Two (2) pushbuttons
  • Two (2) 10k Ohm resistors
  • 330 Ohm resistor
  • 5V LED
  • Seven (7) jumper wires

Circuit

The circuit we are using for this project is the same as Circuit 5 in the Arduino USK Guide, but here is a breadboard diagram below.

Connect the left-hand push-button with the yellow wire to digital pin 2, which accepts only binary inputs.

Connect the right-hand push-button is with the green wire to pin 3, which can accept continuous inputs.

This is because, in our case, the left-hand button is a stand-in for a car’s ignition, which can only be turned on or off, while the right-hand button represents an oximeter glove, which would provide a continuous input; because, for this part of the DriverGuard project, we are only concerned with whether or not the oximeter glove is being worn, a push-button is a reasonable substitution. The LED represents whether or not the car is on.

The wiring is as follows:

  • Red wire: Arduino 5V -> Positive Rail
  • Black wire: Arduino Ground -> Negative Rail
  • Green wire: Arduino Digital Pin 3 -> Oximeter Proxy push-button
  • Yellow wire: Arduino Digital Pin 2 -> Ignition Proxy push-button
  • Blue and Orange wires: Push-buttons -> Negative Rail
  • White wire: LED Anode -> Arduino Digital Pin 13
  • 10k Ohm Resistors: Push-buttons -> Positive Rail
  • 330 Ohm Resistors: LED Cathode -> Negative Rail

The Code

For this project, the desired output is simple: in order for the LED to turn on, both buttons have to be pressed. In the case of the DriverGuard project, this means that, in order for the car to turn on, the oximeter glove must be worn when the ignition is turned on.

/*
Gil Lehmann
April 19, 2020
CPLN 571 Tutorial: DriverGuard Ignition Circuit

This  code is meant as a representation of the actual product:
push-buttons replace the Oximeter glove and car ignition that would 
be present in the actual DriverGuard system.
An LED represents the car's ignition here.
This circuit and code are based on the USK Guide Code Circuit 5
*/


// First we'll set up constants for the pin numbers.
// This will make it easier to follow the code below.

const int ignitionPin = 2;  // ignition button pin
const int oximeterPin = 3;  // oximeter button pin
const int ledPin =  13;    // LED pin


void setup()
{
  // Set up the pushbutton pins to be an input:
  pinMode(ignitionPin, INPUT);
  pinMode(oximeterPin, INPUT);

  // Set up the LED pin to be an output:
  pinMode(ledPin, OUTPUT);      
}


void loop()
{
  int ignitionState, oximeterState;  
  // variables to hold the states of the glove and the ignition

  // In this case we're approximating the ignition and oximeter as pushbuttons.
  // O2Sat will be approximated by this variable:
  int O2Sat = 0;
  
  // Here we'll read the current pushbutton states into
  // two variables:

  ignitionState = digitalRead(ignitionPin); //simple on or off

  if (digitalRead(oximeterPin) == LOW) 
  //in this case, the button means the glove is being worn
  {
    O2Sat = 95; //95 as a value greater than 90
  }
 

  if ((ignitionState == LOW) && (O2Sat > 0)) 
  //if ignition is on and the glove is registering 
  {
    digitalWrite(ledPin, HIGH);  
    // turn the LED on to represent the car turning on
  }
  else
  {
    digitalWrite(ledPin, LOW);  
    // turn the LED off to represent the car being off
  }

}

Because this is a simple bit of code and a simple circuit, it is ready to be altered for whatever project you need it for. Just replace the push-buttons with the sensors you intend to use (and wire them correctly!), and alter the code to fit those sensors. Enjoy!

Leave a Reply

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