- 0. Introduction
- 1. Project Schema
- 2. Arduino Yun. Connections description
- 3. Carriots Project and Device Registration
- 4. Data Transferred from Arduino Yun to Carriots
- 5. Code implemented on Arduino Yun
- 6. Checking Data is collected in Carriots
- 7. Creating the lego gate
This tutorial helps you build a lego security gate.
To do this, we use an Arduino Yun, an ultrasonic sensor and a servo motor to lift and lower the gate. Every time the gate changes position we send that information to the Carriots Engine.
In this project you will learn how to:
- Connect an ultrasonic sensor to an Arduino Yun
- Connect a servo motor to an Arduino Yun
- Send streams to Carriots using the CarriotsClientsYun library
- 1 x An Arduino Yun
- 1 x HiTec SRF05 Ultrasonic Sensor
- 1 x HiTec HS422 Servo Motor
- 1 x Tiny Breadboard
- 1 x Ethernet Connection
- 1 x Legos (with at least one gear)
Music to listen: Regina Spektor - Fidelity
This project is a quick way to create a securtiy barrier app and understand the basics of combining Arduino Yun, ultrasonic sensors, servo motors and Carriots.
Here is the overall diagram of the project:
The Arduino Yun is programmed to register the presence or absence of objects in its proximity. According to this information, the lego gate will lift or lower. For every change of gate status, a stream is sent to Carriots.
All the data streams sent by Arduino Yun are collected and stored in Carriots. Carriots is a huge database that collects all the information that your sensors send.
In addition to storing data, the true power of Carriots is to let you build Apps very quickly with few lines of Groovy code.
With Carriots you can build very complex Apps to support all the logic of your product on the cloud and integrate it with other devices and IT systems. But for now let’s keep it simple.
You can see the connections between the Arduino Yun, the ultrasonic sensor and the servo motor in the diagram below. Note that pictured is the SRF04 ultrasonic sensor, we used the SRF05 ultrasonic sensor instead. They are completely compatible, the only difference is the order of the output prongs.
If you're registered in Carriots, you have a default device already created for you.
Check your control panel and see what it looks like.
Basically you need the device id_developer that might be something like defaultDevice@myusername.
But if you want, you can create a new device and use it in this example.
Now, go to your control panel “My account menu” and check your Apikey.
Its a big alphanumeric token like:
You need this number to complete the example.
In this tutorial we will use the CarriotsSendYun library. If you have not downloaded it you will need to in order to complete this tutorial. You can download the library and get more information about it in the tutorial How to use the Carriots library for Arduino Yun to send streams.
The method used to send streams to Carriots is the method "send". It has 4 parameters that you need to define in order to send a stream correctly (a two-dimensional array, the number of rows the array has, your Apikey, your device id_developer). The array consists of the key-value pairs that you will be sending to Carriots.
Your payload, the stream to send to Carriots, will be:
This is the code for the Arduino Yun. Note that some values should be replaced by your own values.
Before setting up the lego component of the project, you can check to see if your device is sending streams when you put an object in front of and remove an object from the range of the ultrasonic sensor.
Run the program and test it by placing your hand in front of the sensor and removing it.
It's time to test our control panel and check if we have new streams.
Go to “Data management” → “Data streams” and you will see your data.
- menu option
- new data
Making a security gate from legos can be done in many different ways, from very simple to very complex. It's really up to you to decide what type of design and complexity you want. Here, we will give you an idea of how you can make a simple gate that connects to your servo motor.
The basic components of making a gate are the gears that will change the gate's position and the gate itself, which must connect to the gear in a fixed position.
In the pictures below you can see how we have positioned the servo (with a gear fixed to it) under the gate gear. The gate itself consists of a long lego connected to the gear, which will turn as the servo motor turns, and the legos necessary to support the gate from the ground.
- Gear position
- Security Gate