Skip to content

Commit bc86464

Browse files
committed
images started
1 parent a5a25ab commit bc86464

File tree

3 files changed

+188
-4
lines changed

3 files changed

+188
-4
lines changed
133 KB
Loading
202 KB
Loading

content/hardware/07.opta/opta-family/opta/tutorials/18.smart-compressor-app-note/content.md

Lines changed: 188 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ The goal of this application note is to showcase the Opta PLC capabilities on le
3333

3434
## Hardware and Software Requirements
3535

36-
![Hardware Image]()
36+
![Hardware Image](assets/materials.png)
3737

3838
### Hardware Requirements
3939

@@ -44,7 +44,7 @@ The goal of this application note is to showcase the Opta PLC capabilities on le
4444
- PT100 2 Wires RTD (x1)
4545
- RTD to 0-10 V converter (x1)
4646
- Pressure transmitter 0-10 V (x1)
47-
- Power Relay 24 V (x1)
47+
- Power Relay 24 V (Optional x1)
4848
- Wiring Cable 18AWG
4949
- [USB Type-C® Cable](https://store.arduino.cc/products/usb-cable2in1-type-c) (x1)
5050
- Micro-USB Cable (x1)
@@ -60,7 +60,7 @@ The goal of this application note is to showcase the Opta PLC capabilities on le
6060

6161
The electrical connections of the intended application are shown in the diagram below:
6262

63-
![Electrical connections of the monitoring system]()
63+
![Electrical connections of the monitoring system](assets/connection-diagram.png)
6464

6565
The Opta PLC will be powered with an external 24 VDC power supply connected to it's screw terminals `+` and `-` respectively.
6666

@@ -306,6 +306,7 @@ void SensorRead() {
306306
temp = T_I2;
307307
power = C_I1 * GRID_V; // Adjust GRID_V with your grid voltage
308308
press = P_I3;
309+
fault = faultCheck();
309310
310311
Serial.print("Temperature: ");
311312
Serial.print(T_I2, 1);
@@ -372,17 +373,200 @@ There are other functions in the main code listed below:
372373
- `EthernetInit()`: initialize the Ethernet connection for the Modbus TCP communication.
373374
- `onPwrChange()`: callback that controls the compressor power relay from the cloud.
374375
- `NiclaVibrationHAndler()`: manages the BLE connection and gather the vibrations alert from the Nicla Sense ME.
376+
- `faultCheck()`: compare the current sensor values with the fault defined threshold and report the state.
375377

376378
***You can download the complete code from [here]().***
377379

378380
### Nicla Sense ME Code
381+
You can download the code for the Nicla Sense ME [here]().
382+
383+
Let's go through some important code sections to make this application fully operative; starting with the required libraries:
384+
385+
- `Nicla_System.h` adds the support for the Nicla core and extended functionalities on power management.
386+
- `ArduinoBLE.h` enables the support for Bluetooth® Low Energy (BLE) communication, install it by searching for it on the Library Manager.
387+
- `Arduino_BHY2.h` provides the APIs for Nicla Sense ME board sensors.
388+
389+
Initial settings are defined specifying accelerometer samples, sampling frequency, sensor object and time control variables.
390+
391+
```arduino
392+
#include "Nicla_System.h"
393+
#include <ArduinoBLE.h>
394+
#include "Arduino_BHY2.h"
395+
396+
SensorXYZ accel(SENSOR_ID_ACC); // IMU sensor object
397+
398+
#define VIBRATION_LIMIT 2000 // vibration threshold
399+
400+
const uint16_t samples = 64; //This value MUST ALWAYS be a power of 2
401+
const double samplingFrequency = 512; //IMU sampling frequency Hz
402+
unsigned int sampling_period_us;
403+
404+
unsigned long vibration = 1; // variable to store the vibration status
405+
406+
// Alert Service
407+
BLEService alertService("1802"); // Immediate alert
408+
409+
// BLE Alert Characteristic
410+
BLEUnsignedCharCharacteristic alertLevel("2A06", // standard 16-bit characteristic UUID
411+
BLERead | BLENotify); // remote clients will be able to get notifications if this characteristic changes
412+
413+
unsigned long microseconds;
414+
long previousMillis = 0; // last time the vibration level was checked, in ms
415+
```
416+
417+
The Bluetooth® Low Energy services and characteristics are standardized for the specific use of this application. The service is defined as `Immediate alert (1802)` which makes it ideal for notifying on anomalous vibration events and an `alert level characteristic (2A06)`. Notice that they have specific and standardized Bluetooth® Low Energy UUIDs.
418+
419+
In the `setup()` function the different board peripherals are initiated including:
420+
421+
- Serial communication
422+
- Nicla system for power management and LED control
423+
- Onboard IMU sensor
424+
- Bluetooth® Low Energy (BLE) communication
425+
426+
In the Bluetooth® Low Energy initialization we define the device name, `Nicla` in this case for the Opta to easy find it.
427+
428+
```arduino
429+
void setup() {
430+
431+
sampling_period_us = round(1000000 * (1.0 / samplingFrequency));
432+
433+
Serial.begin(115200); // initialize serial communication
434+
while (!Serial)
435+
;
436+
437+
// run this code once when Nicla Sense ME board turns on
438+
nicla::begin(); // initialize library
439+
nicla::leds.begin(); // initialize LEDs support
440+
441+
nicla::setBatteryNTCEnabled(false); // Set to false if your battery doesn't have an NTC thermistor.
442+
nicla::enableCharging(100); // enable the battery charger and define the charging current in mA
443+
444+
nicla::leds.setColor(red);
445+
446+
BHY2.begin();
447+
448+
accel.begin();
449+
450+
// begin initialization
451+
if (!BLE.begin()) {
452+
Serial.println("starting BLE failed!");
453+
454+
while (1)
455+
;
456+
}
457+
458+
/* Set a local name for the Bluetooth® Low Energy device
459+
This name will appear in advertising packets
460+
and can be used by remote devices to identify this Bluetooth® Low Energy device
461+
*/
462+
BLE.setLocalName("Nicla");
463+
BLE.setAdvertisedService(alertService); // add the service UUID
464+
alertService.addCharacteristic(alertLevel); // add the battery level characteristic
465+
BLE.addService(alertService); // add the alert service
466+
alertLevel.writeValue(0); // set initial value for this characteristic
467+
468+
/* Start advertising Bluetooth® Low Energy. It will start continuously transmitting Bluetooth® Low Energy
469+
advertising packets and will be visible to remote Bluetooth® Low Energy central devices
470+
until it receives a new connection */
471+
472+
// start advertising
473+
BLE.advertise();
474+
475+
Serial.println("Bluetooth® device active, waiting for connections...");
476+
}
477+
```
478+
479+
In the `loop()` function we wait for the Bluetooth® connection and if it is connected will indicate it with a blue LED turned on. Every 1000 ms the vibration status will be measured calling the `updateVibrationStatus()` function.
480+
481+
```arduino
482+
void loop() {
483+
// wait for a Bluetooth® Low Energy central
484+
BLEDevice central = BLE.central();
485+
486+
// if a central is connected to the peripheral:
487+
if (central) {
488+
Serial.print("Connected to central: ");
489+
// print the central's BT address:
490+
Serial.println(central.address());
491+
492+
// check the vibration level every 1000ms
493+
// while the central is connected:
494+
while (central.connected()) {
495+
nicla::leds.setColor(blue);
496+
long currentMillis = millis();
497+
// if 1000ms have passed, check the vibration:
498+
if (currentMillis - previousMillis >= 1000) {
499+
previousMillis = currentMillis;
500+
updateVibrationStatus();
501+
}
502+
}
503+
nicla::leds.setColor(red);
504+
Serial.print("Disconnected from central: ");
505+
Serial.println(central.address());
506+
}
507+
}
508+
```
509+
510+
The `updateVibrationStatus()` function averages the samples taken and if the vibration magnitude is above the defined limit it will notify the Opta sending a Bluetooth® message.
511+
512+
```arduino
513+
void updateVibrationStatus() {
514+
/* Read the power management IC registers to retrieve the battery percentage
515+
*/
516+
microseconds = micros();
517+
for (int i = 0; i <= samples; i++) {
518+
519+
vibration += abs(accel.x());
520+
521+
while (micros() - microseconds < sampling_period_us) {
522+
//empty loop
523+
BHY2.update();
524+
}
525+
microseconds += sampling_period_us;
526+
}
527+
528+
vibration = vibration / samples;
529+
Serial.println(vibration);
530+
531+
if (vibration >= VIBRATION_LIMIT) {
532+
alertLevel.writeValue(0);
533+
} else {
534+
alertLevel.writeValue(1);
535+
}
536+
}
537+
```
538+
539+
***You can download the complete code from [here]().***
379540

380541
### Arduino Cloud Dashboard
381542

543+
Taking advantage of the Arduino Cloud, we can seamlessly integrate a simple but powerful dashboard to monitor and visualize the status of the system in real-time:
544+
545+
![Arduino Cloud Dashboard]()
546+
547+
Within the Arduino Cloud's dashboard, the system variables can be monitored with the following widgets:
382548

549+
- ON/OFF compressor power switch widget.
550+
- System variables gauges showing temperature, pressure and power.
551+
- Line charts for historical review on variables behaviour.
552+
- Vibration and fault state alert widgets for easy understand of the compressor state.
553+
554+
We can easily access this dashboard from a PC, mobile phone or tablet from anywhere, receiving an instantaneous update wherever we are.
555+
556+
In addition, we can set different integrations to complement our project, for example, forward the dashboard data to an external service using **Webhook**, **IFTTT** automations and **Smart Home** integrations.
383557

384558
## Full Compressor Monitoring System Example
385559

560+
All the necessary files to replicate this application note can be found below:
561+
562+
- The complete code can be downloaded [here]()
563+
386564
## Conclusion
387565

388-
### Next Steps
566+
In this application note we have learned how to implement an industrial assets monitoring system turning a conventional air compressor into smart. This application could be a simple demonstration of how Arduino's environment simplifies de workflow for developing smart solutions to solve real industrial needs. The Arduino PRO products line is a perfect fit for developing robust and reliable projects for the industry. We covered in-site sensor data sampling, Bluetooth® Low Energy communication, and real-time Cloud monitoring.
567+
568+
### Next Steps
569+
570+
As you already know how to develop a smart air compressor monitoring system with the Opta PLC and the Nicla Sense ME, it's time for you to continue exploring all the capabilities of the Arduino Pro environment to integrate it with your professional setup and improve it with powerful solutions.
571+
572+
You can take this solution even further with the integration of an **FFT** algorithm for the Nicla Sense ME so it can analyze vibration specific spectrums.

0 commit comments

Comments
 (0)