rishi arora
Published © GPL3+

Motion Sensor

Calculating distance and developing a feature intended for a smart car.

BeginnerShowcase (no instructions)1 hour453
Motion Sensor

Things used in this project

Hardware components

Breadboard (generic)
Breadboard (generic)
×1
Arduino ultrasonic sensor
×1
LED (generic)
LED (generic)
×1
Buzzer
Buzzer
×1

Story

Read more

Schematics

b9AqjX89egAjc58GmM9O.JPG

Code

parking_sensor.ino

C/C++
const int trigPin=7;
const int echoPin=9;
long Duration;
int Distance;
int led=6;
void setup() {

  pinMode(trigPin,OUTPUT);
  pinMode(echoPin,INPUT);
  pinMode(led,OUTPUT);
  Serial.begin(9600);
}

void loop() 
{
  
  digitalWrite(trigPin,LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin,HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin,LOW);
  Duration=pulseIn(echoPin,HIGH);
  Distance=Duration*0.034/2;
  if(Distance<50)
  {
    digitalWrite(led,HIGH);
    
    
  }
  else 
  {
    digitalWrite(led,LOW);
  }
  Serial.print("Distance: ");
  Serial.println(Distance);
}

Credits

rishi arora

rishi arora

11 projects • 4 followers

Comments