So, you want to build an IoT Project?
Tags: iot, tutorial, aws, beginners
Published: 2020-03-01 14:46:56

---
title: So, you want to build an IoT Project?
published: true
description: Are you a beginner to developing for The Internet of Things? Perhaps you're an expert but are curious about what new things there are to focus on in? Let's chat about what it means to develop IoT projects in 2020.
canonical_url: https://devopstar.com/2020/03/01/so-you-want-to-build-an-iot-project
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/nxk5uat9i53bvk0lfwyt.jpg
tags: iot, tutorial, aws, beginners
---

> Please reach out to me on [Twitter @nathangloverAUS](https://twitter.com/nathangloverAUS) if you have follow up questions!

*This post was originally written on [DevOpStar](https://devopstar.com/)*. Check it out [here](https://devopstar.com/2020/03/01/so-you-want-to-build-an-iot-project)

Are you a beginner to developing for The Internet of Things? Or perhaps you've been working on embedded systems for a while now but haven't kept up with some of the latest trends. In this post I'm highlighting some things that I feel are worth checking out and investing time in. I'm also going to try to break down some of the invisible barriers people think exist when contemplating building an internet connected project.

## The Idea

Before jumping in It's helpful to have a goal in place when learning something new that will help **drive an outcome**. When dreaming up an idea keep in mind you'll want to keep some of the following things in mind.

#### Nothing is off the table

Don't limit yourself just because you don't immediately see it being possible. Passion is 90% of the process! If there's a particular thing you are really excited about working on you'll be able to leverage that burning desire to your advantage when learning.

> Passion is 90% of the process!

![IoT Project iterating process](https://dev-to-uploads.s3.amazonaws.com/i/zkk5b5wfqqcah1qcf6wn.png)

Understand that iterating on your project is going to be key to get to the finish line anyway, so aiming high just means there will be more learning & prototyping along the way. *Being upfront with yourself that your first design might not be perfect will help you remain engaged.*

#### Cost

The upfront cost to get started with IoT projects isn't likely to be as high as you might think! We'll go into more detail later in the post, however you'll realize entry level price points are normally under $30 for simple 1 device projects.

Once you get going as well you will begin to accumulate random parts just through recycling.

#### Uniqueness

Guess what? Someone has almost certainly attempted what you are wanting to do already. This isn't a bad thing though, in fact it'll make your life a whole lot easier! I recommend checking out some of the sites below for ideas

* [hackster.io](https://www.hackster.io/)
* [Instructables](https://www.instructables.com/)
* [Hackaday](https://hackaday.com/)
* [Make:](https://makezine.com/)

## Our Idea

For the purpose of this post, let's pick an hypothetical project idea to work on!

> We would like a **moisture sensing system** that lets us monitor the state of our garden

The overall view of what we want to achieve can be seen below. When you are trying to visualize your idea its helpful to draw a nice high level diagram.

![Simple IoT Project overview](https://dev-to-uploads.s3.amazonaws.com/i/eag234akfoi3o7vjasgi.png)

#### Shopping List

While we're at this stage it's also worth making a list of things you **think** you might need. Even if your list doesn't make much technical sense it'll give you an idea of what to google for later when shopping for parts.

> Don't shy away from also making notes on your list with any questions you might have

* IoT Device (*Wireless Required*)
* Moisture Sensor
* Cables to connect moisture sensor to device

#### Revise Project Diagram

Once you have your ideas down on paper it's a great idea to revise your original architecture diagram so it includes any extra ideas that came up.

![Revised IoT Project diagram](https://dev-to-uploads.s3.amazonaws.com/i/bwpwwfye0or8tkdonkqb.png)

As you can see I've revised the original idea to now include:

* Needing some kind of **Wireless capability** (we don't really want to run a cable outside the house).
* **Server to store the data** from the moisture sensor.
  * Perhaps we won't need this, but I thought it was worth mentioning it now so we don't forget we need some way to store data from the moisture sensor.
  * This server could also be what allows us to view the monitoring data.

## Parts

With a simple design ready to go we can begin to research the various pieces of our design to flesh out some details.

> You'll probably become really overwhelmed at this stage, especially as you come across some new words or terminology. But stick with it, don't try to understand everything all at once

#### Moisture Sensor

Let's look at the moisture sensor for example. I googled `IoT Moisture Sensor` and found a local online retailer that sells one.

![Moisture sensor from Core Electronics](https://dev-to-uploads.s3.amazonaws.com/i/qrnhkh7c6ay26jvvnhf0.png)

Scrolling down the page and you'll find that most online retailers do a really good job of pointing you to related products / commonly purchased extras. Although this is mostly just a technique for them to sell more product, it can be super helpful when starting a project to get an idea of what you might need.

![Related Products with Moisture Sensor](https://dev-to-uploads.s3.amazonaws.com/i/7n7vvqwit3vz08x149by.png)

In this case I can see people buy [Raspberry Pi Zero W](https://core-electronics.com.au/raspberry-pi-zero-w-wireless.html) devices and [Lithium batteries](https://core-electronics.com.au/polymer-lithium-ion-battery-2000mah-38459.html). This makes sense as we will need a Micro-controller (small IoT computer) and a battery so it can operate without a power-cord.

#### Micro-controller

The Micro-controller is the brains of the operation! In the previous step we came across the [Raspberry Pi Zero W](https://www.raspberrypi.org/products/raspberry-pi-zero-w/), which is a great board to own if you're a hobbyist in the IoT space due to its versatility.

> Sometimes the board you buy won't be the best fit for the final product. Don't worry if you get it wrong the first time, as you can reuse the boards you buy for future projects as well.

For our scenario the choice of Micro-controller could be taken in a number of directions. Below is some of the popular boards people go with along with an average price range for each.

| Device              | Cost   | Connectivity     |
|---------------------|--------|------------------|
| Raspberry Pi Zero W | ~$18   | WiFi / Bluetooth |
| ESP8266             | $5-20  | WiFi             |
| ESP32               | $10-30 | WiFi / Bluetooth |

> **Note**: *Devices like the Raspberry Pi don't take into account the cost of a MicroSD card*

For the protect we're building here **I'd decided to pick an ESP8266** as it's cheap and provides us with a WiFi capability

##### A Word On Prices

Prices on electronics can vary from one extreme to another. Depending on if you are buying locally, or from china directly you'll see a massive difference in cost (and occasionally quality). Below are some of the re-sellers I typically use; keep in mind that **you get what you pay for**. Also the shipping time on products from china can be **literal months**.

* [Banggood](https://www.banggood.com/)
* [Gearbest](https://www.gearbest.com/)
* [AliExpress - RobotDyn](https://robotdyn.aliexpress.com/store/1950989)
* [AliExpress - ChanZon](https://chanzon.aliexpress.com/store/313665)
* [AliExpress - YF](https://ansan888.aliexpress.com/store/605870)
* [adafruit](https://www.adafruit.com/)
* [SparkFun Electronics](https://www.sparkfun.com/)

## Code

If you're already a developer then you'll already know how much easier life can be when you have the best tools are your disposal. The IoT / Micro-controller world is similar however isn't as evolved.

Don't worry though, you won't have to write raw C++ or deal with allocating memory (much if at all). In fact there are projects that exist with the pure function of porting languages like Python and Node over to the Micro-controller landscape.

#### Mongoose OS

[Mongoose OS](https://mongoose-os.com/mos.html) runs on-top of your base Micro-controller and **handles all the hard stuff** for you.

![Mongoose OS Architecture taken from https://mongoose-os.com/mos.html](https://dev-to-uploads.s3.amazonaws.com/i/ds34sbvz9hguhudl9rrr.png)

It will run on-top of boards like the ESP8266 we've chosen and makes deploying, monitoring and connecting to the cloud super easy. For hobby projects like the one we're building it's a fantastic option! The downside is when you go to use it in a commercial setting there are associated costs at a per device level.

#### PlatformIO

[PlatformIO](https://platformio.org/) is a very well established tool chain for developing on embedded devices. It serves itself as an IDE extension for popular editors like VSCode and enables developers to write the same code and deploy it to different architectures seamlessly.

![PlatformIO Logo](https://dev-to-uploads.s3.amazonaws.com/i/4ijcj5bnt0gxvp8r91gk.png)

PlatformIO also provides a nice interface into community build libraries and supports well over [750 boards](https://platformio.org/boards). Everything is also managed via a `platformio.ini` file in the root of a project that defines the board types and libraries that will be needed to build and deploy

```ini
[env:uno]
platform = atmelavr
board = uno
framework = arduino

lib_deps =
  FastLED@3.2.0
```

Not only that but with support for build systems like TravisCI you can also so basic continuous integration testing

```yaml
language: python
python:
  - "2.7"

sudo: false
cache:
  directories:
    - "~/.platformio"

install:
  - pip install -U platformio

script:
  - platformio run
```

If you would like to see how PlatformIO can be used with a basic project, checkout [t04glovern/office-christmas-lights](https://github.com/t04glovern/office-christmas-lights)

## Circuit Design

When you get the designing the circuit, don't shy away from taking designs from the internet. 

> The **first place to look** for examples of how to use your sensor is to check the vendor the product page of the vendor you bought it from. They usually have links to code and circuit examples along with their sensors.

If you just google your part name along with `circuit example` or `code example` I promise you'll find something relevant to helping you. However if you do need to design a circuit yourself, I recommend checking out the [Fritzing project catalog](http://fritzing.org/projects/) and then use [Fritzing](https://fritzing.org/home/) to design.

![Fritzing Circuit Designer](https://dev-to-uploads.s3.amazonaws.com/i/qogvfeb1ao8806jrju07.png)

##### A Word on Electronics

I polled a group of people for reasons why they find it difficult to get into IoT projects and noticed that the main reason was a lack of electronics skills.

[![Poll from developers on why they don't execute on IoT project ideas](https://dev-to-uploads.s3.amazonaws.com/i/nsqw72fai3ijoxl4lird.png)](https://twitter.com/nathangloverAUS/status/1233612144387612672)

For most hobbyist projects you will find that the actual electronics knowledge required is extremely low and pretty much boils down to understanding what a couple types of components do and where to use them.

![Voltage Current Resistance example](https://dev-to-uploads.s3.amazonaws.com/i/pbbsvqaawyhtoyenrr51.jpg)

* **Resistor** - Reduce current flow, usually put in front of sensitive components to ensure a specific current requirement is met.
* **Capacitor** - stores energy, can be used to level out the flow of electricity.
* **Power** and **Ground** - the source and sink of electricity to your circuits.

##### But What if I mess up

The tolerance on electrical components is usually high enough that if you use the wrong voltage or supply the wrong current (within reason) things will be okay.

A general rule of thumb is if you are connecting something for the first time, feeling components that are warm to the touch could be a good indicator that something is wired backwards or wrong.

> Note: **Please don't go sticking your fingers on components over 5 volts**. This idea above is based on experiences with IoT projects under 5 volts.

Even if you do blow something up, it's not normally the Micro-controller and instead the components in your circuits. These components are normally very cheap to replace; so I would always recommend ordering more then you need for projects.

## Connecting To Cloud

Connecting your IoT project to the cloud can be done in a number of different ways these days. As mentioned before projects like [Mongoose OS](https://mongoose-os.com/) make it super simple to get data flowing; however its not the only option.

If you're wanting to work directly with your Cloud providers IoT service you usually can just over MQTT and using certificates provided. For an example, I wrote a project called [Cloudy Toast](https://github.com/t04glovern/cloudy-toast) which is an Internet connected Toaster using [AWS IoT](https://us-east-1.console.aws.amazon.com/iotv2/home?region=us-east-1#/connIntro).

![Cloudy Toast Banner](https://dev-to-uploads.s3.amazonaws.com/i/5kevb0pcj9gdpuwq6ejk.jpg)

For another example there's a post [AWS Sumerian Magic Cube](https://devopstar.com/2019/02/07/aws-sumerian-magic-cube) where I connect an ESP8266 to AWS IoT. It more or less comes down to sending messages over MQTT which is a Pub/Sub message bus commonly used in the IoT world.

```cpp
void aws_reconnect()
{
    // Loop until we're reconnected
    while (!client.connected())
    {
        Serial.print("[AWS] Attempting MQTT connection...");
        // Attempt to connect
        if (client.connect(aws_mqtt_client_id))
        {
            Serial.println("[AWS] connected");
            // ... and resubscribe
            client.subscribe(aws_mqtt_thing_topic_sub);
        }
        else
        {
            Serial.print("[AWS] failed, rc=");
            Serial.print(client.state());
            Serial.println(" try again in 5 seconds");
            // Wait 5 seconds before retrying
            working_led();
            delay(5000);
        }
    }
}

```

## Summary

Over the next couple months I will be deep diving into the specifics of each of the sections above in more detail. This post has the difficult purpose of trying to convince you that you are capable of taking on IoT projects.

I know things won't always go right though, so I encourage you to reach out to me on [Twitter @nathangloverAUS](https://twitter.com/nathangloverAUS) and ask questions.