Dear,
For a school project I am converting the analog signal from the HC-SR04 (Ultrasonic sensor) into a digital signal. This just doesn't work for me so I sought help.
The intention is that, for example, if the HC-SR04 indicates between 2 and 40 cm, there will be 5v on a pin. so that it can be used for further purposes.
See the Arduino Project and drawing below.
†
HC-SR04 Basic Demonstration
HC-SR04-Basic-Demo.ino
Demonstrates functions of HC-SR04 Ultrasonic Range Finder
Displays results on Serial Monitor
DroneBot Workshop 2017
http://dronebotworkshop.com
†
// This uses Serial Monitor to display Range Finder distance readings
// Hook up HC-SR04 with Trig to Arduino Pin 10, Echo to Arduino pin 13
#define trigPin 10
#define echoPin 13
float duration, distance;
void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
†
void loop() {
// Write a pulse to the HC-SR04 Trigger Pin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Measure the response from the HC-SR04 Echo Pin
duration = pulseIn(echoPin, HIGH);
// determine distance from duration
// Use 343 meters per second as speed of sound
distance = (duration / 2) * 0.0343;
// Send results to Serial Monitor
Serial.print("Distance = ");
if (distance >= 400 || distance <= 2) {
Serial.println("Out of range");
†
else {
serial.print(distance);
Serial.println(" cm");
delay(100);
†
delay(100);
†
Who can help me or at least give me tips
Thanks in advance,
Nick