Reader small image

You're reading from  Hands-On Internet of Things with MQTT

Product typeBook
Published inOct 2019
Reading LevelIntermediate
PublisherPackt
ISBN-139781789341782
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Tim Pulver
Tim Pulver
author image
Tim Pulver

Tim Pulver is a Berlin-based freelance interaction designer and developer. In his work, he combines his physical prototyping experience and knowledge of interface design with modern technologies such as 3D printing, laser cutting, web technologies, and machine learning to create unique interactive experiences. In recent years, he has worked on interactive data visualizations, web-based audiovisual experiences, musical interfaces, and cables an innovative browser-based visual programming language that enables the creation of interactive audiovisual prototypes without writing any code. He holds a Bachelor of Arts degree in interface design from the University of Applied Sciences in Potsdam, Germany.
Read more about Tim Pulver

Right arrow

Building a Smart Productivity Cube, Part 1

In the previous chapters, we built a smart pet food dispenser and a smart e-ink to-do list. In this chapter, we are going to build a smart productivity cube. By using mechanical tilt switches, we will be able to sense which side the cube is standing on. We will then assign that position to an activity (for example, learn MQTT) and log how long we pursue this activity.

After following along with this chapter, you will know how to build your own orientation sensor using tilt switches. This chapter serves as the basis for the next chapter, Chapter 8Building a Smart Productivity Cube, Part 2, where we will learn how to enhance your smart productivity cube with MQTT and how to display its information on your smartphone using Android and iOS apps. 

In order to facilitate the learning process, the chapter is divided into the following...

Technical requirements

Before we begin, please make sure that you read Chapter 4, Setting Up a Lab Environment. In Chapter 5, Building Your Own Automatic Pet Food Dispenser, we also tested the required MQTT and Wi-Fi libraries (in the Testing MQTT on Arduino section).

Besides the MQTT and WiFiNINA libraries, we do not need any additional libraries for the Arduino IDE.

The following components are needed to build the project:

Building the smart productivity cube

Before we get started building the smart productivity cube, let me first explain what exactly we are going to build and why.

Many people seem to suffer from the same problem: they feel like they have too little time and wonder where their time went. There are already plenty of time-tracking applications for desktop computers, smartphones, and tablets, such as Toggl (https://toggl.com) and Harvest (https://www.getharvest.com), that address this problem. All of them serve the same purpose—counting how much time you spend on what activities, so you have a better understanding of how you use your time. This is either used for personal insights or professionally, for example, to count billable hours when working for a client. Most of them work like a stopwatch does—you manually start and stop a timer, one per task.

While most of these...

Building the cube

Let's continue by building a cube around the breadboard so that we can place it on different sides. Because we want it to be stable, we need to make sure we secure the breadboard well enough. If we place the cube in a way that the breadboard construction is at the top, we don't want it to fall down.

To compress the size needed on the breadboard, you can move the Arduino a bit inward (placing it on a position on the breadboard so that the Arduino does not stand out). When using a half-sized breadboard, you can then use a side length of 8.5 cm for the cube. If you do so, please don't forget to change the position of the breadboard cables as well. You need to move the cables going from the Arduino to the tilt switches. They need to be connected to ports 0, 1, 2and 3.

Also, don't forget to move the cable connecting ground...

Detecting orientation changes

The easiest approach to detect orientation changes of our cube would be to place the following code at the end of our loop function:

if (previousSide != currentSide) {
Serial.print("Side: "); Serial.println(currentSide);
previousSide = currentSide;
}

But the easiest approach is not always the best one. The problem with this approach is that when we switch sides, another side might be detected in between. For example, let's say the cube was lying on the bottom side and you wanted to place it on its top side. While rotating it, it would (for a very short time) detect that it is placed on the side in between, even though we are just rotating it by hand and it does not rest on this side.

To overcome this problem, we should only detect a side change when the last x values were all recorded on the same side. To get this right, we...

Summary

In this chapter, we learned how to build an orientation sensor using tilt switches from scratch and saw how to improve it step by step. We discussed how to hide the complexity of our project by building a cube around it to make it presentable.

In the next chapter, we will build upon this by adding MQTT into the mix. The cube will be enhanced to broadcast the associated activity along with the stopped time, for example, Watching TV: 123 minutes.

We will also have a look at how to make use of MQTT clients for Android and iOS to display the data published by the cube.

Questions

  1. How should tilt switches be arranged to give reliable readings?

Further reading

You have been reading a chapter from
Hands-On Internet of Things with MQTT
Published in: Oct 2019Publisher: PacktISBN-13: 9781789341782
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
Tim Pulver

Tim Pulver is a Berlin-based freelance interaction designer and developer. In his work, he combines his physical prototyping experience and knowledge of interface design with modern technologies such as 3D printing, laser cutting, web technologies, and machine learning to create unique interactive experiences. In recent years, he has worked on interactive data visualizations, web-based audiovisual experiences, musical interfaces, and cables an innovative browser-based visual programming language that enables the creation of interactive audiovisual prototypes without writing any code. He holds a Bachelor of Arts degree in interface design from the University of Applied Sciences in Potsdam, Germany.
Read more about Tim Pulver