Container shipping is a common transport medium. In fact, 80 percent of international trade in goods is carried by sea. Containers are large and reliable, offering a standard size that makes them portable between ships, trains, and trucks.
However, the loss of items transported via containers is not an uncommon problem in the shipping industry. The good news is that it’s possible to track shipped items using a simple electronic solution.
In this project, we’ll design an Arduino-based electronic tracking system for container shipments. This embedded circuit uses Arduino, LDR and IR sensors, and a real-time clock. The system works by tracking each time a container is opened and items are removed from it. By tracing these factors, it’s easy to detect when items from the container were moved, and potentially misplaced or stolen.
1. Arduino UNO x1
2. LDR sensor x1
3. DS1307 RTC x1
4. IR sensors x2
5. Breadboard x1
6. Connecting or jumper wires
To track the exact time a container is opened and shipped items moved from it, we’ll need a few devices.
- To track the time, a real-time clock — the DS1307 is interfaced with Arduino.
- To detect if a container is opened, an LDR sensor is also interfaced with Arduino.
- To detect the movement of the shipped items, a pair of IR sensors are required.
Here’s how it works. The RTC DS1307 has six terminals: the 32K, SQW, SCL, SDA, VCC, and GND. It’s interfaced with Arduino by using the I2C interface. The DS1307’s VCC and GND pins are connected to Arduino’s 5V supply and ground pins, respectively.
The RTC module’s SCL and SDA pins are connected to one of Arduino UNO’s I2C ports.
The LDR sensor has three terminals: the VCC, GND, and OUTPUT. The VCC and ground are connected to Arduino’s 5V DC and ground. The LDR’s OUTPUT pin is connected to Arduino UNO’s analog input pin A0.
The IR sensors have three terminals: the VCC, GND, and OUT. The VCC and GND pins are connected to Arduino’s 5V DC and ground. The IR sensors’ OUT terminals are connected to Arduino’s digital I/O pins 2 and 3, respectively.
Arduino sketch 1
Arduino sketch 2
How it works
To begin, set the current time using the real-time clock DS1307 and start the clock by using Arduino sketch 1. Once the RTC starts, it keeps the time — so long as it stays powered by a coin battery.
Next, the RTC is ready to interface with the shipment’s tracking system and can be installed inside the container. The LDR sensor uses the light to note whenever the container is opened (as, otherwise, it’s dark inside).
The sensor’s analog output rises in response to incident light and can be calibrated to output a certain voltage in the light. Its analog output voltage remains low in the dark due to increased resistance.
To do so, the LDR sensor is adjusted in the circuit using the onboard pot to give a zero analog reading in the dark and a reading above 700 in the light. When the container is opened, the sensor’s analog output rises. If it reaches above 100, the current time is read from the RTC module, and a message that notes this time is sent serially. This message can also be stored on an SD card or in a logging system.
There are two IR sensors connected within the circuit. The pair is installed at the entrance of the container. When a shipment is moved out of the container, IR sensor 1 detects the obstacle in its path. Then, IR sensor 2 also detects the obstacle in its path.
Arduino is only programmed to react if IR sensor 2 detects an obstacle after IR sensor 1. If this occurs, a message with the time of this movement is sent serially. This message can also be stored on an SD card or in a logging system.
Arduino sketch 1 is used to save time in the RTC module. It begins by importing the Wire and DS1307 library. Here’s the library that’s used in this project:
Link to DS1307 Zip Library: DS1307
Here are the functions of sketch 1:
- An object of the DS1307 is initialized, which is named rtc.
- In the setup() function, the baud rate for serial communication is set to 9600.
- The RTC module is initialized by using the rtc.begin() method.
- The current time is set in the RTC by using the rtc.set() method.
- The RTC begins the clock by using the rtc.start() method.
- The current time is set in the RTC module, which continues to track it.
Now, it’s ready to be used in the container’s shipment tracking system. Arduino sketch 2 is, then, loaded in the Arduino UNO to run the system. The sketch begins by importing the Wire and DS1307 library.
Here are the functions of sketch 2:
- An object of the DS1307 type is initiated and named rtc.
- Five variables of an 8-bit integer type are declared for storing the second, minute, hour, day, and month.
- A variable of the 16-bit integer is declared for storing the year.
- The pins that interface the LDR and IR sensors are defined as constants.
- The getTimeStamp() function is defined to receive the current time from RTC module. This function begins by calling the rtc.get() method to get the current time (in the second, minute, hour, day, month, and year variables).
- The current time is sent to the serial port in the appropriate format with the suitable strings padded around.
- The setup() function calls two methods: the Serial.begin() to set the baud rate for serial communication to 9600 and the rtc.begin() to initialize the RTC module.
- The loop() function tests the status of the LDR sensor. If the LDR sensor’s analog output is greater than 100, a message noting that the container is being opened is transmitted serially. It also confirms that IR sensor 2 is activated after IR sensor 1.
If IR sensor 2 is activated, a message that a shipped item is being moved out of the container is transmitted serially. (As the IR sensors have an active LOW signal, the sketch also checks their output for a LOW logic.)
Filed Under: Arduino, Electronic Projects