When you wake up in the morning first thing you search is an alarm clock to shut that thing down so that you can procrastinate another 5 to 10 min or wake up and get ready if you follow time strictly. The typical day starts with all the daily tasks such as having coffee, having bath, breakfast etc. Have you noticed or counted a number of things you use after getting up from the bed? It's a lot. All these things or gadgets aren't homemade. These are made in a factory or in a mass manufacturing facility nearby or maybe outside country. ( Or even outside our planet i.e if we start living in Mars, Haha Jk.) Think about these machines working tirelessly just to produce enough products to meet weekly deadlines to enjoy weekends or just Sundays or not even that in some factories working 24x7x365. These machines need services on regular basis otherwise they might start to annoy the owner with noises, squeaks etc. Or might even stop working someday. To maintain the health of our tireless machines we should monitor their health regularly. This will even help in predictive maintenance of machines through which we can schedule regular services and we can even tell when the machine will break down beforehand. This can save a lot to a factory producing millions of units of products such as enclosures, wires or injection moulding units etc. Imagine a situation where in which a company having 100 machines manufacturing some plastic enclosures faces a sudden breakdown of 10 machines. The number might be less but will cause damage to 10% of the overall production of that day. If an IoT device on these can tell you about the health of machine and can warn you about the breakdown date and suggest service day for machines? It would be awesome right. Yes, In this project we'll make use of NXP's Rapid IoT device to this predictive maintenance only with the help of some basic sensor parameters. We will use the following sensors from the device: 1. Motion sensor to detect vibration patterns 2. Temperature sensor 3. Light sensor 4. Gas sensor to detect safe levels.We'll set the interval to 0.5s
Vibration data is very important because through vibration data we can get following information,
1. Machine status i.e ON or OFF
2. Machine process status i.e which process is going on
3. Production rate i.e just by analysing the data production rate
4. Predictive maintenance through the variation in vibration patterns due to loose or worn out parts.
From first 3 we can derive power consumption, number of products produced etc. which will help in converting old machine to digital machine without really investing on machine.
Predictive maintenance will help in scheduling the service days of machine for smooth industrial operation
Mounting screws provided on the Rapid IoT device is helpful in mounting machines.
Note: Please Don't use double sided tape or foam tape as it suppresses vibrations.
Here we will use
vibration i.e Z axis data of accelerometer sensor,
Light sensor to detect light levels and
Gas level for detecting leakage in an industrial environments.
The project looks like this
To upload this firmware on the rapid IoT device you need to connect the device to your PC, press button 3 and then press the reset button behind the device. After this the device will be detected in your PC. Now you can download the firmware directly to Rapid IoT device. It will reboot and now you can see the values on the device. Values displayed on the device will be just for reference as it will be fixed mounted on the machine after which data may or may not be visible. That's why we will connect Raspberry Pi to send this data to cloud.
Since Raspberry Pi 3 comes with bluetooth we can easily pair our device with it and start receiving data on Pi. After turning on the bluetooth from GUI or command line you can start scanning by the following commands.
$ sudo bluetoothctl [bluetooth]# scan on
This will enable bluetooth search and will list the number of devices
Discovery started [CHG] Controller B8:27:MA:78:1D:EC Discovering: yes [NEW] Device 00:60:37:0A:AF:3F PAF3F [CHG] Device 00:60:37:0A:AF:3F RSSI: -65
After the it has found your device you can pair with the device through following command
[bluetooth]# pair 00:60:37:0A:AF:3F
After it gets paired it starts sending the data of all the parameters we have enabled through our firmware in Rapid IoT Device along with thier UUIDs. We will have to note down this UUIDs of each data like temperature data etc. for further processing.
Now we have set up a connection form the Raspberry Pi to the Rapid IoT device via bluetooth. Now using a Python script we will store the values on a data base. If you just want to test you can even use the values from the Rapid IoT Dashboard. There also you have an option to store the values through.csv file.
First we need to install docker to install r studio on Raspberry Pi.
$ curl -sSL https://get.docker.com | sh $ sudo service docker start
After the successful installation of docker we will have to install R studio image on docker. This image is called rocker.
Why R language?
Because its powerful and easy to operate and gives wonderful data visualizations
and most important is it is opensource.
Install rocker using following command
$ docker pull rocker/rstudio
Otherwise you can even install R studio on your PC where the data analytics and further processing is done. Because R running on Raspberry Pi might be slow due to computation limitations of pi.
You can directly send the data to a.csv file or you can install influx DB and visualize the data in tools like grafana. Former method will be directly opening a.csv file and start writing the 4 values with respect to timestamp and latter will store the same in data base for realtime visualization. I would suggest Influx DB method for remote operations.
There's a nice interface to Python and BLE by IanHarvey called bluepy
Commands for Influx DB:
$ sudo pip3 install bluepy influxdb
You can install grafana from gonzalo123's iotgrafana by executing following commands.
$ sudo pip3 install docker-compose $ git clone https://github.com/gonzalo123/iot.grafana.git && cd iot.grafana $ docker-compose up
After the installation Influx DB and Grafana will be available at following links on browser:
http://raspi ip address:8086 - Influx DB
http://raspi ip address:3000 - Grafana
Raspberry Pi script to save data to.csv
Here I will show how we can use tidyverse, datasauRus and lubridate libraries to visualise the data collected by our rapid Iot Device. Please find the attached.csv file which is data generated by the device. Here we have data of cable length manufactured by the 2 machines of different locations. The cable length is being calculated by the ON OFF time of machine using vibration data analysis. It contains 24 hours of data.
Following code will generate the graphs shown below.
# "cable_vendor_data_with_timestamp.csv" %>% read_csv() %>% View() "cable_vendor_data_with_timestamp.csv" %>% read_csv() %>% pull(vendor) %>% unique() # Plot a histogram "cable_vendor_data_with_timestamp.csv" %>% read_csv() %>% ggplot(aes(x = cable_length_in_cms, fill = vendor)) + geom_histogram(binwidth = 0.1) + geom_vline(xintercept = 10, color = "red", linetype = 2) "cable_vendor_data_with_timestamp.csv" %>% read_csv() %>% mutate(year = ts %>% year()) %>% mutate(month = ts %>% month()) %>% mutate(day = ts %>% day()) %>% mutate(hour = ts %>% hour()) %>% mutate(minute = ts %>% minute()) %>% mutate(second = ts %>% second()) %>% mutate(day_of_week_num = ts %>% wday()) %>% mutate(day_of_week = ts %>% wday(label = TRUE)) %>% # filter(hour != 3) %>% ggplot(aes(x = cable_length_in_cms, fill = vendor)) + geom_histogram(binwidth = 0.1) + geom_vline(xintercept = 10, color = "red", linetype = 2) + facet_wrap( ~ hour, nrow = 6, ncol = 4)
Here I have written a Pyhton code to send an alert when machine experiences weird vibrations due to damage or wear and tear. A threshold value is set so that once the threshold crosses email will be sent to the concerned engineer or owner.
Which makes the project ICense complete industrial IoT system.