Skip to main content
Integrations 7 min read

How to create an IoT device for an asset tracking map

How to create an IoT device for an asset tracking map

Internet of Things is one of the most sought-after technology today. It is involved in almost every sector, from agriculture, energy, finance, healthcare, manufacturing, retail, hospitality to transportation, and logistics. IoT has brought a revolution in all sectors by allowing businesses to generate more value and also providing end-user better services.    

Today's blog will show you how to create your own IoT device to capture location data and temperature data.

What you need

The use case is about sending temperature and location data to a cloud from anywhere in the world using cellular communication, there are different components required to make it work.

Hardware component -

  • Arduino MKR GSM 1400 board - This board handles computation and communication. It has a Cortex-M0+ 32Bits micro-controller, USB Serial port for development and debugging, and a pre-integrated cellular modem compatible with global 2G and 3G GSM networks.
  • 3G GSM Antenna with U.FL connector - Antenna improves the range of cellular communication on Arduino board.
  • Arduino MKR GPS shield - The low-power Global Navigation Satellite System receiver shield based on the u-blox SAM-M8Q GNSS for georeferenced projects. It connects easily with Arduino MKR family boards.
  • A LiPo battery pack - Helps in handling the power surges during cellular communication. The battery should be at least 2500 mAh since GSM handshake could easily reach a 2A peak(USB port can provide 500 mA at max). 
  • Micro-USB cable - Required for programming the Arduino board and troubleshooting.
  • LM35 Temperature sensor -A precession Integrated circuit Temperature sensor, whose output voltage varies, based on the temperature around it. It can measure temperature anywhere between -55°C to 150°C.
  • Breadboard and wires - For making connections to build the devices
  • A SIM card - An activated SIM card with data on it for sending data to the cloud using cellular communication.

Software app  -

  • Arduino Desktop IDE - An integrated development environment to write, debug and upload the code on Arduino MKR GSM board.

Hardware setup

For this part, you do not need U.FL antenna, LiPo battery, and SIM card as we are not going to send data to the cloud. Then what are we going to do today? We are building an IoT device that collects temperature and location data with the help of GPS shield and LM35 temperature sensor.

The communication between the Arduino board and GPS shield will be I2C.  For that connect Arduino MKR GSM 1400 and GPS shield with the help of I2C connector cable provided with Arduino MKR GPS shield in the box. This cable is an extension of the I2C bus and it has a 5-pin connector. 

Next, we need to connect LM35 temperature sensor with Arduino for collecting temperature data. 

LM35 is an analog sensor with 3 pins, namely, VCC, GND, and Analog Out. Where VCC will connect with 5V, Ground to ground, and Analog Out to A0 analog pin of Arduino MKR GSM 1400.

For making above mentioned connections, you will require a breadboard and three male-male connection wires.

Software setup

To program MKR GSM 1400 offline you need to install Arduino Desktop IDE and add the Atmel SAMD Core to it. Once installed, open the Arduino IDE, select Tools menu, then Boards, and last Boards Manager

Here, search MKR GSM to find the core. Click on its box and click on the install button. On the bottom bar of the window, you can follow the download and install procedure, including the installation of the proper driver, needed by the operating system to use the board.

Next, from Tools select the board Arduino MKR GSM 1400 and then the port labeled as the same name. 

The MKR GPS Shield is connected through Serial1 to the MKR Board or through I2C / DCC protocol on the 5 pin connector. To make use of it, you need to include "Arduino_MKRGPS.h" in your code. To get this file, you need to click on the Sketch menu, then Include Library, and lastly Manager Libraries.

In the new popped-up window, search 'MKR GPS' and install it.

Your Arduino Desktop IDE is ready for Arduino MKR GSM 1400 board and MKR GPS shield.

The sketch

The first code section is used to include the libraries required by our application.

The Arduino_MKRGPS.h includes all the GPS functionalities and we are going to use latitude, longitude, altitude, and number of satellites for our example.

Copied
        
#include 

// For LM35
int sensor = A0; //Change the value as per your connection (A0,A1,A2,A3,A4,A5,A6...)
float tempc;
float svoltage;

void setup() {
  Serial.begin(9600);  //Initialize serial
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo native USB port only
  }
  if (!GPS.begin()) {
    Serial.println("Failed to initialize GPS!");
    while (1);
  }else{Serial.println("GPS is working");}
}

void loop() {
  float xval = analogRead(sensor); //Output of ADC in decimal format
  svoltage = (xval*3300.0)/1023;  //Sensor output in mVolts
  tempc = svoltage/10; //Conversion factor - Datasheet
  
  if (GPS.available()) {
    // read GPS values
    Serial.println("-----GPS Available-----");
    float latitude   = GPS.latitude();
    float longitude  = GPS.longitude();
    float altitude   = GPS.altitude();
    int   satellites = GPS.satellites();
 
    Serial.print("Latitude: ");
    Serial.println(latitude, 7);
    Serial.print("Longitude: ");
    Serial.println(longitude, 7);
    Serial.print("Altitude: ");
    Serial.print(altitude);
    Serial.println("mtrs");
    Serial.print("Number of satellites: ");
    Serial.println(satellites);
    Serial.print("Temperature in degree celsius: ");
    Serial.println(tempc);
    Serial.println();
    delay(2000);
    } 
  }

  

In the above code, we are acquiring longitude, latitude, altitude, and the number of satellites from the MKR GPS shield and also temperature data from LM35; and printing it on the Serial Monitor. 

Upload the sketch on the board by clicking on the Upload button. Then open Serial Monitor. Make sure you have selected 9600 baud as baud rate at the bottom right of the Serial Monitor.

You will get the data printed on Serial Monitor from the MKR GPS shield and LM35 as shown above in the diagram.

Conclusion

In this part, we have built a basic IoT device collecting temperature and location data. In the next part, we will send data from an IoT device using cellular communication to the cloud. 

 

Vidhan Bhonsle

Vidhan Bhonsle

Have your say

Sign up for our newsletter

Why sign up:

  • Latest offers and discounts
  • Tailored content delivered weekly
  • Exclusive events
  • One click to unsubscribe