Está en la página 1de 2

#include <SoftwareSerial.

h>

SoftwareSerial Bluetooth(8, 9); // RX, TX do Arduino


const int pinoOut = 2; //PINO infravermelho
int btTx = 9; // PINO BT tx
int btRx = 8; // PINO BT rx
const int trigPin = 4; // PINO ultrassom
const int echoPin = 3; // PINO ultrassom do eco

float duration, distance; // Duração e distancia do eco, deixa a informação mais


precisa

void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(pinoOut, INPUT); //DEFINE O PINO COMO ENTRADA
Serial.begin (9600); //INICIALIZA A SERIAL
Bluetooth.begin(9600);

void loop() {
//if (digitalRead(pinoOut) == LOW) { //SE LEITURA DO PINO FOR IGUAL A LOW,
FAZ
//Serial.println ("Objeto detectado"); //IMPRIME O TEXTO NO MONITOR SERIAL
//} else { //SENÃO, FAZ
// Serial.println ("Nenhum objeto detectado");
//IMPRIME O TEXTO NO MONITOR SERIAL
//}

digitalWrite(trigPin, LOW);
delayMicroseconds(1000);
digitalWrite(trigPin, HIGH);
delayMicroseconds(50);
digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);

distance = (duration * .0343) / 2;

//if (distance > 200.00) {


//Serial.println("DESOCUPADO........");
//} else {
//Serial.println("OCUPADO.............");
//}

if (digitalRead(pinoOut) == LOW && distance < 200.00 ) {


Serial.println("OCUPADO");
Bluetooth.print("NÃO TEM VAGA");
}
else {
Serial.println("DESOCUPADO");
Bluetooth.print("TEM VAGA");
}

//Bluetooth.print();
//Serial.print("Distance: ");
//Serial.println(distance);
delay(1000);

También podría gustarte