Ultrasound Ranging Sensor module

Dependents:   Obstacle_avoidance servourfmatlab hcsr04 DistanceOnSevenSegLed ... more

You are viewing an older revision! See the latest version

Homepage

Table of Contents

  1. HCSR04

HCSR04

You can find the details of the sensor at http://www.micropik.com/PDF/HCSR04.pdf

include the mbed library with this snippet

#include "mbed.h"
#include "hcsr04.h"
#include "TextLCD.h"

DigitalOut myled(LED1);
HCSR04  usensor(p25,p6);
TextLCD lcd(p14, p16, p17, p18, p19, p20,TextLCD::LCD16x2); // rs, e, d4-d7
unsigned int dist;
int main()
{
    unsigned char count=0;
    while(1) {
        usensor.start();
        wait_ms(500); 
        dist=usensor.get_dist_cm();
        lcd.cls();
        lcd.locate(0,0);
        lcd.printf("cm:%ld",dist );
 
        count++;
        lcd.locate(0,1);
        lcd.printf("Distance =%d",count);
        
    }
}


All wikipages