0% found this document useful (0 votes)
6 views1 page

Sensor

The document contains an Arduino code that measures distance using ultrasonic sensors. It controls three LEDs (red, yellow, green) based on the measured distance, turning them on or off depending on specific distance ranges. The setup includes defining pins for the LEDs and the sensor, and the loop continuously checks the distance and updates the LED states accordingly.

Uploaded by

Isabele Cristina
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

Sensor

The document contains an Arduino code that measures distance using ultrasonic sensors. It controls three LEDs (red, yellow, green) based on the measured distance, turning them on or off depending on specific distance ranges. The setup includes defining pins for the LEDs and the sensor, and the loop continuously checks the distance and updates the LED states accordingly.

Uploaded by

Isabele Cristina
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

int vermelho = 2;

int amarelo = 1;
int verde = 3;
int trigger = 5;
int echo = 6;
float distancia;
float tempo;

void setup()
{
pinMode(vermelho, OUTPUT);
pinMode(amarelo, OUTPUT);
pinMode(verde, OUTPUT);
pinMode(trigger, OUTPUT);
pinMode(trigger, OUTPUT);
pinMode(echo, INPUT);
}

void loop()
{
digitalWrite(trigger, LOW);
delayMicroseconds(2);
digitalWrite(trigger, HIGH);
delayMicroseconds(10);
digitalWrite(trigger, LOW);
tempo = pulseIn(echo, HIGH);
distancia = (0.0343*tempo)/2;

if ((distancia<=150) && (distancia>=100))


{
digitalWrite(verde, HIGH);
}
else
{
digitalWrite(verde, LOW);
}
if ((distancia<=100) && (distancia>=50))
{
digitalWrite(amarelo, HIGH);
}
else
{
digitalWrite(amarelo, LOW);
}
if ((distancia <=50) && (distancia>15))
{
digitalWrite(vermelho, HIGH);
}
else
{
digitalWrite(vermelho, LOW);
}
}

You might also like