Using Ultrasonic (HC SR-04) with Raspberry Pi

In this tutorial we will be Using Ultrasonic Sensor (SR-04) with Raspberry Pi –

Step 1 – Connections

  • Here we will be using GPIO24 as Trigger pin and GPIO25 as Echo pin.
  • For this, connections will be as shown –

  • We have to connect echo pin in a Voltage Divider, made by 330Ω and 470Ω as Shown.

Step 2 – Working on Code –

  • Create a new file in IDLE and write the code as given
  • The Code for the Following will be –

  • Now save this as python file as
  • Open terminal and type command sudo python and press Enter.
  • Now you will get Realtime reading by Ultrasonic Sensor on the terminal.

  • You can press Ctrl+C any time to stop the program.

Hope that you would have liked it. For any Querry, you can leave a comment below : – )




About the Author

Abhishek Thakur, Embedded Systems Enthusiast

Related Post

Submit a Review

Display Name