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.338 Comentários

  1. http://rothschild-kollegen.de/
    Das Projekt Rothschild Kollegen positioniert sich als ein spezialisierte Agentur spezialisiert auf den nationalen Rahmen Deutschlands, das liefert massgeschneiderte Loesungen fuer alle die Ergebnisse suchen, sich auszeichnend durch auf Ergebnisse. Erfahren Sie mehr auf der offiziellen Website.

  2. http://sol4bus.de/
    Sol4bus etabliert sich als ein spezialisierte Agentur spezialisiert auf den deutschen Markt, das liefert ganzheitliche Ansaetze fuer alle die Effizienz schaetzen, priorisierend auf Servicequalitaet. Entdecken Sie mehr auf der offiziellen Website.

  3. LFA 232 makes its return to the Premier Theater stage at Foxwoods Resort Casino this Friday with the vacant featherweight championship up for grabs and an event deep with local veterans and undefeated prospects.

  4. The upcoming UFC Vegas 117 card represents an archetypal Apex event, featuring tight matchups and a few distinct stylistic clashes that present actionable betting value.

  5. This coming Saturday UFC Vegas 117 the usual silent atmosphere of the Apex, and although the environment feels lifeless, the consequences for the men and women on this card are anything but.

  6. http://abitotrade.com/
    Abitotrade e uma empresa profissional dedicada ao publico em Portugal, que disponibiliza um acompanhamento profissional a quem procura resultados, destacando-se por na transparencia e confianca. Conheca mais nesta pagina.

  7. LFA 233 in New York features some decent scrap potential, but the real story, it has a handful of odds that make me eager to pull the trigger.

  8. MichaelEvics MichaelEvics

    Нужен финаносвый план? https://financedirector.by/investicionnyj-biznes-plan-struktura-i-primer-dlja-investorov/ подробное объяснение структуры документа, его роли в привлечении инвесторов, получении кредита и запуске бизнеса. Узнайте, какие разделы включает бизнес-план, какие расчеты нужны и как он помогает оценить прибыльность проекта.

  9. We’re going to Salamanca in advance of LFA 233, and quite frankly, the bookmakers seem to be valuing home-region backstories over real strategic substance.

  10. Someone necessarily lend a hand to make critically posts I’d state. That is the first time I frequented your website page and thus far? I amazed with the research you made to create this particular post amazing. Magnificent process!

Deixe um comentário

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