Connecting a Door with Raspberry Pi and thethings.iO

Story

At thethings.iO we want to show you different ways of using our platform for your projects and products! For this reason, we have developed a prototype using a Raspberry Pi and our REST API to monitor the access to a room.connecting a door with raspberry pi and thethings io

The device, that should be embedded next to the door as you will see on the next pictures, uses an ultrasonic sensor to publish the distance to the closest wall (if any) every 10 seconds. When the door is opened by someone, the measured distance is shortened due the blocking door. The device will automatically report the incident to the thethings.iO cloud but it will allow the user to manually enter an access code to specify that the access was allowed.

Just for having fun, the sensorā€™s distance is continuously sent so we can visualize its fluctuations in real time at thethings.iO panel. Itā€™s easily distinguished on the following graph when someone has entered, donā€™t you think?

In addition, the device has four buttons, two for entering a code, one to shut it down and the last one to memorize the ā€œnormal distanceā€ i.e. the deviceā€™s distance to the closest obstacle when the door is shut. To perform the last two actions, entering a password is required.

Also, two LEDs show some feedback to the user. When the leds blink, they show that the device is memorizing a new distance. When both leds are on, a password can be entered.

Getting into the code!

To write a value toĀ thethings.iOĀ you first need to get a token that identifies your ā€œthingā€ and allows it to use the cloud. To get a token you need a thethings.iO account (you get three tokens with a free account). Once you have the account, you need to activate the token, which can be done from the same thethings.iO website and just requires you to press a button. You can find detailed instructions here.schematic connecting a door with raspberry pi and thethings io

In this project, the activated token should be hard-written into the code, specifically inside the variable ā€œtokenā€ of the fileĀ ttrest.py.Ā From now on,Ā writing to the cloud is as easy as calling the function ttwrite where the first parameter is the name of the variable that we want to write to and the second parameter is the actual value.

d = tt.get_distance() #retrieve distance from ultrasonic sensor

ttrest.ttwrite('Distance', str(d)) # write data to thethings.iO

Your turn!

Do you like it? Why donā€™t you try to do your own project with theĀ thethings.iOĀ service? Itā€™s free for the first three devices! šŸ˜‰

For more detail: Connecting a Door with Raspberry Pi and thethings.iO


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top