Book Image

Raspberry Pi Home Automation with Arduino - Second Edition

By : Andrew K. Dennis
Book Image

Raspberry Pi Home Automation with Arduino - Second Edition

By: Andrew K. Dennis

Overview of this book

Table of Contents (16 chapters)
Raspberry Pi Home Automation with Arduino Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
4
Temperature Storage – Setting Up a Database to Store Your Results
Index

Testing the photoresistor with software


We will be using the arduPi template we installed earlier to create our test code.

Take a copy of arduPi_template.cpp and rename it as LightSensor.cpp.

Next, in a text editor of your choice, open the new file and add the following code to it:

//Include ArduPi library
#include "arduPi.h"
//Include the Math library 
#include <math.h>

#define TH 690

Here, we had the standard template header, but we also added a new constant called TH. This will represent the threshold. Like the setpoint constant we declared for the thermostat, the threshold is used to decide to perform an operation based upon whether the room gets lighter or darker.

Let's move on to add the next block of code. Paste this block after the previous code you added to your file:

/*********************************************************
 *  IF YOUR ARDUINO CODE HAS OTHER FUNCTIONS APART FROM  *
 *  setup() AND loop() YOU MUST DECLARE THEM HERE        *
 * ********************************...