Book Image

Arduino Home Automation Projects

By : Marco Schwartz
Book Image

Arduino Home Automation Projects

By: Marco Schwartz

Overview of this book

Table of Contents (14 chapters)
Arduino Home Automation Projects
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Testing the project


We can now write a simple test for the project, just to see if the hardware connections are correct. We are going to write the code inside the Arduino IDE. Note that this section explains the code for testing the project, and that can you find the complete code in the GitHub repository of the project.

The code starts by defining the pin of the current sensor:

#define CURRENT_SENSOR A0

We then define the different variables that are necessary for the test. Here, we are going to measure the current and the power. Note that we don't measure the voltage of the device, so you will have to define it yourself depending on your country:

float amplitude_current;
float effective_value;
float effective_voltage = 230; // Set voltage to 230V (Europe) or 110V (US)
float effective_power;
float zero_sensor;

Then, in the setup() function of the sketch, we need to get the zero value of the sensor. As we have an analog sensor, we need to know what the sensor is reading when no current is flowing...