This application is written in JavaScript and Arduino C++. You must set up the Arduino IDE to program the hardware to collect your sensor values. You will also need to acquire the hardware used for this tutorial.

Programmable Logic Controller Hardware and Sensors

This tutorial uses industrial-quality hardware that is designed to withstand harsh environments like those found in manufacturing and other industrial applications. You could use other hardware vendors by following this tutorial as a model for how to implement the same PubNub connectivity with other PLC vendors.

For this tutorial, we are using the ProductivityOpen Controllers by Automation Direct. We chose this hardware because it supports using C++ to program allowing for using our PubNub Arduino SDK. Automation Direct also offers fast shipping and amazing customer service.

Required PLC Hardware

You'll need one of each of these components:

P1AM-100 PLC - This is the Programmable Logic Controller that will be the brains of our sensor data collection.

P1-4ADL2DAL-2 (Productivity1000 analog combo module) - This module will be used to collect the analog output values from our vibration sensors. You will also need a separate 24v power supply for this module as it is isolated from the P1AM-100. You may also want to purchase one of the recommended removable terminal blocks to make connecting 24v power and the sensors easier.

P1AM-ETH - This module is required to connect the P1AM-100 PLC to the internet and enables streaming sensor data over the PubNub network. An ethernet connection is required for the tutorial.

P1-01AC (Optional) - This power supply connects to the P1AM-100 PLC to enable you to power it from an AC power source. You could also use an external 24v power supply to power the P1AM-100 PLC or one of the other power supply modules available from Automation Direct for the P1AM-100.

You'll also need two sensors for collecting vibration data. These will connect directly to the P1-4ADL2DAL-2 (Productivity1000 analog combo module). You can use any sensor that is analog voltage output type with this tutorial.

We used the SINVT Voltage-Output-Type Tilt Switch by WitMotion because it is industrial quality and pairs nicely with our other selected hardware.

Assembling Your Vibration Monitoring PLC

Each of the ProductivityOpen modules link together. Open the lock tabs, connect each module, and then push the locking tabs back down. The modules should be connected in this order (There is only one possibility):

P1-01AC > P1AM-ETH > P1AM-100 > P1-4ADL2DAL-2

Next, you'll need to connect the P1-01AC to AC power.

The last step is to connect your sensors and 24v power to the P1-4ADL2DAL-2.

  • Connect an external 24v power supply to the 24v and 0v pins on the P1-4ADL2DAL-2.

  • Connect the positive wires from both sensors to the 24v pin.

  • Connect the negative wires from both sensors to the 0v pin.

  • Connect the X and Y analog outputs from one sensor to V1+ and V2+ inputs.

  • Connect the X and Y analog outputs from the other sensor to V3+ and V4+ inputs.

  • Other wires from the sensors are not used.

Industrial automation modules with AC power input, Ethernet connection, and DC power wiring annotations for sensor outputs.

Arduino IDE Setup

Arduino provides a guide for downloading and installing the Arduino IDE.

Once the application is installed, you must configure it to support the hardware used in this tutorial and add the PubNub Arduino SDK library.

Set Up P1AM-100 for Arduino IDE

Open the Arduino IDE and open Preferences from the File menu.

In the Additional Boards Manager URLs area, add the following URL:

Then click OK and go to Tools > Board: > Boards Manager. Search for 'P1AM'.

Install the P1AM-100 board by Facts Engineering. Close the Boards Manager window.

Go to Tools > Board: > P1AM-100 and select 'P1AM-100'. You are now ready to develop with the P1AM-100 programmable logic controller using the Arduino IDE.

Set Up PubNub Arduino SDK

In the Arduino IDE, open the Library Manager by going to Tools > Manage Libraries...

Search for 'PubNub.'

Install the PubNub Arduino SDK. Close the Library Manager.

You are now ready to develop with the PubNub Arduino SDK using the Arduino IDE.

Your development environment is now ready. Next, you need to configure your PubNub API keys.

BackStep 1 of 4Next