Description:
This is the HC-SR04 ultrasonic ranging sensor. This economical sensor provides 2cm to 400cm of non-contact measurement functionality with a ranging accuracy that can reach up to 3mm. Each HC-SR04 module includes an ultrasonic transmitter, a receiver and a control circuit.
There are only four pins that you need to worry about on the HC-SR04: VCC (Power), Trig (Trigger), Echo (Receive), and GND (Ground). You will find this sensor very easy to set up and use for your next range-finding project!
شرح :
Features:
Documents:
Mikroelectron Code:
/*
Mikroelectron coding center
by Eng.Mahmoud Sukker
*/
#define echoPin 7 // Echo Pin
#define trigPin 8 // Trigger Pin
#define LEDPin 13 // Onboard LED
long durationdistance; // Duration used to calculate distance
void setup() {
Serial.begin (9600);
pinMode(trigPinOUTPUT);
pinMode(echoPinINPUT);
pinMode(LEDPinOUTPUT);
}
void loop() {
digitalWrite(trigPinLOW);
delayMicroseconds(2);
digitalWrite(trigPinHIGH);
delayMicroseconds(10);
digitalWrite(trigPinLOW);
duration = pulseIn(echoPinHIGH);
//Calculate the distance (in cm) based on the speed of sound.
distance = duration / 58.2;
Serial.println(distance);
if (distance < 10)digitalWrite(LEDPinHIGH);
else digitalWrite(LEDPinLOW);
delay(500);
//Delay 500ms before next reading.
}
|
Quantity |
---|---|
In stock
|