Book Image

Internet of Things with the Arduino Yún

By : Marco Schwartz
Book Image

Internet of Things with the Arduino Yún

By: Marco Schwartz

Overview of this book

<p>Internet of Things (IoT) is currently a growing trend in the technology space, and the Arduino Yún is the perfect board to get started with building IoT projects. This book covers many of the powerful features of the Arduino Yún via four exciting projects. The first project is all about sending weather measurements data to a Google Docs spreadsheet for easy online visualization. The second one is about building an energy consumption meter and controlling devices remotely. The third focuses on the field of security, by helping you to build a camera that is triggered by motion and that uploads pictures automatically to Dropbox. Finally, the last project is in relation with the field of robotics, and focuses on building a robot that is controlled via Wi-Fi. <br /><br />The main focus of this book is to teach everything you need to know to build complex projects using the Arduino Yún, organized around the fields of home automation, security, and robotics.</p>
Table of Contents (11 chapters)

Testing your hardware connections


Now that all the connections are made, we can test the project. To get started, we will take care of the motion sensor. For this, we will write a very simple sketch that will only make use of the embedded Atmel microcontroller on the Yún board. We first need to declare the pin that the sensor is connected to, as follows:

const int sensor_pin = 8;

Then, in the setup() function, we will start the Serial connection, as follows:

Serial.begin(9600);
delay(1000);

We can also set some delay before data is read from the sensor, as it needs some time to initialize and work correctly. In the loop() function, we continuously read the value from pin number 8. Remember that the sensor will simply return a logical high state if some motion is detected and a low state otherwise. This means that we can store the sensor's reading into a Boolean variable, as shown in the following line of code:

boolean sensor_value = digitalRead(sensor_pin);

Every second, this value is then printed...