Preface

Raspberry Pi is a single-board, credit-card-sized, computer packed with many opportunities to explore and invent. It is really amazing to see kids start coding Python from scratch, and build a bird box that streams live video on the Internet to check whether a bird has got its meal. I remember that when I was a kid, I used to play with Lego toys attached to DC motors and batteries, which was engaging. At that time, I could not imagine the logic that went into coding, and did not get any chance to code my projects and control the movement of those Lego blocks using a mobile phone. But I am lucky enough now to get an opportunity to explain such projects and provide a launchpad for young creators who really have a passion to create something and change the world around us.

The world is moving towards a new era. Technology is revolutionizing daily needs and habits and making them available on a simple interface, which gave me motivation to write a book on Raspberry Pi sensors. It's a world of creativity, and the I believe that creativity comes when you start understanding and appreciating the fundamentals and start applying logic to it. A lot of information and projects on Raspberry Pi are floating on various webpages, and one wishes to achieve as much as he/she can. I feel that the information on webpages is often observed as incomplete. It gives us a quick start to build projects but does not explain what is behind them.

It is known that without actually diving too deep into electronic devices and communication protocols, you can start coding on Raspberry Pi and craft amazing projects. I have colleagues around me who often need to code and wire the sensors on the Raspberry Pi platform for their experiments. They can develop Python code on artificial neural networks in a short span of time, but when it comes to wiring something, they look around. I believe that a basic understanding of electronics is a plus for such prodigies out there, who want to develop code on such platforms. In the opposite scenario, hardware developers can wire sensors, ensures proper voltage levels on device pins, but when it is time to code, they need help.

The most interesting thing that I find with the Raspberry Pi is that I can still play with the hardware components and soldering iron, and code my hardware to make it live. This book provides a kick start for such creators, who really want to know how things work together, and want a direction for starting projects on sensor interfacing and the Internet of Things with Raspberry Pi. There is tremendous growth in technology when we look towards the connected array of everything around us.

Internet of Things opens up a new world for collecting data and analyzing it for better user experience. A lot of data from the array of sensors has been generated from several different sensor nodes. In this context, the Raspberry Pi provides us with the opportunity to start with simple projects, such as uploading data to the Internet from a developed sensor station, as described in the chapters of this book. This will be your first step to building an Internet of Things project. Another interesting thing is that with the rise of Raspberry Pi 2 model B, developers have got enough processing power to perform computation-intensive algorithms on the Raspberry Pi. Therefore, image processing has been included in one of the chapters. It would have been very difficult to try to explain image processing to beginners, but I have at least tried to offer a simple start for readers so that they begin image processing on their own.

This book explores five different projects, any of which can be a startup for different ways of building electronics projects. The approach I have followed while preparing the projects is quite interesting. This is the methodology I often follow to develop complex hardware designs. Although I do not rely on breadboards (as I am more into high-speed circuit designs), small project prototypes, some of which are covered in this book, can easily be wired on breadboards. The first approach should be to purchase the best hardware components (preferably through hole for breadboard testing), on which you can rely when the code is not working or not giving the proper results. Prepare a block diagram and consider each issue that may occur during hardware and firmware design. Second, read datasheets of components used and ensure every single entity meets the design requirements. Thirdly, wire the components to the breadboard and check it thoroughly. Finally, when the hardware is built robustly, write the code (or firmware), and rewrite it to make it more perfect. Remove the unnecessary variables and unreachable code or loops, handle interrupts, define the sleep time and watchdogs of a processor, and manage proper memory segments to avoid crashes. However, this book has followed mostly simple code that does not go that deep into managing embedded programming. Installing useful coding libraries on the Raspberry Pi takes care of the faults often created by a programmer. Just call a function and it does all the embedded calls in the background. Thanks to the developers of the Raspberry Pi libraries, with which we build more robust code (whether knowingly or unknowingly). When you prepare a sample of code, I advise you to break it down into pieces.

You may face some difficulty when building the project for getting data from temperature, humidity and light sensors. First, get it done for temperature and humidity, and then code for the light sensor. Whenever both pieces of code give you the desired values, recode them. Then you can combine them by managing the function calls.

When writing the chapters, I have followed a common theme across the book: first the setup, then the purpose of the project, and finally describing the hardware with complete details. In some of the chapters, the software has been divided into components, and then they have been merged so as to avoid monotony for you. I apologize to you for being lengthy in the theory portion in some parts of this book, but I am sure that you will love to read and learn a lot from it, and you can get the most out of it.

Any questions, improvements, and suggestions are welcome, and should probably take place in the GitHub issues for the book at https://github.com/rushigajjar/raspberrypisensors so that everybody can take part. Besides that, anybody can contact me on LinkedIn at https://in.linkedin.com/in/rushigajjar, and send messages regarding their interesting projects and startups. I would really love to hear about it. Or you can send tweets by sharing temperature and luminance values at @rushigajjar once you get your air conditioner and lights automated!

What this book covers

Chapter 1, Meeting Your Buddy – the Raspberry Pi, gives an introduction to all the models of Raspberry Pi available in the market, including the recent Raspberry Pi 2 model B. A method of installing the operating system and interesting ways to share the Internet with the Raspberry Pi are discussed. Then we perform some hands-on coding in Linux terminal, Linux shell scripting, Python, and C on the Raspberry Pi.

Chapter 2, Meeting the World of Electronics, explains the fundamentals of electronics and communication protocols by which electronic devices communicate. Experiments with GPIO are more interesting to perform with the shell, Python, and C languages.

Chapter 3, Measuring Distance Using Ultrasonic Sensors, shows you how to set up an ultrasonic sensor with the Raspberry Pi and learn to take care of different voltage levels across the devices. We prepare a code to get our ultrasonic sensor running, and develop an aid for a visually impaired person with an obstacle avoidance system.

Chapter 4, Monitoring the Atmosphere Using Sensors, develops your skills in choosing a sensor from many that are available in the market. We then implement the hardware and software required for temperature, humidity, and light sensors to automate our home appliances.

Chapter 5, Using an ADC to Interface any Analog Sensor with the Raspberry Pi, explains interfacing of analog-to-digital convertors with an array of sensors. We build a sensor station for the Raspberry Pi using serial protocols to use the generic software function built, to get data from any sensor interfaced with it. Finally, the data can be stored in a log file for analysis.

Chapter 6, Uploading Data Online – Spreadsheets, Mobile, and E-mails, takes a dive into the Internet of Things and sensor nodes. With the help of the sensor station developed in the previous chapter, we upload the data to online spreadsheets and observe a real-time graph. We also get emergency e-mails on our e-mail platforms. Once you get your project done, you can send your sensor values to .

Chapter 7, Creating an Image Sensor Using a Camera and OpenCV, covers the basics of image processing and how an installation of the OpenCV library can be performed successfully. Using a camera, we will develop an IP camera to install in your backyard to observe live streaming of activities. Further, we will build a piece of motion detection code in OpenCV to detect human movement in a particular area and capture an image for an immediate alert.

Appendix, Shopping List, includes the list of the hardware components that need to be purchased in order to perform the hands-on tasks described in the book. From chapter 2 onwards, these components will be required to test our codes. You can directly take this list to the electronics distributors near you and come home with a filled shopping bag!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.221.136