Reader small image

You're reading from  Internet of Things with Arduino Cookbook

Product typeBook
Published inSep 2016
PublisherPackt
ISBN-139781785286582
Edition1st Edition
Tools
Concepts
Right arrow
Author (1)
Marco Schwartz
Marco Schwartz
author image
Marco Schwartz

Marco Schwartz is an electrical engineer, entrepreneur, and blogger. He has a master's degree in electrical engineering and computer science from Supélec, France, and a master's degree in micro engineering from the Ecole Polytechnique Fédérale de Lausanne (EPFL), Switzerland. He has more than five years' experience working in the domain of electrical engineering. Marco's interests center around electronics, home automation, the Arduino and Raspberry Pi platforms, open source hardware projects, and 3D printing. He has several websites about the Arduino, including the Open Home Automation website, which is dedicated to building home automation systems using open source hardware. Marco has written another book on home automation and the Arduino, called Home Automation With Arduino: Automate Your Home Using Open-source Hardware. He has also written a book on how to build Internet of Things projects with the Arduino, called Internet of Things with the Arduino Yun, by Packt Publishing.
Read more about Marco Schwartz

Right arrow

Chapter 6. Fun Internet of Things Projects

In this chapter, we will cover:

  • Making a simple Arduino clock

  • Building a digital candle

  • A cloud-controlled digital candle

  • Building a Bitcoin ticker with Arduino

  • Assembling a GPS module

  • Building a simple GPS tracker

  • Troubleshooting fun IoT project issues

Introduction


In this chapter, we are going to have some fun, and apply all that we saw so far in the book to simple, entertaining, but also useful IoT projects that use Arduino. In these examples, we are going to build a clock that gets the time from the cloud, and also an actual GPS tracker that will display the position of your Arduino project on Google Maps!

Making a simple Arduino clock


As the first project of this chapter, we are going to build a simple clock that gets the time from a cloud server, using Arduino. The time itself will actually be displayed on an OLED screen, also controlled by the Arduino board.

Getting ready

For this project, you will need an OLED screen to display the time that can be controlled via Arduino. I recommend using the 128x64 OLED screen from Adafruit (https://www.adafruit.com/products/938).

We can now assemble the project, which basically consists of simply connecting the Arduino board to the OLED screen. First, place both boards on a breadboard. Then, connect the VIN pin of the OLED board to the VCC of the Arduino board, and GND to GND. After that, connect the data and clock pins: data goes to the SDA of the Arduino board, and CLK goes to the SCL of the Arduino board. Finally, connect the RST pin of the OLED screen to pin 4 of the Arduino board.

This is the final result:

On the software side, you will need to download...

Building a digital candle


In this recipe, we are going to learn how to make a digital version of a candle using Arduino. We'll see how to control a multicolor LED to emulate the behavior of a real candle. It's just the perfect project for Valentine's Day, Christmas, and other celebrations.

Getting ready

For this project, the only thing you will need is an Adafruit NeoPixel, which is a smart RGB LED that can be easily controlled via Arduino.

I also used some alligator clips to connect the Arduino board to the NeoPixel.

Assembling the project is really easy – you just need to connect the NeoPixel input pin to Arduino pin 5, GND to GND, and VCC to VCC of the Arduino board.

This is the final result:

On the software side, the only thing you need is to install the Adafruit_NeoPixel library, which you can install from the Arduino library manager.

How to do it...

Let's now see how to configure the project. The first step is to include the required library, and declare that the NeoPixel is connected to pin...

A cloud-controlled digital candle


In the previous recipe, we learned how to build a digital candle using Arduino. But what about the IoT aspect of the project? Well, this is what we are going to deal with in this recipe. We are going to connect the project from the previous recipe to the cloud, and learn how to control it from anywhere. This could, for example, be a candle that you send to loved ones that are far away, and that you suddenly switch on to show you are thinking about them.

Getting ready

For this project, first you need to follow the previous recipe to build the candle. Then, you can configure the candle with some new code to control it from the cloud.

You will need to install the PubSubClient and aREST libraries, which you can easily do by using the Arduino library manager.

The sketch starts as always with the required libraries:

#include <SPI.h>
#include <WiFi101.h>
#include <PubSubClient.h>
#include <aREST.h>
#include <Adafruit_NeoPixel.h>
#define...

Building a Bitcoin ticker with Arduino


Bitcoin is currently the most used cryptocurrency in the world. There are a lot of Bitcoin tickers (plugins or websites that indicate the current price of Bitcoin) out there, but wouldn't it be cool if you could have your own little Bitcoin ticker on your desk? This is exactly what we are going to do in this recipe.

Getting ready

For the hardware, you can refer to the very first recipe of this chapter, as it uses exactly the same hardware that we use in this project: an OLED screen connected to the Arduino MKR1000 board.

Let's now see how to configure the project. As the sketch is quite long, I will only highlight the most important parts here. First, we define the Wi-Fi credentials, and we also define the API that we'll use to grab the current price of Bitcoin:

// WiFi settings
const char* ssid     = "Jarex_5A';
const char* password = "connect1337';

// API server
const char* host = "api.coindesk.com';

Then, in the loop() function of the sketch, we create...

Assembling a GPS module


In this recipe, we are going to learn how to completely assemble a GPS module with Arduino, and make sure that it is working. The goal is to build a GPS tracking module with Arduino, which is what we will see in the next recipe.

Getting ready

For this project, we will have to use an Arduino Uno board, instead of the usual MKR1000 board, as at the time of writing, the GPS/GSM module I used was not compatible with the MKR1000 board. This is the list of all the components that you will need for this recipe:

Building a simple GPS tracker


In the last recipe of this chapter, we are going to build a simple GPS tracker using the hardware we built in the previous recipe. We will send the current GPS location of the project to a cloud server, and then use this to display the position of the project in real time on a Google Maps widget.

Getting ready

You will, of course, need to have built the hardware in the previous recipe, and make sure that the GPS is working correctly. If that's not done yet, please refer to the previous recipe.

Let's now see how to configure the project so that it sends data to Dweet.io, which is a cloud server we already used in this book. As the code is quite long, I will only highlight the most important parts here.

First, let's define a new thing called gps_tracker:

String dweetThing = "gps_tracker';

Inside the loop() function of the sketch, we create a new request to Dweet.io, by including the latitude, longitude, and battery level inside the request:

uint16_t statuscode;
  int16_t...

Troubleshooting fun IoT project issues


In this part of the chapter, we are going to see what can go wrong when configuring your board and connecting it to the Internet. Indeed, some of the steps involved here are quite complex and many things can go differently than expected.

Nothing is displayed on the OLED screen

The first thing that can happen is that the OLED module has not been correctly connected to the Arduino board. For example, you could have mixed the SCL and SDA pins. Also make sure that you have correctly connected the reset pin. Then, make sure that the Wi-Fi credentials have been correctly entered in the sketch.

I can't get my location using the GPS module

The GPS module that I used in this chapter really needs to have a clear line of sight with the sky to work correctly, unlike the more advanced modules that you have in your phone, for example. So if the project doesn't work, make sure the module is close to a window or even slightly outside. Also make sure that you have connected...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Internet of Things with Arduino Cookbook
Published in: Sep 2016Publisher: PacktISBN-13: 9781785286582
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Marco Schwartz

Marco Schwartz is an electrical engineer, entrepreneur, and blogger. He has a master's degree in electrical engineering and computer science from Supélec, France, and a master's degree in micro engineering from the Ecole Polytechnique Fédérale de Lausanne (EPFL), Switzerland. He has more than five years' experience working in the domain of electrical engineering. Marco's interests center around electronics, home automation, the Arduino and Raspberry Pi platforms, open source hardware projects, and 3D printing. He has several websites about the Arduino, including the Open Home Automation website, which is dedicated to building home automation systems using open source hardware. Marco has written another book on home automation and the Arduino, called Home Automation With Arduino: Automate Your Home Using Open-source Hardware. He has also written a book on how to build Internet of Things projects with the Arduino, called Internet of Things with the Arduino Yun, by Packt Publishing.
Read more about Marco Schwartz