Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grupo 01 - Sensor Ultrassônico #2

Open
Anderson-MB opened this issue Oct 16, 2023 · 0 comments
Open

Grupo 01 - Sensor Ultrassônico #2

Anderson-MB opened this issue Oct 16, 2023 · 0 comments

Comments

@Anderson-MB
Copy link
Contributor

Anderson-MB commented Oct 16, 2023

Testei o sensor ultrassônico HC-SR04. O código utilizado é disponível abaixo:

// Código para a utilização do sensor ultrasônico:

// Definindo as portas echos e triggers

#define echoPin_frente 5
#define trigPin_frente 4

// variáveis sem sinal no intervalo de 0 a 255

unsigned int duracao = 0;
unsigned int distancia = 0;

void setup(){
  
  // Informando as entradas e as saídas
  
  pinMode(echoPin_frente, INPUT);
  pinMode(trigPin_frente, OUTPUT);
  
  // Criando um monitor serial para informar os resultados
  
  Serial.begin(9600);
  
}

void loop(){
  
  // Funcionamento do sensor dianteiro
  
  digitalWrite(trigPin_frente, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin_frente, LOW);
  
  // Captação do sinal de onda dianteiro
  
  duracao = pulseIn(echoPin_frente, HIGH);
  
  // Velocidade do som se propagando no ar dada por: "[(343,5 * 100)/10e6]/2 = 0,017175"  
  
  distancia = duracao * 0.017175;

  Serial.print(distancia);
  Serial.println("cm --- Adversario a frente");
  
  
  
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant