Naya Lee
Published

A Smart Car Door to protect your driving safety

A project by a team of students from Hebei University of Technology

IntermediateShowcase (no instructions)8 hours167
A Smart Car Door to protect your driving safety

Things used in this project

Story

Read more

Code

Code

C/C++
#include <rgb_lcd.h>
#include <Wire.h>
#include <Servo.h>
#include <Ultrasonic.h>
#include <U8x8lib.h>
#include <U8g2lib.h>
#include <Arduino.h>
#include "DHT.h"


U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(U8X8_PIN_NONE);
Servo myServo
Ultrasonic ultrasonic(2);
rgb_lcd lcd;

int FingerValue,ServoAngle;
float centimeter1,centimeter2,Speed,temperature,humidity;
char c;
int Switch;

DHT dht(3,DHT11);

void setup() 
{
  dht.begin();
  
  myServo.attach(9);
  
  Serial.begin(9600);
  
  lcd.begin(16,2);
  lcd.setRGB(255,0,0);
  lcd.setCursor(0,0);
  lcd.print("D:");
  lcd.setCursor(0,1);
  lcd.print("Speed:");
  
  u8x8.begin();
  u8x8.setPowerSave(0);
  u8x8.setFlipMode(1);
  
  pinMode(A0,INPUT);
  pinMode(4,OUTPUT);
  pinMode(5,OUTPUT);
  pinMode(6,INPUT);
  pinMode(7,OUTPUT);
  
  digitalWrite(4,LOW);
  digitalWrite(5,LOW);
  digitalWrite(7,LOW);
}

void loop() 
{
  temperature=dht.readTemperature();
  humidity=dht.readHumidity();
  u8x8.setFont(u8x8_font_chroma48medium8_r);     
  u8x8.setCursor(0,33);
  u8x8.print("WENDU:");
  u8x8.print(temperature);
  u8x8.print("C");
  u8x8.setCursor(0,50);
  u8x8.print("SHIDU:");
  u8x8.print(humidity);
  u8x8.print("%");
  
  Switch=digitalRead(6);
  centimeter1=ultrasonic.MeasureInCentimeters();
  if(centimeter1<=20)
  {
    digitalWrite(4,HIGH);
    digitalWrite(5,LOW);
    digitalWrite(7,LOW);
  }
  else
  {
    if(Switch==LOW)
    {
     digitalWrite(4,LOW);
     digitalWrite(5,LOW);
     digitalWrite(7,LOW);
    }
    if(Switch==HIGH)
    {
     digitalWrite(4,LOW);
     digitalWrite(5,HIGH);
     digitalWrite(7,HIGH);
    }
  }
  delay(100);
  centimeter2=ultrasonic.MeasureInCentimeters();
  Speed=(abs(centimeter1-centimeter2))*10.0/100.0;
  lcd.setCursor(4,0);
  lcd.print(centimeter1);
  lcd.setCursor(12,0);
  lcd.print("cm");
  lcd.setCursor(7,1);
  lcd.print(Speed);
  lcd.setCursor(13,1);
  lcd.print("m/s");
  
  FingerValue=analogRead(A1);
  ServoAngle=map(FingerValue,494,762,0,90);
  myServo.write(ServoAngle);
  while(Serial.available())
  {
        c=Serial.read();
        if(c=='1')
        {
           Serial.println("BT is ready");
           Serial.write("LED Light");
           digitalWrite(5,HIGH);
           digitalWrite(4,LOW);
        }
        else if(c='2')
        {
            Serial.write("LED Black");
            digitalWrite(5,LOW);
            digitalWrite(4,HIGH);
        }
  }
  delay(700);
}

Credits

Hu Tianyi, Zhang Xinpeng, Geng Ziyang, Yuan Dehua

Posted by Naya Lee

Comments