Book Image

Raspberry Pi Home Automation with Arduino

By : Andrew K. Dennis
Book Image

Raspberry Pi Home Automation with Arduino

By: Andrew K. Dennis

Overview of this book

<p>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.</p> <p>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.</p> <p>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.</p>
Table of Contents (17 chapters)
Raspberry Pi Home Automation with Arduino
Credits
About the Author
Acknowledgement
About the Reviewer
www.PacktPub.com
Preface
3
Getting Started Part 2 – Setting up Your Raspberry Pi to Arduino Bridge Shield
Index

Setting up our software


Let's start with writing a simple program that opens and closes a relay connected to the Raspberry Pi. Once we have confirmed this works we can then modify the application we wrote in the previous chapter to switch the relays on and off and construct a URL to post the data to the web.

A program to test the relay

Load up Geany and add the following program to a file called Relay.cpp in the same directory as your arduPi library:

//Include ArduPi library
#include "arduPi.h"

//Needed for Serial communication
SerialPi Serial;

//Needed for accesing GPIO (pinMode, digitalWrite, digitalRead, I2C functions)
WirePi Wire;

//Needed for SPI
SPIPi SPI;
/*********************************************************
 *  IF YOUR ARDUINO CODE HAS OTHER FUNCTIONS APART FROM  *
 *  setup() AND loop() YOU MUST DECLARE THEM HERE        *
 * *******************************************************/

/**************************
 * YOUR ARDUINO CODE HERE *
 * ************************/

int main...