Book Image

Getting Started with Raspberry Pi Zero

By : Richard Grimmett
Book Image

Getting Started with Raspberry Pi Zero

By: Richard Grimmett

Overview of this book

Raspberry Pi Zero is half the size of Raspberry Pi A, only with twice the utility. At just three centimeters wide, it packs in every utility required for full-fledged computing tasks. This practical tutorial will help you quickly get up and running with Raspberry Pi Zero to control hardware and software and write simple programs and games. You will learn to build creative programs and exciting games with little or no programming experience. We cover all the features of Raspberry Pi Zero as you discover how to configure software and hardware, and control external devices. You will find out how to navigate your way in Raspbian, write simple Python scripts, and create simple DIY programs.
Table of Contents (16 chapters)
Getting Started with Raspberry Pi Zero
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Adding a sonar sensor


The basic circuit you just built is a wonderful start. Now you'll interface a more complex device, a sonar sensor, with Raspberry Pi Zero. Here is a picture of the sonar sensor that you'll add:

The device is an HC-SR04 and they are available at most online electronics retailers. Now let's connect the device to Raspberry Pi Zero. In order to do this, first let's look at the layout of the GPIO pins on Raspberry Pi Zero:

You'll need to connect to the 5 volt connection of the Raspberry Pi Zero, pin 2. You also need to connect to the GND, which is pin 6 on Raspberry Pi. Pin 16 (GPIO 23) is used as an output trigger pin and pin 18 (GPIO 24) as an input to time the echo from the sonar sensor.

Note

Don't connect 5 volts as an input to any of the GPIO pins as this might cause damage.

Now that you know the pins you have to connect to, you'll connect the sonar sensor. However, there is a problem, as you can't connect the 5-volt return from the sonar sensor directly to the Raspberry...