Raspberry Pi Home Automation with Arduino

1 (1 reviews total)
By Andrew K. Dennis
  • Instant online access to over 8,000+ books and videos
  • Constantly updated with 100+ new titles each month
  • Breadth and depth in over 1,000+ technologies
  1. An Introduction to the Raspberry Pi, Arduino, and Home Automation

About this book

Low-cost and high-performing, with a massively diverse range of uses and applications, the Raspberry Pi is set to revolutionize the way we think about computing and programming. By combining the Raspberry Pi with an Arduino board you'll be able to revolutionize the way you interact with your home and become part of a rapidly growing group of hobbyists and enthusiasts.

This essential reference will guide you through a series of exciting projects that will allow you to automate your very own home. With easy-to-follow, step-by-step examples, diagrams, and explanations you will not only find it incredibly productive but also highly engaging and informative.

Assuming no prior knowledge, our detailed practical examples will guide you through building hardware and software solutions using the Raspberry Pi and Arduino. You will learn how you can use thermistors and relays to keep cool and stay in the shade whilst also utilizing electrical motors and photoresistors. These meticulously designed tutorials will form the basis of automating your entire home and getting you started with dozens of potential projects.

Publication date:
February 2013
Publisher
Packt
Pages
176
ISBN
9781849695862

 

Chapter 1. An Introduction to the Raspberry Pi, Arduino, and Home Automation

This chapter provides an introduction to the Raspberry Pi, Arduino, and the subject of home automation.

We'll look at the history of the Raspberry Pi and how it came to be, as well as the Arduino platform – an open source microcontroller that provides developers with a means to interact with their surroundings, through a variety of sensors and motors.

Finally, we will wrap up the chapter by covering home automation and how technologies such as the Raspberry Pi have put the ability to build complex sensor based systems in the hands of the open source community.

Let's start by looking at what we will be covering in the coming chapters.

 

What we will explore in this book


We have a number of exciting projects ahead that will slowly introduce you to home automation via the technologies of the Raspberry Pi and Arduino. These projects include:

  • Writing software to control hardware

  • Building a thermometer using a thermistor

  • Turning the thermometer into a thermostat using relays

  • Controlling electric motors using a motor shield

  • Writing software for storing sensor data generated by your projects

By completing each chapter in the book, you will gain a basic knowledge of building circuits and hardware for home automation projects. You will learn about writing software to both control your projects and record the data generated by them. Finally, we will look towards future projects you can build with your new skills.

Our next step is to learn a little about the background of the technologies we are going to be using. We will start with the Raspberry Pi.

 

History and background of the Raspberry Pi


From the first vacuum tube computers, to the tape and punch card machines of the '60s, and the first microprocessor mainframes of the '70s, computing had very much been the preserve of large businesses and university research departments. However, by the late '70s, with the release of the Apple II and earlier seeds planted by such technology as the TV Typewriter and Apple I, this was rapidly changing.

As the '80s rolled into view, the public saw low-cost home computers such as the ZX Spectrum and Commodore 64 hit the mass market and subsequently give birth to a whole generation of amateur programmers. By the '90s, these programmers, brought up on tinkering with their home computers and writing BASIC, were heading into academia and the computer industry, and helping to forge the dot.com boom with game, web, open source, and business technologies.

The genesis of the Raspberry Pi is in many ways linked to this. A group of computer scientists lead by Eben Upton at the University of Cambridge's Computer Laboratory in 2006 struck upon the idea of producing a cheap educational micro-computer geared towards the amateur computer enthusiast, budding students, and children. The aim was to help to provide the skills to future Computer Science undergraduate applicants that many of those applying in the '90s possessed, thanks to the home computers of the '80s.

However it would be another two years before the project became viable, and not until 2012 before the Raspberry Pi was being shipped out to the public.

The 2000s saw a huge growth in mobile computing technologies, a large segment of this being driven by the mobile phone industry. By 2005, ARM – a British manufacturer of CPU core components and a by-product of the '80s home computer company Acorn, had grown to where 98 percent of mobile phones were using their technology. This translated into around 1 billion CPU cores. ARM technology would later end up being featured on the Raspberry Pi with the ARM ARM1176JZF-S processor core being used.

During the same period, Ebon Upton designed several concepts for the Raspberry Pi and by 2008, thanks to a by-product of the increasing penetration of mobile phone technology, the cost of building a miniature, portable microcomputer with many of the multimedia functions that the public were accustomed to was becoming viable.

Thus the Raspberry Pi foundation was formed and set about the task of developing and manufacturing the Raspberry Pi computer.

By 2011, the first Alpha models were being produced and tested, and the public finally got to see what the Raspberry Pi was capable of.

Demos of Quake III Arena and full HD/1080p video showed that the tiny computer could pack a big punch for low cost.

Finally in 2012, the Raspberry Pi was ready for public consumption. Two versions of the Raspberry Pi were scheduled to be manufactured, namely models A and B, with B being released first.

The model A board which will not include an Ethernet port and will consume considerably less power than the model B was given a price tag of $25.

The model B that includes an Ethernet port was given a target price of $35 USD and manufacturing in China started. This would later be moved to the UK with Sony taking over the process.

After several setbacks, including the wrong Ethernet port being attached to the early batches and several compliance regulations having to be passed, the Raspberry Pi was making its way into the hands of tech enthusiasts across the globe to a great reception.

So what exactly does the Raspberry Pi Model B you're holding include?

Raspberry Pi hardware specifications

We will briefly go over some of the core components that make up the Raspberry Pi to give you a better feel for what it is capable of.

The Raspberry Pi is built off the back of the Broadcom BCM2835. The BCM2835 is a multimedia application processor geared towards mobile and embedded devices.

On top of this, several other components have been included to support USB, RCA, and SD card storage.

We will now look at some of the core-components of the Raspberry Pi board. The following figure highlights some of these with a description of each provided:

Dimensions

The Raspberry Pi is a small device coming in at 85.60mm x 53.98mm x 17mm and weighing only 45g. This makes it perfect for home automation, where a small device can be placed in a case and mounted inside an electrical box, or replace an existing thermostat device on a wall.

3.5mm analog audio jack

The 3.5mm analog audio jack allows you to connect headphones and speakers to the Raspberry Pi. This is especially useful for audio and media player based projects.

Composite RCA port

You are probably familiar with the composite cables used to hook up your DVD player to the TV. They usually come in the red, white, and yellow plug variety. The Raspberry Pi has a port for attaching the yellow video cable from your TV to it, allowing you to use your TV as a monitor.

Two USB 2.0 ports plus one micro USB

USB is one of the most common methods for connecting peripherals and storage devices to a computer. The Raspberry Pi comes equipped with two of them, allowing you to hook up a keyboard and mouse when you get started and a micro USB port for powering your device.

HDMI port

The High Definition Multi-media Interface (HDMI) port allows the Raspberry Pi to be hooked up to high-definition televisions and monitors that support the technology. This provides an additional option to the composite RCA port for video and additionally supports audio.

Should you wish to stream video and audio from the web to your TV, this is the port you would want to use.

SD card port

The main storage mechanism of the Raspberry Pi is via the SD card port. The SD card will be where we install our operating system and will act as our basic hard disk. Of course, this storage can be expanded upon using the USB ports.

256 MB/512 MB SDRAM shared with GPU

The Raspberry Pi comes equipped with 256 MB of SDRAM on older versions of the model B and 512 MB on the newer revisions. This isn't a huge amount, and much less than you would expect on a PC, where RAM is available in gigabytes. However, for the type of applications we will be building, 256 MB or 512 MB of RAM will be more than enough.

CPU

Early in this chapter we touched upon ARM – the British manufacturers of central processor unit (CPU) cores. The Raspberry Pi comes equipped with a 700 MHz, ARM1176JZF-S core – part of the ARM 11 32-bit multi-processor core family.

The CPU is the main component of the Raspberry Pi, responsible for carrying out the instructions of a computer program via mathematical and logical operations.

The Raspberry Pi is in good company using the ARM 11 series and has joined the ranks of the iPhone, Amazon Kindle, and Samsung Galaxy.

GPU

The graphics-processing unit (GPU) is a specialized chip designed to speed up the manipulation of image calculations.

In the case of our Raspberry Pi, it comes equipped with a Broadcom VideoCore IV capable of hardware accelerated playback and support for OpenGL.

This is especially useful if you want to run games or video via your Raspberry Pi, or work on 3D graphics in an open source application such as Blender.

Ethernet port

The Ethernet port is the Raspberry Pi's main gateway to communicating with other devices and the Internet. You will be able to use the Ethernet port to plug your Raspberry Pi into a home router such as the one you currently use to access the Internet, or a network switch if you have one set up.

GPIO pins

The General Purpose Input/Output (GPIO) pins on the Raspberry Pi are the main way of connecting with other electronic boards such as the Arduino.

As the name suggests, the GPIO pins can accept input and output commands and thus can be programmed on the Raspberry Pi.

The Arduino shields will be attached to the GPIO via a bridge shield allowing us to transfer data from sensors soldered to the device back to the Raspberry Pi. This is especially useful in home automation projects, where we may wish to store sensor data or manipulate motors based upon a program running on the Raspberry Pi's operating system.

Having touched upon the technical capabilities of the Raspberry Pi, we will now look at the Arduino and the Raspberry Pi to Arduino shield, a way to connect the two technologies via the GPIO pins.

 

History and background of Arduino


One of the most popular open source hardware products to have hit the market is the Arduino platform – a branch off of the earlier open-source Wiring platform. Developed in Italy by Massimo Banzi and David Cuartielles in 2005, Arduino is an open source hardware technology coupled with a programming language and an Integrated Development Environment (IDE).

The Arduino platform allows the user to create custom hardware and applications to control it via its namesake programming language.

Currently, there are several board models on the market ranging in size and components. For example, the Lilly Pad allows enthusiasts to attach an Arduino board to clothing for electronic textile-based projects. These boards support a wide range of "shields" – Arduino compatible electronic boards that can be plugged into it and expand its functionality. One particular extension has been the introduction of Ethernet shields and wireless Xbee devices to allow communication with home networks and the Web.

The benefit of the Arduino for amateur enthusiasts has been that little or no knowledge of how electronics are soldered together is required to use the pre-built shields. However, as the user becomes more comfortable with the technology, he/she can progress to building his/her own projects using the numerous kits and sensors available on the market.

This easy adoption has helped to contribute to the number of websites and books dedicated to home automation projects using the technology.

In this book, we will not be using one of the Arduino microcontroller boards, the Raspberry Pi will fulfill this role. However we will be using the Raspberry Pi to Arduino shield. This will allow us to connect shields and other components to the Raspberry Pi and control them via the Arduino programming language.

Raspberry Pi to Arduino shield connection bridge

For our project, the particular Raspberry Pi to Arduino shield we will be using is produced by Cooking Hacks, an offshoot of the Libelium wireless communications company based in Spain.

Their website can be found at http://www.cooking-hacks.com.

The Cooking Hacks shield is connected to the Raspberry Pi's GPIO pins, and with the inclusion of the arduPi software, you will be able to communicate between your electronic devices, the Raspberry Pi's operating system, and web-based projects.

Let's take a quick look at the shield and its components.

Shield specifications

The Raspberry Pi to Arduino shield is a credit card sized electronics board that mimics an Arduino microcontroller in its layout. The Raspberry Pi connector is under the board, and the top of the board contains typical pins and connectors you would find on an Arduino board such as the Uno.

The following figure highlights some of the key components of interest and a description of each is also listed:

XBee socket

The two Xbee sockets on the shield provide support for Xbee wireless radio communication modules. Our Raspberry Pi comes equipped with an Ethernet port, so we will not need to use these for any of our home automation projects. If, however, you wish to switch out Ethernet for Xbee devices instead, these are the connectors you can use.

Power source selector

The power source selector is a small switch located on the side of the shield that can be used to enable an external power source.

UART

The Universal Asynchronous Receiver/Transmitter (UART) is the serial input and output port for your bridge shield and is marked with Rx and Tx. This can be used to transmit serial data, such as text and is useful for debugging code, for example.

Digital GPIO pins

The digital I/O pins provide a place where you can hook up other electronic components. For example, you can solder a temperature sensor to pin 2 and then, via the Arduino programming language, read the data transmitted from it.

Serial Peripheral Interface (SPI) pins

SPI pins can be used to connect a peripheral device to your Arduino shield. The SPI includes the SCK (Serial Clock), MISO (Master In Slave Out), and MOSI (Master Out Slave In) pins.

In Circuit Serial Programmer (ICSP) connector

The ICSP allows us to program the Arduino microcontroller. For our project, we will not need this, as the Raspberry Pi will be taking the place of the Arduino microcontroller.

Power pins

The power pins can be used when hooking up a device to the shield. For example, a device drawing power from the shield and writing data back to it will need to use one of the power options (5V or 3.3V) and also the grounding pin.

Analog inputs

The analog inputs can be used to hook up devices such as potentiometers (commonly found as twisting knobs for changing things such as volume), which send an analog signal to the shield.

This is the analog counterpart of the digital GPIO pins described earlier.

Raspberry Pi GPIO connector

The Raspberry Pi GPIO connector can be found on the bottom of the shield. This is where you will connect your Raspberry Pi to Arduino bridge shield to the Raspberry Pi's GPIO pins.

Soldering

Soldering is the process of attaching electronic components together using a heated metal filler (the solder), in order to allow the electrical current to flow between them.

At this point, it is worth mentioning that practicing some soldering before you start building the projects in this book is worth the effort, but not strictly necessary. If you are a novice, do not worry as there will be minimal soldering.

Also if you have any old PC hardware sitting around, like a graphics card no longer in use, you can practice un-soldering and re-soldering the components until you get comfortable with the process. These will also help you get used to handling the soldering iron and de-soldering tool.

Writing software for the Arduino

After you set up the Arduino shield and plug it into the Raspberry Pi, you will probably be wondering how to interact with it. After all, it has sensors and LEDs, but these are nothing without applications to control them in a meaningful manner.

Many software languages are available on the Raspberry Pi and we are interested in four. These are the Arduino programming language, Python, SQL, and HTSQL.

The Arduino programming language – a subset of C++ – provides us with a tool for programming Arduino compatible shields and the components connected to them. One benefit of using this technology is that there is a wealth of programs and libraries online that can be used for future projects. You will be using this language in the Geany IDE for writing the core applications that will be reading data from sensors attached to your projects.

The next language we will be using is Python. Python is a high-level programming language developed in the late '80s by Guido Van Rossum named after the popular comedy show Monty Python's Flying Circus.

This language allows you to build web and database applications that can be used to process the output of Arduino programs. We will be using Python to build a web application that can process data sent to it and then insert it via SQL (Structured Query Language) into an SQLite 3 database.

We will also use SQL for building the database that our Python script connects to. In conjunction with the SQLite database management system we will construct a repository for storing some of the results from our projects, for example, temperature data.

Finally we will also be using HTSQL (Hyper Text Structured Query Language) to provide a web interface to our database that is easy to query via the web browser.

HTSQL allows us to set up a server pointed to our database and then query it without having to write further server-side code.

Now that we have looked at our tools for building home automation systems, the Raspberry Pi and Arduino, lets look at what home automation is.

 

What home automation is


Having picked up this book, you may already have an idea of what home automation is, but just in case, we'll give you a quick overview of the subject and the open source technology that is driving many projects out there today.

Home automation is more than just a remote control for your TV! Examples include programming your DVR to record your favorite shows, setting the AC unit to come on when it reaches 76 degrees Fahrenheit, and installing a fancy alarm system that contacts the police in the instance of a break-in.

Also known as domotics (a portmanteau between domestic and informatics), home automation can be summed up as the mechanism of removing as much human interaction as technically possible and desirable in various domestic processes, and replacing them with programmed electronic systems—essentially the automation of the home and housework.

A history of home automation

Concepts for home and building automation were around for decades before becoming reality and featured in the writing of the 19th century sci-fi author HG Wells, comics, and cartoons such as the Jetsons. American industrialist George Westinghouse helped to pioneer the AC (Alternating Current) electrical system – which the X10 home automation standard would later run over – and in 1966, the company that bears his name, Westinghouse Electric, employed an engineer who developed what could arguably be called the first computerized home automation system – the ECHO IV.

The Electronic Computing Home Operator (ECHO) was featured in the April 1968 edition of Popular Mechanics and had been expanded from a set of spare electronics - both in the physical and literal sense, to include computing its founder Jim Sutherland's family household finances and storing their shopping lists, amongst an array of other tasks.

You can still read the original Popular Mechanics article online at Google books (http://books.google.com/books?id=AtQDAAAAMBAJ&pg=PA77&source=gbs_toc_r&cad=2#v=onepage&q&f=false).

The ECHO never went commercial and through the '60s, hobbyists and a number of large companies such as Honeywell toyed with the idea of computerizing the home, however it was the '70s, much as with personal computing, that saw the birth of the modern era of home automation technology.

X10 – a standard is born

The beginning of modern home automation technology can be argued to be found with the introduction of the X10 technology standard . Conceived in 1975 by Pico Electronics, who later partnered with Birmingham Sound Reproducers, X10 laid out the framework for allowing remote control access of domestic appliances. The X10 standard was designed to allow transmitters and receivers to work over existing electrical wiring systems by broadcasting messages such as "turn off" and "turn on" via radio frequency bursts.

Three years later in 1978, X10 products began to make their way into stores geared towards electronics enthusiasts and shortly after, in the '80s, the CP-290 computer interface made its way into the market for the Mattel Aquarius computer.

The CP-290 unit allowed computers to communicate with X10 compatible appliances in the home. Over the years, support for Windows and Mac has been included, and gave those interested in home automation the ability to program their lighting systems, thermostats, and garage doors from their home computers.

As revolutionary as X10 has been, it unfortunately had a number of flaws. These included:

  • Wiring and interference issues

  • Commands getting lost in transmission

  • Limited scope of products supporting X10

  • Limited scope of commands available

  • Slow speed of signal transmission

  • Lack of encryption

  • Lack of confirmation message without expensive two way devices

By the late '90s, home automation still hadn't penetrated the home market on a truly wide scale, however the technological advancements of the dot-com boom were providing a whole new set of tools, protocols, and standards that addressed many of the flaws that the X10 standard has been limited by.

The dot.com boom and open source – a new set of technologies

With the explosion of technologies that followed the birth of the web in the '90s, home computing and networking technologies were now available to the public and could easily and cheaply be installed at home. These technologies would later provide ideal candidates for pushing the boundaries of what could be achieved by home automation enthusiast, and provide the industry with the tools for building smart home appliances and systems.

It was only a small step from PC to PC communication to appliance to PC communication.

Home networks running on Ethernet and later WiFi provided a mechanism that could allow computers and electronic appliances to communicate with one another across a home without needing to use the existing electrical wiring. In the case of WiFi, no extra cabling was required.

As protocols such as FTP and HTTP became the norm for accessing information across the Internet, hardware developers saw the opportunity to leverage these communications technologies in open source hardware devices. Where as X10 appliances had no way of knowing if a signal had been successfully sent without the purchase of costly "two-way" devices, web technologies provide a whole framework for returning error codes and messages.

At approximately the same time as the Arduino platform we introduced earlier was being developed, the first tablet computers were beginning to be released. From 2005 until now, there has been an explosion in mobile, tablet, and smartphone devices. This growth has been commonly referenced to as the "post-PC" era.

These devices have provided mobile computing platforms that can run complex software and be small enough to fit in the user's pocket. As a result of this, applications have been developed for the iPhone and Android that allow the user to control consumer electronics such as the TV.

Due to their size, portability, and in some cases, low cost, they have provided the perfect platform for interfacing with home appliances and devices, and provided an extension to a medium the user is familiar with.

Along side the explosion in hardware, there was also an equivalent explosion in software. One particular product of interest that we will look at is the open source Android operating system.

The Android OS is a Linux-based operating system geared towards mobile devices. As part of the Open Handset Alliance – a consortium of 84 companies operating in the mobile sphere, Google backed and eventually purchased the Android mobile operating system.

The aim has been to create an open source operating system that can compete with companies such as Apple, and provide a robust system that can work across multiple manufacturer devices.

As a result of this, commercial manufacturers of home appliances have begun to embed the technology and software into their products, and a generation of "smart-devices" has started to appear in stores around the world.

Commercial products

If you are interested in a smart refrigerator that can tell you the weather and keep track of your groceries, or an oven that can be controlled via your smartphone, then you are in luck.

Products such as the Samsung RF4289HARS refrigerator running Android and the LG smart washing machine are paving the way for smart homes by embracing open source and web-based technologies.

It is also not just appliances that are getting the makeover. Thermostat systems such as the Nest – a company founded by ex-Apple employees-are re-thinking how smart thermostats work.

Barcodes and QR codes on products now allow the consumer to scan them with their smartphone and download information directly from the web providing details on the item. This can be extended to allow scanning and inventory management of products in the home, recording data such as consume – by dates of products in the refrigerator, and dynamically generating shopping lists.

This combination of hardware, software, and information now provides the potential for the home to become part of "an Internet of Things" to quote Kevin Ashton.

Thanks to the open source and open-standard technology being used in these devices, it is easy to combine home-brew projects built with the Raspberry Pi and commercial products by companies such as LG, to build a smart home that creates a network of devices that can communicate with one another to combine the execution of tasks.

As we mentioned, home-brew systems such as the Raspberry Pi can form part of this network; let's now look at the effects of the arrival of the Raspberry Pi on the world of home automation.

Arrival of the Raspberry Pi

With the arrival of the Raspberry Pi and the Raspberry Pi to Arduino shield, a set of open source technologies now exist that combine the power of the PC, the communication and multimedia technologies of the web, the ability to interact with the environment of a microcontroller, and the portability of a mobile device.

This provides the perfect set of factors allowing us to build cheap devices for our homes that can interface with commercial devices, but can be tailored for our own needs while also providing a great tool for learning about technology.

For those familiar with Arduino devices, the Raspberry Pi combined with its shields provide an all-in-one medium for creating devices without the need for a separate PC or Mac—giving us an alternative to solutions that currently exist.

Also, thanks to the Raspberry Pi's mission of providing an educational tool for those interested in programming, the addition of the Arduino shield will provide a mechanism for those who wish to move from writing software that manipulates the Raspberry Pi, to software that manipulates their environment and provides a pathway for learning about electronics. This could have the positive effect of bolstering the ranks of home-brew and Maker clubs with an eye towards home automation and lead to an ever-greater diversity of tools being produced for the public.

 

Summary


In this chapter, we have familiarized ourselves with the Raspberry Pi and Arduino. We have also looked at some of the existing technologies used in home automation and their history.

Where as Sutherland's ECHO IV filled a room in his house, the Raspberry Pi fills a space not much larger than a credit card.

Home automation now seems to be taking the next step to becoming widely adopted, and the Raspberry Pi neatly fits into this world by providing those who want to customize control of their devices with an easy and a cheap tool for achieving it, and by also expanding what can be done with Arduino technology currently out in the market place.

With this in mind, we will get started on our first project– setting up the Raspberry Pi.

About the Author

  • Andrew K. Dennis

    Andrew K. Dennis is the manager of professional services software development at Prometheus Research. Prometheus Research is a leading provider of integrated data management for research and is the home of HTSQL, an open source navigational query language for RDBMS.

    Andrew has a diploma in computing, a BSc in software engineering, and is currently studying for a second BSc in creative computing in his spare time.

    He has over 12 years of experience working in the software industry in the UK, Canada, and the USA. This experience includes e-learning courseware development, custom CMS and LMS development, SCORM consultancy, web development in a variety of languages, open source application development, blogging about the integration of web technologies with electronics for home automation, and punching lots of Cat5 cables.

    His interests include web development, e-learning, 3D printing, Linux, the Raspberry Pi and Arduino, open source projects, home automation and the use of web technology in this sphere, amateur electronics, home networking, and software engineering.

    Browse publications by this author

Latest Reviews

(1 reviews total)
Not received the ebook. Again have to give a star. My preference would be no star.
Book Title
Access this book and the full library for just $5/m.
Access now