Wearable sensors are an emerging market that is rapidly gaining recognition in the global market, especially in the industrial sector.
Raspberry Pi based PLC family offers a wide range of possibilities to control and monitor this innovative technology.
In this post, you will learn how to take a picture using a USB camera when a load cell detects a specific value, controlled by an industrial Raspberry Pi PLC and monitoring it using Node-RED.
1x Weight Sensor
1x HX711 Load Cell Transmitter Module
1x USB camera
1x Raspberry Pi industrial PLC See the product >>
Connect the hardware as shown below to proceed with the software:
Weight sensor setup
1. First, let's clone a project that contains an example file which shows a function of the library. So, open up a terminal window in your Raspberry Pi PLC controller and type the following:
git clone https://github.com/tatobari/hx711py
2. Once the repository was cloned, a directory named hx711py will appear with the file named example.py. So, go to that file to adjust some changes:
sudo nano example.py
3. Inside the file, let's modify some lines, so that the code looks as follows:
#! /usr/bin/python2 import time import sys EMULATE_HX711=False referenceUnit = -1 if not EMULATE_HX711: import RPi.GPIO as GPIO from hx711 import HX711 else: from emulated_hx711 import HX711 def cleanAndExit(): print("Cleaning...") if not EMULATE_HX711: GPIO.cleanup() print("Bye!") sys.exit() hx = HX711(25, 2) hx.set_reference_unit(referenceUnit) hx.reset() hx.tare() print("Tare done! Add weight now...")
def func(): while True: try: val = hx.get_weight(5)
hx.power_down() hx.power_up() time.sleep(0.1) except (KeyboardInterrupt, SystemExit): cleanAndExit() function = func() for i in function: print(i)
4. Once the code was modified, exit with Ctrl + X, type 'Y' to save the file with the same name and Enter.
Test the Raspberry scale
1. For a correct calibration and to be able to get the right weight, you need a comparison object whose weight you know. It is recommended to choose an average value of the maximum the load cell can get. For example, if your weight scale can get up to 20 kgs, then it is recommended to choose an object whose weight is 10 kgs.
2. First of all, you need to comment the next line as follows:
3. And then, place the object on the scale and run it with the following command:
sudo python example.py
4. Your will see that the displayed values will be both positive and negative. In this case, they are displayed at 24500 values around -22200. So we referenced the values like:
−22200 ÷ 24500 = -0.9
5. After getting that value, go back to the line we commented on earlier, and uncommented it removing the hashtag, and typing the value you got as a reference unit like:
referenceUnit = -1