Raspberry Pi

Code Generator

Raspberry Pi - ULTRASONIC

The HC-SR04 Ultrasonic Sensor is a very affordable proximity/distance sensor that has been used mainly for object avoidance in various robotics projects . It essentially gives your Raspberry Pi eyes / spacial awareness and can prevent your robot from crashing or falling off a table. It has also been used in turret applications, water level sensing, and even as a parking sensor. This simple project will use the HC-SR04 sensor with Raspberry Pi and a Processing sketch to provide a neat little interactive display on your computer screen.

Hardware Required

- Raspberry Pi

- ULTRASONIC Sensor

- 330 Ohm Resistor

- 470 Ohm Resistor

Circuit

Code - Blocks

Code - Python

Create new python file Ultrasonic.py and enter following code. To run the code, open the terminal and go to directory where you code is located and enter the command " sudo python Ultrasonic.py " and hit enter.