Introduction

Welcome!

Hi there. Congratulations on being interested enough in the process of learning about measuring distance using ultrasonic audio with the Raspberry Pi to have gotten your hands on this book.

Hopefully this will be a journey of discovery for both of us. The goal is to experiment with computers and use them to know a bit more about what is happening in the physical environment. This sort of thing has been done already by others, but I have an ulterior motive. I write books to learn and document what I’ve done. The hope is that by sharing the journey perhaps others can learn something from my efforts :-).

Ambitious? Maybe :-). But if you’re reading this, I managed to make some headway. I dare say that like other books I have written (or are in the process of writing) it will remain a work in progress. They are living documents, open to feedback, comment, expansion, change and improvement. Please feel free to provide your thoughts on ways that I can improve things. Your input would be much appreciated.

You will find that I have typically eschewed a simple “Do this approach” for more of a story telling exercise. This means that some explanations are longer and more flowery than might be to everyone’s liking, but there you go, that’s my way :-).

There’s a lot of information in the book. There’s a vast amount of ‘stuff’ that people with even a passing interest in computing will find excessive. Sorry about that. I’ve deliberately gathered together a lot of the content from other books I’ve written to create a guide that is as full of usable information as possible to help people who could conceivably be using the Pi and coding for the first time. This is ONE fairly simple project that might otherwise be described in 5 pages stretched out into a lot more. But I’m working on the principle that if I need to recreate what I have here from scratch, this guide will leave nothing out. It will also form a basis for other similarly explained books (as books before this one have done). Evolving the description as the OS versions and Raspberry Pi’s are updated.

I’m sure most authors try to be as accessible as possible. I’d like to do the same, but be warned… There’s a good chance that if you ask me a technical question I may not know the answer. So please be gentle with your emails :-).

Email: d3noobmail+ultra@gmail.com

Cover photo via Good Free Photos and Acer220.

What are we trying to do?

Put simply, we are going to examine the wonder that is the Raspberry Pi computer and use it to accomplish something.

In this specific case we will be connecting an ultrasonic module to the Pi, measuring the values that it returns, recording them in a database and then making those values available via web interface!

Along the way we’ll;

  • Look at the Raspberry Pi and its history.
  • Work out how to get software loaded onto the Pi.
  • Learn about networking and configure the Pi accordingly.
  • Install and configure a web server and a database.
  • Write some code to interface with our ultrasonic module.

Who is this book for?

You!

Just by virtue of taking an interest and getting hold of a copy of this book you have demonstrated a desire to learn, to explore and to challenge yourself. That’s the most important criteria you will want to have when trying something new. Your experience level will come second place to a desire to learn.

Having said that, it may be useful to be comfortable using the Windows operating system (I’ll be using Windows 7 for the set-up of the devices), you should be aware of Linux as an alternative operating system, but you needn’t have tried it before. The best thing to remember is that before you learn anything new, it pretty much always appears indistinguishable from magic, but once you start having a play, the mystery quickly falls away.

What will we need?

Well, you could just read the book and learn a bit. By itself that’s not a bad thing, but trust me when I say that actually experimenting with physical computers is fun and rewarding.

The list below is pretty flexible in most cases and will depend on how you want to measure the distances.

  • A Raspberry Pi (I’m using a Raspberry Pi Model B 2 / 3)
  • Probably a case for the Pi
  • A MicroSD card
  • A power supply for the Pi
  • A keyboard and monitor that you can plug into the Pi (there are a few options here, read on for details)
  • A remote computer (like your normal desktop PC that you can use to talk to connect to the Pi). This isn’t strictly necessary, but it makes the experience way cooler.
  • A JSN-SR04T Ultrasonic Module. They are available from lots of places for around $10 US. Google is your friend. There is a version 2.0 of the module. I have not used this.
  • A 1k and 2k Ohm resisters with some soldering equipment
  • Some dupont connectors (that’s what I used, but you could connect to the Pi in different ways)
  • An Internet connection for getting and updating the software.

As we work through the book we will be covering off the different parts required and you should get a good overview of what your options are in different circumstances.

Why on earth did I write this rambling tome?

That’s a really good question. This is a project that I use in the real world (to measure the height of the water in my water tank). Over the years of owning a house with a water tank I have had several instances where (for a range of reasons) the tank has emptied and I didn’t realise (and even once where the tank over filled!). I generated a previous book on multiple temperature measurements and that was an enjoyable process, so I thought that I’d repeat it and perhaps continue to adapt the book for subsequent projects by simply adapting whatever the proceeding one was. Will this work? Who knows.

What I can tell you is that I now have a way of measuring the height of the water in my water tank and you have a book that tells you how I did it :-).

Included is a bunch of information from my books on the Raspberry Pi, Linux and d3.js. I hope you find it useful.

Where can I get more information?

The Raspberry Pi as a concept has provided an extensible and practical framework for introducing people to the wonders of computing in the real world. At the same time there has been a boom of information available for people to use them. The following is a far from exhaustive list of sources, but from my own experience it represents a useful subset of knowledge.

raspberrypi.org

Google+

reddit

Raspberry Pi Stack Exchange