top of page
Technology
Screenshot (781).png

Code anti sleep alarm car

  • stemlabrkmvp
  • Dec 20, 2024
  • 4 min read

Updated: Dec 28, 2024

To create an Anti-Sleep Alarm Car System using an Arduino Uno, we need to address a few limitations of the Arduino platform. The Arduino Uno doesn't have enough processing power to run complex image processing tasks like detecting a driver's eyes in real-time. For that reason, we'll use external sensors, such as an Infrared (IR) sensor to detect driver presence, and simple blink detection to monitor fatigue. The drowsiness detection can be achieved using a gesture sensor or a basic vibration sensor to detect unusual patterns like head nodding (a sign of sleepiness).

How the System Works:

  1. Driver Presence: The system will first use an IR sensor or seat pressure sensor to detect if the driver is seated and active. If the driver is in the seat, the system starts monitoring for signs of fatigue.

  2. Drowsiness Detection: For simplicity, we'll use a vibration sensor (or an accelerometer) to detect head nodding. When the sensor detects continuous or abnormal vibration, it will trigger an alarm.

  3. Alarm Trigger: If drowsiness is detected (from vibration or motion), the system will trigger a buzzer or LED as an alert.

Required Components:

  1. Arduino Uno board

  2. IR Proximity Sensor or Pressure Sensor: Detects if the driver is in the seat.

  3. Vibration Sensor or Accelerometer (e.g., MPU6050): Detects signs of fatigue such as head nodding.

  4. Buzzer: Sounds the alarm when drowsiness is detected.

  5. LED (optional): For a visual alert.

  6. Resistors and Wires: For connecting components.

Wiring:

  1. IR Proximity Sensor (or Pressure Sensor):

    • Connect VCC to 5V on Arduino.

    • Connect GND to GND.

    • Connect the OUT pin to digital pin 7 on Arduino.

  2. Vibration Sensor:

    • Connect VCC to 5V on Arduino.

    • Connect GND to GND on Arduino.

    • Connect OUT to digital pin 8 on Arduino.

  3. Buzzer:

    • Connect the positive leg to digital pin 9 on Arduino.

    • Connect the negative leg to GND.

  4. LED (optional):

    • Connect the anode (positive) of the LED to digital pin 13.

    • Connect the cathode (negative) to GND through a 220Ω resistor.

Arduino Code:

// Pin definitions
int irSensorPin = 7;    // Pin connected to IR sensor
int vibSensorPin = 8;   // Pin connected to Vibration sensor
int buzzerPin = 9;      // Pin connected to Buzzer
int ledPin = 13;        // Pin connected to LED (optional)

// Variables for tracking sensor states
bool driverPresent = false;
bool drowsinessDetected = false;
int vibrationThreshold = 1000; // Adjust based on sensor sensitivity

void setup() {
  // Set up the pins
  pinMode(irSensorPin, INPUT); // IR sensor input
  pinMode(vibSensorPin, INPUT); // Vibration sensor input
  pinMode(buzzerPin, OUTPUT);   // Buzzer output
  pinMode(ledPin, OUTPUT);      // LED output
  
  // Start serial communication for debugging
  Serial.begin(9600);
}

void loop() {
  // Check if the driver is in the seat
  driverPresent = digitalRead(irSensorPin);

  // If the driver is not in the seat, turn off the alarm
  if (!driverPresent) {
    digitalWrite(buzzerPin, LOW);  // Turn off the buzzer
    digitalWrite(ledPin, LOW);     // Turn off the LED
    Serial.println("No driver detected");
    return; // Exit the loop if no driver is present
  }

  // Driver is present, check for signs of drowsiness
  int vibrationReading = analogRead(vibSensorPin); // Read vibration sensor value
  
  // Print the sensor value for debugging
  Serial.print("Vibration Reading: ");
  Serial.println(vibrationReading);

  // If vibration exceeds threshold, assume driver is drowsy (head nodding)
  if (vibrationReading > vibrationThreshold) {
    drowsinessDetected = true;
  } else {
    drowsinessDetected = false;
  }

  // If drowsiness is detected, activate the alarm
  if (drowsinessDetected) {
    digitalWrite(buzzerPin, HIGH);  // Turn on the buzzer
    digitalWrite(ledPin, HIGH);     // Turn on the LED
    Serial.println("Drowsiness Detected! Alarm triggered!");
  } else {
    digitalWrite(buzzerPin, LOW);  // Turn off the buzzer
    digitalWrite(ledPin, LOW);     // Turn off the LED
  }
  
  delay(200);  // Small delay to stabilize sensor readings
}

Description of the Code:

  1. Initialization:

    • The pins for the IR sensor, vibration sensor, buzzer, and LED are defined. The Serial communication is initialized for debugging.

  2. Driver Detection:

    • The system first checks if the IR sensor detects the driver. If the sensor reads a low value (driver not present), the alarm system is turned off.

  3. Drowsiness Detection:

    • If the driver is detected, the system reads the vibration sensor to check for abnormal movements (such as head nodding). The vibration sensor value is compared to a threshold value to determine if drowsiness is detected.

  4. Alarm Trigger:

    • If drowsiness is detected (based on the vibration sensor), the buzzer sounds, and the LED lights up. If no drowsiness is detected, both the buzzer and LED remain off.

  5. Serial Monitor:

    • For debugging, the system outputs the vibration sensor reading to the Serial Monitor to observe how the system is detecting movements.

Fine-Tuning the System:

  1. Vibration Threshold:

    • The vibrationThreshold value can be adjusted to be more or less sensitive to detect fatigue. You may need to experiment with different values based on your sensor's characteristics.

  2. Sensor Calibration:

    • You may need to calibrate the vibration sensor and experiment with the IR sensor to ensure accurate detection of driver presence and movement patterns.

  3. Additional Features:

    • You can add more sophisticated motion sensors or integrate with other technologies (e.g., a camera system for eye detection) if desired.

Conclusion:

This simple Anti-Sleep Alarm Car System uses basic sensors to monitor for drowsiness in a driver. The Arduino Uno is used to monitor driver presence and motion patterns that indicate fatigue. If the system detects head nodding or inactivity, it triggers an alarm to alert the driver. This solution is relatively straightforward, cost-effective, and can be enhanced with more advanced sensors for better accuracy and functionality.

 
 
 

Recent Posts

See All
SMART BRIDGE

Smart Bridge System using Arduino Uno Creating a Smart Bridge  system involves using sensors to monitor the bridge's condition (such as...

 
 
 

Comments


bottom of page