Link Ads

More search type here...

Showing posts with label arduino parking alarm. Show all posts
Showing posts with label arduino parking alarm. Show all posts

April 22, 2014

PARKING ALARM CAR


/* THIS IS PARKING ALARM SYSTEM MODIFICATION FROM PING SENSOR from ARDUINO.CC    THIS PROGRAM USING PING SENSOR+LCD+TONE
   MODIFICATION BY: ARDUINOEASYPROJECT.BLOGSPOT.COM
    
   The circuit PING SENSOR:
    * +V connection of the PING attached to +5V
    * GND connection of the PING attached to ground
    * SIG connection of the PING attached to digital pin 7

   The circuit Piezo:
    * attached to pin 9
    * attached to ground
 */


const int pingPin = 7;
float sinVal;
int toneVal;
int PiezoPin = 9;  //Output to piezo pin 9

void setup()
{
  Serial.begin(9600);
  pinMode(PiezoPin, OUTPUT);  
}

void loop()
{
  long duration, inches, cm;
  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin, LOW);
  pinMode(pingPin, INPUT);
  duration = pulseIn(pingPin, HIGH);
  inches = microsecondsToInches(duration);
  cm = microsecondsToCentimeters(duration);
 
  Serial.print(inches);                  // THIS SERIAL JUST FOR DEVELOPER TO TEST
  Serial.print("in, ");
  Serial.print(cm);
  Serial.print("cm");
  Serial.println();
 
  if (cm <= 25)   // YOU CAN CHANGE THE DISTANCE WARNING AT THIS
    {
    for (int x=0; x<270; x=x+10)
      {
      sinVal = (sin(x*(3.1412/180)));
      toneVal = 2000+(int(sinVal*1000));
      Serial.println(sinVal);
      tone(PiezoPin, toneVal);
      delay(5);
      }
    }
  else
  { noTone(PiezoPin); }
  delay(100);
}

long microsecondsToInches(long microseconds)
{
  return microseconds / 74 / 2;
}

long microsecondsToCentimeters(long microseconds)
{
   return microseconds / 29 / 2;
}



This arduino parking alarm system will generate alarm sound when the car move to close the object around 25 cm. It is easy to change save distance, just set the cm variable in the program that you want.