Software apps and online services
The objective of this project was to create a prototype for a low-cost device to monitor pressure on industrial equipment in remote locations using cellular data.
The following is a a step by step walkthrough of the project following the flow of data from the pressure transducer to the email notification generated by the script attached to the Google Sheet.
The pressure transducer converts pressure to an analog electrical signal.
The Arduino Uno converts the analog signal from the pressure transducer into pressure (psi).
When communicating between two Arduino devices via Serial:
- Connect RX on Device #1 to TX on Device #2
- Connect TX on Device #1 to RX on Device #2
- The devices must have a common ground
Data Transmission Frequency (Uno to MKR GSM 1400)
- NORMAL: Every 30 minutes (transmitFrequency) the Uno will serial.print data to the MKR GSM 1400 which will transmit the data to the cloud.
- HIGH/LOW TRIGGER: If the pressure goes above 40 psi (highTrigger) or below 20 psi (lowTrigger) and stays there for greater than 2 minutes (dtLastTriggerLimit) the Uno will serial.print data to the MKR GSM 1400 which will transmit the data to the cloud.
- DEMAND POLL: If pin A1 on the Uno is pushed high it will serial.print data to the MKR GSM 1400 which will transmit the data to the cloud. Note: pin A1 is named "buttonPin" in the sketch for the Uno. There are 2 ways that pin A1 on the Uno can get pushed high. (1) There is a push button on the breadboard. (2) If pin A3 on the MKR GSM 1400 is high it will push pin A1 high. Since pin A3 is controlled by an input in the Arduino Cloud, the current pressure can be obtained remotely at any time without having to wait for a regularly scheduled data transmission.
- The sketch for the Uno could be modified so that multiple inputs like temperature, humidity, battery voltage, etc. could be monitored with high and low setpoints in addition to pressure in the current version.
- The code used to convert the analog signal from the pressure transducer into pressure (psi) is based off the instructions given in the following YouTube video: https://www.youtube.com/watch?v=AB7zgnfkEi4
- The following post on the Arduino Forum covering "Serial Input Basics" was very helpful when it came to writing the code to communicate from one device to the other using serial data: https://forum.arduino.cc/index.php?topic=288234.0
The code used for the Arduino Uno in this project is attached with comments explaining key information.
File Name: "InstrumentReader"
The MKR GSM 1400 processes serial data from the Arduino Uno and transmits the data to the Arduino Cloud using cellular data.
It is worth noting that in the code for the MKR GSM 1400 you'll see Serial1.read as opposed to Serial.read. The reference material on the Arduino website gives a good explanation. The table in the image below shows that the TX/RX pins on MKR boards are accessed via Serial1.
This project is setup with 2 variables in the Arduino Cloud. The image below shows how these variables are displayed in the dashboard on the Arduino Cloud.
The first variable named "dataStringCloud" is effectively a package of all the data from the device. This approach was taken as opposed to one variable for each value to simplify processing the data in Google Sheets. With individual variable names, it was difficult to tell the difference between a value staying the same and a value that did not get updated. The data from this package is parsed in Google Sheets.
The second variable named "pinCloud" is used to control the MKR GSM 1400 from the Arduino Cloud. There is a switch function in the sketch that controls the action based on the value of pinCloud. When pinCloud = 1, pin A1 is pushed high causing an LED on the board to light up. When pinCloud = 2, pin A3 is pushed high which leads to the Arduino Uno sending the current data as described above.
The code used for the Arduino MKR GSM 1400 in this project is attached with comments explaining key information.
File Name: "CommunicationsDevice"
Data is transferred from the Arduino Cloud to Google Sheets using a webhook.
The core of the webhook is the doPost function written in the script of a Google Sheets file.
Here is a quick summary of how to set-up the webhook. Note that the process starts in Google Sheets. You don't get to the Arduino Cloud until the end. To get from A to B, start at B.
- Create a New Google Sheets file
- Click "Tools" on the toolbar & select "Script editor" in the dropdown
- Write code with a doPost function (refer to GoogleSheetsScript.js attached to this project)
- Click "Publish" on the toolbar & select "Deploy as web app..." in the dropdown
- A dialog box will come up with 3 fields.
- (1) Project Version: Always use the dropdown to select "New". After the first update it will default to the # of the current version; if you don't use the dropdown to select "New", the changes will not go into effect.
- (2) Execute the App as: "me (email@example.com)"
- (3) Who has access to the app: "Anyone, even anonymous"
- Press deploy after verifying the values in the 3 fields
- A second dialog box will appear with the "Current web app URL". This is the URL that you will copy & paste into the webhook tab on the Arduino Cloud. Worth noting, this URL stays the same regardless of the project version.
- Click ok, and you are done!
Use Google Sheets to parse the individual values from dataStringCloud and display the unique records transferred from the Arduino Cloud
The link below is to the Google Sheets file used for a recent test of the device. The cells in this file are colored based on how they were populated as indicated in the legend on each sheet.
- doPost function - Transmits data from the Arduino Cloud Webhook. It runs when there is new data on the Arduino Cloud.
- sendEmail function - Sends emails based on values extracted from the sheet named "Data" in the Google Sheets file for the project. It runs once every minute based on the settings in the trigger setup.
Steps to Setup a Trigger for the sendEmail function
- Open Google Sheets file
- Click on "Tools" in the toolbar
- Select "Script Editor" in the dropdown
- From the Script editor window proceed to:
- Click on "Edit" in the toolbar
- Select "Current project's triggers" in the dropdown
- From the G Suite Developer Hub window proceed to:
- Select "Add Trigger" in the bottom right corner of the window
- In the dialog box that comes up make selections to run the sendEmail function.
- Note: running the trigger on a Time-Driven basis makes it possible to generate email notifications when the device stops updating.
This could be optimized by turning off or removing the displays. Another option would be to remove non-essential sensors like the DHT22 and the DS3231.
This could be optimized by reducing the size or frequency of data transmissions. For example: To reduce reduce size, only send pressure as opposed to pressure, temperature, humidity, and time. To reduce frequency, only hourly updates as opposed to every 30 minutes.
Total = $241
- Arduino MKR GSM 1400 ($70)
- Arduino Uno ($22)
- 2 x 3.7V LiPo Batteries ($30)
- 2 x LED Displays ($29)
- Weather Resistant Plastic Box ($22)
- Pressure Sensor ($19)
- Temperature / Humidity Sensor - DHT22 ($10)
- RTC Module - DS3231 ($5)
- Voltage Step-up Converter ($5)
- Logic Level Converter ($4)
- Miscellaneous - LEDs, Resistors, Wiring, etc. ($25)
All of the hardware and tools used for this project were purchased from the following:
- Arduino Online Store (https://store.arduino.cc/)
- Adafruit (https://www.adafruit.com/)
- Amazon (https://www.amazon.com/)
- Harbor Freight
- Home Depot
Thanks for taking the time to review this project.
Any and all questions / feedback / comments / suggestions are welcome / appreciated.