Traditional factory automation and remote monitoring systems have overhead costs of up to six figures per machine or more. With complex legal contracts from equipment manufacturers, licensing, consulting, and installation costs, putting together a system to remotely monitor your machines is a lot more complicated than it should be.
Using off the shelf hardware with a secure cloud platform is a great alternative to implementing expensive SCADA systems for non-critical monitoring applications like counting the number of boxes on a conveyor belt, monitoring the cycle time of a machine for optimization, or gathering data from your production line.
In this tutorial we’ll show you how to quickly deploy a sensor that can count the number of objects moving on a conveyor belt in real time. This can be used for quality control, logistics, and to maximize the efficiency of your production line.
You might think that the complexity of setting up a system from scratch would be too time consuming, but using tools like Temboo Code Generation and widely available low cost hardware, you can set up an entire network within a few hours. IoT Platforms like Temboo allow you to copy and paste code from one device to another, while managing APIs and updates from the web. This makes deploying and maintaining an IoT system a lot more manageable than having to manually interface with every sensor node.
Setting Up A Production Line Monitoring System
We’ll be using a Dragino Yún Shield along with an Arduino Uno as our hardware platform. The Dragino Yún will act as a bridge to connect our sensor node to a WiFi network.
We’ll also use a photoelectric sensor, which uses infrared light to detect how far away an object is. The Arduino will read a value from the sensor at a rate of 5 times per second, which should be more than enough for an average conveyor belt moving boxes. Every 20 seconds, the Arduino will upload the latest object count.These rates can be increased for high speed processes as well. Our program will count how many objects pass by, and store these values in a Google Sheet which your organization can access via browser or mobile app.
- Arduino or Draguino Yún
- Arduino Zero (Other hardware platforms can be used, but will require modification to the provided code)
- IR Distance Sensor
- Note the max range of this sensor – you can use a more powerful sensor if a higher resolution or longer range is needed. Make sure that the Arduino can provide enough power to the sensor, otherwise you will need to use an external power source.
- USB Cable and Power Adapter
- WiFi Access
- A Temboo account
To begin, we’ll show you how to make your Arduino Yún add rows of data to a Google Sheet. You can use this to log data from sensors connected to your Yún. This sketch uses our Google > Sheets > AppendValues Choreo.
Step 1: Get Your Temboo Account And API Credentials Set Up
- Make sure you have a Temboo account. If you don’t already have one, you can register for a free account here.
- Since this sketch uses a Google spreadsheet you’ll also need a Google account.
- Log in to Google’s Developer Console and create a new project if you haven’t done so already.
- Under the API Manager section, select Library and make sure you’ve enabled API access for the Google Sheets API.
- Select Credentials in the API Manager section and create a new Client ID specifying Web application for the Application type.
- When configuring the Consent Screen, make sure you fill out the Email Address and Product Name fields.
- Save the Consent Screen details and specify the callback URL below as the Authorized Redirect URI. Make sure to replace ACCOUNT_NAME with your Temboo account name.
- Go to the Google > OAuth > InitializeOAuth Choreo page, and fill in the Client ID from the app you registered at Google and the following Scope: https://www.googleapis.com/auth/spreadsheets. Then click Generate Code to run the Choreo from our site.
The InitializeOAuth choreo will return an authorization URL and a callback ID (required for the FinalizeOAuth step).
- Open a new web browser, navigate to the authorization URL returned by the InitializeOAuth Choreo, and click “Accept” to gran the app access to your Google Account.
- Go to the Google > OAuth > FinalizeOAuth Choreo page, and specify the callback ID returned earlier by the InitializeOAuth Choreo. Then click Generate Code to run the Choreo from our site. This process will return a Refresh Token which can be used along with the Client ID and Client Secret to authenticate with Google.
- Create a Google Sheet. In this example, our spreadsheet has two columns as seen below: time (in milliseconds) and sensor values.
A screenshot of a spreadsheet taking data from a Yún – note the column names.
- When viewing your spreadsheet, you’ll see a spreadsheet ID in your browser’s URL bar. Copy this ID because you’ll need it when running the AppendValues Choreo. In the example below, the highlighted part is the Spreadsheet ID.
- Make sure that you have the latest version of the Arduino IDE. You should also check that you have the newest version of the Temboo Library by checking the Arduino Library Manager.
- Make sure that your Yún is connected to the internet. Arduino has a helpful guide if you need assistance.
Step 2: Write the Sketch
Copy the sketch code below into a new tab in your Arduino IDE. This code calls the AppendValues Choreo, and you will need to replace the placeholder values in the code with your own Google account details and the ID of your Google Sheet.
The placeholders include:
Step 3: Create Your Header File
The sketch above references the TembooAccount.h header file, which contains your Temboo account information.
Copy this code into a new tab in Arduino and call it TembooAccount.h.
#define TEMBOO_ACCOUNT “ACCOUNT_NAME” // your Temboo account name
#define TEMBOO_APP_KEY_NAME “APP_NAME” // your Temboo app key name
#define TEMBOO_APP_KEY “APP_KEY” // your Temboo app key
Your app name and key can be found here: https://temboo.com/account/applications
Step 4: Set Up Your Production Line Monitoring Hardware
Now that we’ve set up Google Sheets to log our sensor data, let’s connect our IR distance sensor to our arduino. Make sure your Arduino is powered off before connecting the sensor. Connect the red wire (+5V) to the 5V pin on the Arduino Yún, black wire (Ground) to the GND pin, and the yellow wire (Data) to pin A0. Power your board up and give it up to a minute to boot up.
If you haven’t set up your Arduino Yún to connect to a WiFi network yet, check out this guide on how to get it up and running.
That’s it! Your Production Line Counter is Ready
Open up the Google Sheet that you associated with your choreo, and watch the data being updated every 15 seconds. The first column shows a timestamp of how long your program has been running. The second column stores a count of how many objects passed over the IR distance sensor. In our code, we are incrementing the counter based on the falling edge of the object, and the sensor is polling at a rate of 5Hz. Feel free to modify our code to suit the needs of your project. If you have any questions, send us a message via live chat on the bottom right corner of this window!
Temboo can be used to quickly generate code in over a dozen programming languages and several hardware platforms. One example of how you can extend the functionality of this project is to send an SMS employees when your production rate drops under a certain threshold.
Check out our Quickstart Guides for more ideas on how you can connect your facilities to the Internet of Things without breaking the bank.
Interested in hearing more about the latest Industrial IoT technologies and solutions? Contact us for more information on how to implement IoT solutions at your business or follow Temboo on Twitter, LinkedIn, Facebook, Instagram or YouTube.