F4M1L135
Published © GPL3+

Proximity Sensor

Proximity sensor, something like the sensors of cars!

BeginnerProtip10,289
Proximity Sensor

Things used in this project

Story

Read more

Schematics

The schematics

for the reverse sensor

Code

Code of the program

Arduino
The code for the program i made
int TRIG = 5;
int ECO = 6;
int LED = 3;
int DURACION;
int DISTANCIA;
int LED2 = 2; 
int LED3 = 4;
int ALERTA = 7;

void setup() {
  // put your setup code here, to run once:
pinMode(TRIG, OUTPUT);
pinMode(ECO, INPUT);
pinMode(LED, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(ALERTA, OUTPUT);
Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
digitalWrite(TRIG, HIGH);
delay(1);
digitalWrite(TRIG, LOW);
DURACION = pulseIn(ECO, HIGH);
DISTANCIA = DURACION / 58.2;
Serial.println(DISTANCIA);
delay(200);

if (DISTANCIA <= 15 && DISTANCIA >= 8 ) {
  digitalWrite(LED, HIGH);
}
else {
  digitalWrite(LED, LOW);

  if (DISTANCIA <= 20 && DISTANCIA > 15) {
    digitalWrite(LED2, HIGH);
    
    
  }
  else {
    digitalWrite (LED2, LOW);
  
    if (DISTANCIA > 20) {
      digitalWrite(LED3, HIGH);
    
    }
    else {
      digitalWrite (LED3, LOW);
     
 
if (DISTANCIA < 7 && DISTANCIA >= 0) {
  digitalWrite (ALERTA, HIGH);
  delay(150);
  digitalWrite (ALERTA, LOW);
  delay(150);
}
else {
  digitalWrite (ALERTA, LOW);
}
    }
  }

}
}

Credits

F4M1L135

F4M1L135

0 projects • 0 followers

Comments