Jump to content
Electronics-Lab.com Community

In the bowels of: Sonic Sensor


Recommended Posts

In the photography is the "Ultrasonic HC-SR04 distance measuring transducer sensor".

"HC-SR04 consists of ultrasonic transmitter, receiver, and control circuit. When triggered it sends out a series of 40KHz ultrasonic pulses and receives echo from an object. Power supply: 5V DC; quiescent current: less than 2mA; effectual angle: less than 15°; distance: 2cm - 500cm."  

The sensor is 1.75 inches/ 4.45 cm by 0.75 inches/ 1.9 cm. The IC on the bottom left is an LM324 quad op amp. The two on the right are not marked.





small 3650.JPG

// The sensor is triggered by a HIGH pulse of 10 or more microseconds. Give a short LOW pulse beforehand to ensure a clean HIGH pulse:

  • digitalWrite(iTrigPin, LOW); //pin 12 Out
  •  delayMicroseconds(5);
  • digitalWrite(iTrigPin, HIGH);
  • delayMicroseconds(12);
  • digitalWrite(iTrigPin, LOW);

   // Read the signal from the sensor: a HIGH pulse whose  duration is the time (in microseconds) from the sending  of the ping to the reception of its echo off of an object.

  • pinMode(iEchoPin, INPUT);   //pin 13 In
  • lDuration = pulseIn(iEchoPin, HIGH);

The photography shows the trigger pulse in blue and the signal from the sensor in yellow bracketed by the white cursors. In the lower right is the width of the pulse: 24.4 ms from a object at 16 inches/ 40.6 cm from the sensor.






small F3638.JPG

// Convert the time into a distance - long way for clarity

  • lCM = (lDuration/2) / 29.1;     // Divide by 29.1 or multiply by 0.0343
  • lInches = (lDuration/2) / 74;   // Divide by 74 or multiply by 0.0135

So for 2440 us/2 = 1220/74 = 16.48 inches  or 1220/29.1 = 41.9 cm


Link to comment
Share on other sites

An experimental blind spot monitoring (BSM) for an automobile. One can attach the sonic sensor on the rear
section of the automobile. I mounted mine on the flap door that covers the gasoline cap. I used a length of
good duct tape that wrap around the inside of the flap door also.

I ran a length of 4 wire telephone cable from the sensor through the backdoor gap into the backseat. Then a
length of 2 conductor wire from the Arduino Uno to the dash for a white LED. The LED has an 68 ohm resistor in
series with it. The LED and resistor lives in the plastic tube

For the Arduino Unio one can control the LED blinking without using the Delay() by:

  • int iLEDstate = LOW;               // used to set the LED state
    const long lInterval = 1000;       // interval at which to blink (milliseconds)
    unsigned long lPreviousMillis = 0; // will store last time LED was updated
    int iDashLED = 10;    		   // LED on/off pin
    pinMode(iDashLED, OUTPUT);
    //only distances more than 3 ft and less than 12 ft
    if(lInches > 36 && lInches < 144 ) 
        Dash_LED_Blink();  //blink the LED
    else if (iLEDstate == HIGH) 
        iLEDstate == LOW;
        digitalWrite(iDashLED, iLEDstate); //make sure LED is off
    void Dash_LED_Blink()
      // check to see if it's time to blink the LED
       unsigned long lCurrentMillis = millis();
      if (lCurrentMillis - lPreviousMillis >= lInterval) 
        // save the last time the LED blinked
        lPreviousMillis = lCurrentMillis;
        // if the LED is off turn it on and vice-versa
        if (iLEDstate == LOW) 
          iLEDstate = HIGH;
          iLEDstate = LOW;
        // set the LED with the iLEDstate 
        digitalWrite(iDashLED, iLEDstate);



Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...