rishi arora
Published © GPL3+

Distance Detector

This project is used to detect the distance between two objects. This application can be used to detect a congestion-free path.

IntermediateShowcase (no instructions)1 hour765
Distance Detector

Things used in this project

Story

Read more

Code

jamming_iot.ino

Java
const int trigPin=7;
const int echoPin=9;
long Duration;
int Distance;
int sensor=11;
int sensor_value;
void setup() {

  pinMode(2,OUTPUT);
  pinMode(trigPin,OUTPUT);
  pinMode(echoPin,INPUT);
  pinMode(3,HIGH);
  pinMode(4,HIGH);  
  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<20)
  {
    digitalWrite(4,HIGH);
    digitalWrite(3,LOW);
    
  }
  else if(Distance>21)
  {
    digitalWrite(3,HIGH);
    digitalWrite(4,LOW);
  }
  Serial.print("Distance: ");
  Serial.println(Distance);
  
  
 
}

Credits

rishi arora

rishi arora

11 projects • 4 followers

Comments