http://buildbot.com.br/blog/como-utilizar-o-sensor-ultrasonico-hc-sr04/
http://arduinobasics.blogspot.com.br/2012/11/arduinobasics-hc-sr04-ultrasonic-sensor.html
Lista de Materiais:
IDE Arduino 1.0.6
1x Board Arduino UNO
1x Protoboard 830 furos
1x Cabo USB-A male to USB-B male
1x Conj. de fios jumper p/ protoboard
1x Sensor ultrasônico HC-SR04
Montagem:
#include <Ultrasonic.h>
//*****************************************************************
float cmMsec, inMsec;
//*****************************************************************
#define PINO_TRG 4
#define PINO_ECHO 5//*****************************************************************
Ultrasonic ultrasonic(PINO_TRG, PINO_ECHO); //*****************************************************************
void setup(){
Serial.begin(9600); }
//*****************************************************************
void loop(){
long microsec = ultrasonic.timing(); cmMsec = ultrasonic.convert(microsec, Ultrasonic::CM);
inMsec = ultrasonic.convert(microsec, Ultrasonic::IN);
Serial.print("Centimetros: ");
Serial.print(cmMsec);
Serial.print(" - Polegadas: ");
Serial.println(inMsec);
delay(1000);
}
//*****************************************************************
Download: Ultrasonic.h
Nenhum comentário:
Postar um comentário