Ultrasonic Distance Sensor - HC SR04

  • Ultrasonic capteur Distance - HC SR04
Below you can see the corresponding code :
An example of a project for Distance Sensor
/*
Author: Danny van den Brande, Arduinosensors.nl. BlueCore Tech.
This code is made for the HC-SR04 Ultrasonic sensor.
*/
#include <LiquidCrystal.h> 
//#include <LiquidCrystal_I2C.h>//uncomment when using a I2C

//LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);// Uncomment when using a I2C
//make sure you set the right adress. here are the most common ones.
//PCF8574 = 0x20, PCF8574A = 0x38, PCF8574AT = 0x3F.

LiquidCrystal lcd(12, 11, 5, 4, 3, 2); 

int trig = 8; 
int echo = 9; 

void setup() 
{  
  pinMode(trig, OUTPUT);
  pinMode(echo, INPUT);
  Serial.begin(9600);
  lcd.begin(16,2); 
  lcd.setCursor(0,0);  
  lcd.print("Afstand in cm:");
}

void loop() {
  long duration, distance;
  digitalWrite(trig, LOW);
  delayMicroseconds(2);
  digitalWrite(trig, HIGH);
  delayMicroseconds(10);
  digitalWrite(trig, LOW);
  duration = pulseIn(echo, HIGH);
  distance = (duration/2) / 29.1;

  lcd.setCursor(0,1);  
  lcd.print("                "); 
//  Serial.print("                ");
  lcd.setCursor(0,1);   
  lcd.print(distance); 
  lcd.print(" cm");  
  Serial.print(distance);
  Serial.println(" cm");
  delay(250); 
}

Specifications
Operating voltage 5V.
Detection distance: 2cm – 500cm.
Effective angle: <15°.

Write a review

Please login or register to review

Ultrasonic capteur Distance - HC SR04

  • Webwinkel Keurmerk en klantebeoordelingen

  • 14 dagen bedenktijd 
  • Verzendkosten voor eigen rekening
  • Product Code: HC SR04
  • Availability: 38
  • 2.99€

  • Ex Tax: 2.47€

Similar Products

Rotary Encoder Module

Rotary Encoder Module

Below you can see the corresponding code: An example project for the Rotary encoder.  /* Autho..

2.29€ Ex Tax: 1.89€

NTC Waterproof Thermistor/ Temperature sensor

NTC Waterproof Thermistor/ Temperature sensor

Length 50 cm.Below you can see the corresponding code:An example of a project for the sensor./* Aut..

2.36€ Ex Tax: 1.95€

2 Color led module RG

2 Color led module RG

Below the corresponding code:// Arduino test code for KY011 int redpin = 11; // select the pin for ..

2.29€ Ex Tax: 1.89€

Temp and humidity Sensor

Temp and humidity Sensor

Below you can see the corresponding code: An example of a project for the DHT11/* Author: Danny va..

2.99€ Ex Tax: 2.47€

Tags: Ultrasonic Distance Sensor, HC SR04