Ir ao conteúdo

Sensor de Distância ultrasonico com Arduino e HC-SR04 (Arduino + HC-SR04)

Boa noite,

Continuando minhas aventuras com o Arduino e sensores. Hoje decidi brincar com o Sensor Ultrasonico HC-SR04 para medir distancia.

O funcionamento do mesmo é realmente simples, ele possui 4 pinos, VCC para alimentação, Trig para iniciar uma medida, Echo para retorno da distância e GND terra.

O mesmo possui uma biblioteca pronta para fazer as medidas e tudo mais. A mesma se chama Ultrasonic. O unico problema que tive com a mesma é que ela estava desatualizada e ainda utilizava o WProgram.h enquanto o Arduino 1.0.1 utiliza Arduino.h, atulizei a mesma e executei sem problemas.

A mesma deve ser incluida no seu diretório “arduino-1.0.1/libraries” e você deve fechar e abrir a IDE.

Sensor VCC conecta ao Arduino +5V pino
Sensor Trig conecta ao Arduino PINO 12
Sensor Echo conecta ao Arduino PINO 13
Sensor GND conecta ao Arduino GND

Você pode configurar os pinos nas variáveis trig e echo.

[code lang=”c”]
#include “Ultrasonic.h”
int trig = 12;
int echo = 13;
Ultrasonic ultrasonic(trig,echo);

void setup() {
Serial.begin(9600);
}

void loop()
{
Serial.print(“Distance CM:”);
Serial.println(ultrasonic.Ranging(CM));
Serial.print(“Distance INC:”);
Serial.println(ultrasonic.Ranging(INC));
delay(100);
}
[/code]

Referências:
HC-SR04 DataSheet
Biblioteca Ultrasonic atualizada para Arduino 1.0.1

Publicado emAndroid

1.420 Comentários

  1. You can certainly see your skills in the work you write. The world hopes for even more passionate writers like you who aren’t afraid to say how they believe. Always follow your heart.

  2. Hi there, I found your web site via Google while looking for a related topic, your site came up, it looks great. I’ve bookmarked it in my google bookmarks.

  3. http://ul-digital.fr/
    La societe Ul Digital se positionne comme une structure experimentee focalisee sur le marche francais, qui propose une approche complete aux entreprises et particuliers, en valorisant sur les resultats. Visitez le site sur cette page.

  4. I have acquired some new things from your web site about personal computers. Another thing I’ve always presumed is that computers have become a specific thing that each household must have for several reasons. They offer convenient ways to organize the home, pay bills, search for information, study, hear music and also watch television shows. An innovative way to complete all of these tasks is with a laptop. These desktops are mobile ones, small, strong and easily transportable.

  5. http://virthua.fr/
    La societe Virthua s’impose comme une structure experimentee focalisee sur le cadre national francais, qui met a disposition une approche complete aux entreprises et particuliers, en priorisant sur l’attention personnalisee. En savoir plus ici.

  6. Thank you for the good writeup. It in fact was a amusement account it. Look advanced to far added agreeable from you! By the way, how can we communicate?

  7. http://bartalomej.de/
    Bartalomej praesentiert sich als ein professionelles Unternehmen spezialisiert auf den deutschen Markt, das ermoeglicht ganzheitliche Ansaetze fuer alle die Ergebnisse suchen, sich auszeichnend durch auf persoenliche Betreuung. Entdecken Sie mehr auf dieser Seite.

Deixe um comentário

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *