An electronics box prototype to track missing cargo during lorry transport. This was implemented by the Sustainable Living Lab (SL2) at the Raitong Organics Farm in Northeastern Thailand. The whole process from ideation, iterative development, testing and deployment spanned about two weeks, including three days at the Raitong Farm in Thailand.
About 5 out of 750 boxes of packaged rice occasionally goes missing during the weekly 10 hour lorry journey to the sea port in Bangkok. This was affecting the farm’s financial bottomline as well as harming its reputation with clients. Due to strict security measures at the sea port, it was ruled out that the boxes went missing at the port.
It was suspected that the thieves carefully removed the tarp and put it back after removing a few boxes at a location where the truck stopped for a while, somewhere during the lorry journey. The farm needed proof of this.
IdeationSL2 came up with the idea of using a GPS system combined with Radio Frequency Identification (RFID) tracking of tags placed on the boxes. The reason why we chose RFID was that the tags were cheap enough, in the order of a few cents per tag, to be “fire and forget”, and we needed a lot of these. Also, we had to pick the UHF frequency range, which has a detection range of up to 10m, because the usual RFID that we are familiar with, which is in the KHz frequency range, only had a range of a few centimeters. The cargo truck measured 6m in length, 2.45m in width and 2m in height.
The theory was that once any of the boxes goes out of range of the RFID reader (a couple of metres), it could be assumed that the box was being stolen. Once this happened, a Short Message Service (SMS) alert would be sent out indicating that particular time and location. The mobile GSM system also allowed real time commands to be sent via SMS to the electronics box to ask for updates. In addition, all tracking activity would be logged onto a micro SD card for post-mortem data analysis.
Selecting the ComponentsRFID Reader
We picked the SparkFun Simultaneous RFID Reader - M6E Nano whose specifications fit our requirements, having a range of 4.5m. SparkFun has a tutorial on how to use this reader, and even provided an Arduino library, called the “SparkFun Simultaneous RFID Tag Reader Library." How useful! We also got a heatsink for the reader since it can get hot pretty fast. It is not recommended to run scanning for more than ten minutes since the reader will auto-shutdown if it reaches 85 deg Cel.
UHF RFID Antenna
The UHF antenna was a generic one, which we bought it directly from a RFID technology company in Singapore called Tracknet Id located at Woodlands. Interestingly, this UHF RFID antenna cannot be bought in any physical shop in Singapore, nor is it easy to buy on short notice online, being sold out on the SparkFun store. The RF cable connections were a little tricky. First there was a 10cm u.FL to SMA adaptor from the reader which has to be connected to a 3m long SMA to TNC RF cable which connects to the antenna. We had to make sure the male and female connectors matched. We managed to get a range of 4.5m for detection of the RFID tags at max power and clear line of sight with no obstruction. We read that UHF RFID is blocked by metal and water, which includes human bodies, so if you put an RFID tag in your hand and cover it, there is a chance that the antenna will not pick it up. There is also a safety distance of 21cm from the antenna during operation according to FCC guidelines due to radiation. UHF antennas also interfere with one another, so make sure that their detection fields do not overlap.
SIM Module with GPS
The GSM SIM5320e 3G has both GPS as well as GSM capability. You can make calls and SMSes to this module if you insert a valid prepaid SIM card and hook up a speaker and mic. It can also locate itself using the GPS satellites. So it has two antennas, one for GSM and one for GPS. As with most Arduino compatible accessories, you can search for information about this component online. There is this nifty YouTube video on how it can be used to track stolen vehicles, which is a somewhat similar use case to ours! There is also this helpful starter guide which explains on how you can program the SIM5320 with AT commands directly over the serial port. Best of all, Adafruit has a tutorial and a special library for this component called the ‘Arduino Fona 3G library’! The library is essentially a wrapper around the AT commands and has a bunch of error checking utilities and multi-command routines to make it easier to program the SIM5320. It also converts the raw longitude latitude output of the GPS data which is in something called NMEA format (e.g. 0117.093867 N,10350.701970 E) into Decimal Degrees (e.g. Decimal degrees (DD): 41.40338, 2.17403) which can be directly input into Google Maps. It is interesting to note that the NMEA data also includes velocity (including direction) and time, extremely useful for our use case. We can know how fast the truck is moving or whether it is stationary at any point in time! Coming back to the Fona 3G library, considering that the document for the SIM5320 AT Commands runs into 550 pages, this library removes the need to figure out the AT commands you need by abstracting it into self-explanatory function calls such as getGPS() and getSMS(). Very useful!
A side note about the GPS antenna - it has the interesting property of being magnetic, which means that it sticks easily and securely on the roof of any vehicle. Do note that the antenna has to be oriented correctly to point upwards to the sky for best results. Do also note that in urban areas, it can take anywhere between 5 to 20 min to get a GPS fix from cold start, due to buildings interfering with the signal. At the Raitong farm in Thailand, it was clear open sky, and the first GPS fix came in almost immediately at around 1 min or less. In Singapore, even when positioned near a window, it is not guaranteed that a GPS fix can be obtained at all. If there is no GPS fix within 20 min, you can assume that you need to move to a more open area away from tall buildings.
SD Card Module
We bought a generic Arduino compatible microSD card reader and used the inbuilt Arduino ‘SD’ library, modifying the ReadWrite example program to suit our needs.
Block DiagramSparkFun RFID Library Limitation
After exploring all the examples in the SparkFun RFID library, I discovered that there was no library function to count the number of unique tags within the antenna’s tracking range. What was happening was that the reader was randomly reading all the tags in random order, so for a particular tag that was nearer to the antenna could be read multiple times while a tag that was further away would only be read once. Since the reader could read up to 150 tags per second, in theory, it should be able read all the tags within the antenna’s range at least once. So I came up with a simple algorithm that would use an array to keep track of the number of unique tags read. If the current tag number is not in the array, it is a new tag, so add it to the array. If it is already in the array, skip this tag and read the next tag. Do this for a few seconds to ensure all tags are read at least once.
I was not sure if this would work, so I posted my hypothesis to both the SparkFun forum and Arduino forum. The Sparkun forum answered one day later and was immediately helpful, even providing the entire implementation of the code for my hypothesis. The Arduino forum replied four days later and was not very helpful but I thanked the person anyway.
In Thailand, I tested the code for 70 tags and lo and behold, all 70 unique tags were read within 10 seconds! Thanks to the open source community!
A side note related to this issue is the difference between EPC and TID numbers for each RFID tag. EPC stands for Electronic Product Code and is a 12 byte number meant to identify the category of product, e.g. a milk carton, eggs, whereas the 20 byte TID or Tag Identification number is a 20 byte number which is truly unique for each RFID tag. The library function created only reads the EPC but not the TID, and there does not seem to be an easy way to read multiple TID tags simultaneously, based on the available functions in the library. Luckily for us, Sparkfun randomises the EPC numbers on their tags, so there is only a 2^96 chance of two tags having the same EPC number, which means the probability is almost 0 (12 bytes x 8 bits = 96 bits), and we can ignore this issue.
UHF RFID Blocked
UHF RFID is blocked by metal and water, including human bodies. After testing the UHF RFID detection range with cartons of rice at the Raitong farm, we realised to our disappointment, that the antenna could only detect tags behind a SINGLE box. Anything more than one box placed between the tag and the antenna, and the tag could not be picked up. This is a problem, since the boxes were stacked 8 or 9 high, by 6 wide and 15 in length, and the antenna needed to be able to penetrate at least 6 boxes in order to track all the boxes at the last vertical layer the back of the truck. This was assuming that the boxes would be stolen from the back of the truck since the sides of the truck had metal railings 2m high, whereas the metal railing was only about 0.6m high at the back.
We found out from Bryan that the rice had 14% moisture, so the water content could be interfering with the signal. Apart from the awful detection range of the antenna, there were also other factors that could complicate things. For example, how and where could we secure the antenna since the boxes were densely packed with no space inbetween? Would the metal flooring and railings of the truck interfere with the signal? Would the human thief be able to block the antenna inadvertently since human bodies block UHF RFID? Also, the detection lobe of the antenna is rather limited. What if the boxes were stolen from the top instead of the back of the truck?
We decided to scrap the RFID idea, so it was back to the drawing board for us. The next best idea was to install a Raspberry Pi computer with webcam, but we ran out of time to implement this. We resorted to a simple trick - using a tripwire. We would rig a couple of strings over some of the boxes. If any of the boxes were moved, the tripwire would trigger, and an SMS alert sent out indicating the time and location.
The block diagram for the actual deployed box looked like this:
Data Logging
The datalog.txt file would record all GPS data at every 30 second interval, including position, speed and time. The log file would also report the status of the tripwire and note where the truck was stationary for more than 3 min.
SMS Interactivity
The system recognises only one command sent via SMS which is “Loc”. It will then send back a status string, including the number of SMSes left, whether the tripwire has activated, the date, time, speed and google maps link to its current location.
The system will automatically send out an SMS alert when the wire has tripped and when the truck has been stationary for more than three minutes.
Truck Tracking
No boxes were stolen during this particular journey although we discovered some interesting things. For one, the truck took a longer time than expected - about 14 hours instead of the 10 hours promised by the transport company. We found out that the truck stopped for a long time at certain places, for up to 1 hour. This was not normal.
Also, the tripwire indicated to us that some of the boxes got loose during the journey since the top layer of boxes was not a complete layer. This is good feedback so that it can be ensured that the top layer of boxes should be securely fastened the next time.
Bryan from the Raitong farm was grateful to us for the prototype and attempting to find proof of stolen cargo. We also learnt from this trip about teamwork and improved our technical knowledge.
Future ImprovementsTamper-Proof Box
Since the thieves would be able to see the box, they might attempt to tamper with it. The box should be securely locked and is only be able to be opened by a key or password. The box should be permanently sealed and all access to the internal components should be via exposed ports on the outside of the box. This includes charging ports for the phone banks and reading from the SD card.
Raspberry Pi with Webcam
We did not have time to implement the next best idea which was to have a Raspberry Pi connected to a webcam. We could set up the RasPi to talk to the Arduino easily, each controlling different components, since the Arduino handles the SIM5320 very well, and the RasPi can handle the data flow from the webcam. The idea would be to add another SMS command to ask the webcam to send a low res image of whatever it sees at the back of the truck. The box could also automatically send out an MMS of the low res pic whenever the truck is stationary for more than X minutes.
APPENDICESA. Power Calculations
Note: Each of the following three components is connected to a dedicated 10000mAh power bank with a 2.1A max current draw rating. Each power bank has to last for more than 10 - 12 hours for the truck journey.
RFID Reader
It has a peak power draw at 3.6W, or 0.72A at 5V while scanning at max power of 27.0dB. Using a 10000mAh (or 10Ah) power bank with 5V output, the power bank can output 0.72A for 10Ah/0.72 = 13.9 hours. But it will not be scanning continuously due to overheating. So we programmed it such that it scans for max 20s per min, or 20min per hour. So the power can last for 13.9/0.33 = 41.7 hours.
GSM SIM5320e 3G with GPS Antenna
Sending SMSes can draw up to 2A from the power bank. This means that the 10Ah power bank can last for 5 hours which translates to 3600 SMSes, assuming each SMS takes 5 sec. In comparison, we would not have hit anywhere near 500 SMSes during the 10-12 hour journey. Assuming 500 SMSes at 5 seconds each, it will draw 2A for 0.7 hours, which is 1.4Ah. The power left from the power bank would be 10Ah - 1.4Ah = 8.6Ah. Assuming 100mA constant current draw for the GPS, which is conservative, the power bank can last for 86 hours.
Arduino Mega with microSD Card
Assuming a constant current draw of 200mA, which is conservative, the 10Ah power bank can last for 50 hours.
B. Software Code
First version created in Singapore with working SD card, GSM and GPS. See README for all Arduino pin and wiring connections. No RFID. (link)
Actual deployed version with tripwire and SMS interactivity. No RFID. (link)
Useful test program for RFID range testing and tag counting (link)
Useful test program for GSM SIM5320 module, including SMS and GPS (link)
Comments