LTE 4G Sensor Using a SIM7000
by JonMackey in Circuits > Arduino
9572 Views, 58 Favorites, 0 Comments
LTE 4G Sensor Using a SIM7000
This device is used to monitor multiple temperature sensors and report out of range conditions to your cell phone via SMS.
I wrote all of the software used in this project except for the 1-wire bus code and the standard Arduino code.
Things you may be interested in even if you have no interest in a 4G temperature sensor:
- The code that communicates with the SIM7000 using GSM AT commands is non-blocking.
Non-blocking code allows your UI to be more responsive. - The SMS code uses PDU mode rather than the more common text mode.
- Most of the device configuration is set via SMS messages sent from your phone.
- The display code can display any font at any point size.
If you’re interested in building this project, the bare boards and parts list is available on PCBWay.
The code for this project is on GitHub.
As noted, the cell modem used is a SIMCom SIM7000. The SIM7000 has many features, including voice and GPS. Only the SMS functionality is used in this project.
I’m not going to go into any detail on how to assemble the board. I’ve published several instructables that contain the steps needed to assemble a board. If you actually attempt to build this project and have questions, just send me a message (rather than a comment.) This instructable will describe how critical parts of the project work, how to operate it, and how to assemble the case.
Boards
This project is made up of 4 boards.
- 4G LE Sensor - A 60x70mm board containing the microcontroller, SIM7000, UART, and battery charger.
- Display - A 35x35mm board containing a 240x240 1.3 inch color TFT ST7789 display.
- 5 button - A 35x34mm board containing 5 buttons in a cross pattern.
- 4 port RJ11 - A 20x60mm board used to connect up to 4 DS18B20 temperature sensors using telephony RJ11 4P4C connectors.
The 4G LE sensor board’s connection to the SIM7000 is roughly based on the reference design found in the SIM7000 hardware design document. The mcu is an ATmega644PA. The display and 5 button boards are boards I designed for other projects that meet the minimal requirements of this project. All of the boards connect to the main board using 1mm pitch flat cables.
My original design for the 4G LE Sensor board used four 2.5mm audio jacks to connect the temperature sensors. I decided to move these connections to a separate board that uses RJ11 connectors to make it easier to integrate into the case. An advantage of RJ11 connectors is they eliminate the possibility the signals will be shorted when when connecting the sensor.
As noted, the AVR microcontroller is an ATmega644PA running at 3.3V, 8MHz. This microcontroller has two serial USARTs, one SPI interface, and one I2C interface. The display is connected to the SPI bus. One of the serial USARTs is connected to a USB to TTL serial chip, the other connects to the SIM7000. The I2C interface isn’t used but is exposed if needed. SPI sensors could be added by using the pins on the board’s ICSP connector. All of the unused ATmega644PA pins are exposed via headers. The SIM7000’s USB port is also exposed for future use.
Even though the board's serial USB connection logs most of the SIM7000 communication activity, it doesn't capture all of the traffic. The SIM7000 serial traffic can be monitored/debugged using the 3 pin header labeled SIM7000 UART. This header is on the 3v3 side of the TXB0104 level shifter. The protocol used with the SIM7000 in this project uses serial XON/OXFF. This data is not part of the log. Also, any buffer corruption that has occurred isn't seen. I found using a data analyzer to record the actual traffic is very helpful in some situations.
Software
This is an overview of the software used.
Get the OneWire sources here.
Get the LTE 4G Sensor sources here.
The major classes used on the board are LTESensor and DS18B20Multidrop.
Class LTESensor:
LTESensor is a subclass of SIM7000 which is a subclass of TPDU. LTESensor manages the UI and any non generic communication with the SIM7000 via the SIM7000 class. The TPDU class deals with unpacking and packing TPDU Fields of incoming and outgoing SMS messages.
Class DS18B20Multidrop:
This class handles all communication with and monitoring of DS18B20 temperature sensors. DS18B20Multidrop owns an instance of the OneWire class that performs the actual communication with the DS18B20 on the 1-wire bus.
My MacOS utility applications used in this project (optional):
- SubsetFontCreator - creates a subset of a font for either 1 bit or RGB displays as compressed bitmap data.
- SerialHexLoader - used to debug and test the SIM7000 serial connection. The app name is a bit misleading. None of the SerialHexLoader loader features are used. I’ve been adding utility code to this app for use by various projects. For the LTE 4G Sensor project primarily the menu containing AT commands and manually typed commands are used. Some of the AT commands in the menu are SIMCom specific.
The command and the response is displayed in the SerialHexLoader log window along with any unsolicited responses from the SIM7000. The screenshot below is of the commands periodically sent to the SIM7000 (anything with a '>' prefix.) The time in the log (*PSUTTZ) and connection status (+CREG) are examples of unsolicited data from the SIM7000. All are used to update variables in the LTESensor instance.
The User Interface
As noted in the boards step, the UI consists of a 1.3 inch 240 x 240 display with 5 buttons in a cross pattern; up, down, left, right, and enter.
There are two main panels, Info and Settings. When the board starts up and after waking from sleep, the Info panel is displayed. The Info panel lists the current temperature of each sensor and whether it’s in range (green text) or out of range (red text.) The info panel also displays the local time, signal strength in bars, and a battery level indicator icon in the shape of a battery.
From the Info panel you get to the Settings panel by pressing the up button. From the Settings panel you can activate or deactivate the alarm, set the time format, and set either Celsius or Fahrenheit as your temperature unit. There are also two sub panels, one to set the PIN and another to display alarm settings.
To activate or deactivate the alarm, move the selection frame to Alarm using the Up/Down buttons and then press either the left or right buttons to toggle between on (alarm active) or off (alarm inactive.) All changes are immediately saved.
The 4 digit PIN is used to validate a received SMS setup command. To edit the PIN move the selection frame to PIN using the Up/Down buttons, then press the center Enter button. Pressing Enter will display the PIN editor. To change any of the PIN digits, move the selection frame to the digit to be changed using the Left/Right buttons, and then press the Up/Down buttons to increment or decrement the digit. To save the new PIN move the selection frame using the Left/Right buttons to Set, then press Enter. To cancel the PIN edit, move the selection frame to Cancel and press Enter. When you exit the PIN editor you will return to the Settings panel.
The Alarm Settings displays the current alarm settings, and can optionally send a test SMS to the target phone. To display the Alarm Settings panel, move the selection frame to Alarm Settings and press Enter. The top 3 lines are static, they are for information only. The first line displays the alarm phone number to be sent an SMS text for alarm events. This is also the only number that is allowed to remotely change the alarm state as well as request the current state of the sensors board (alarm state, temperatures, signal strength, and battery level.) The next 2 lines display the alarm high and low temperature settings. The last line, when selected and Enter pressed, will send a test message to the alarm phone number. To return to the main Settings panel, press the Up button until the Settings panel appears.
The remaining two settings in the Settings panel are the time and temperature display formats. Use the Up/Down buttons to select either setting, then use the Left/Right buttons to toggle between formats. All changes are immediately saved.
To return to the Info panel press the Up button until the Info panel appears.
If there is no user interaction for 90 seconds, the board will enter a light sleep mode where the display is powered down to conserve the battery. Pressing any button will cause the board to leave light sleep mode. While in light sleep mode the sensors are monitored and the SIM7000 is in an idle state capable of receiving incoming SMS texts.
On the front of the board to the left of the USB connector is the power button. Pressing and holding this button for 2 seconds will put the SIM7000 and the rest of the board into deep sleep mode. This reduces the battery usage to almost nothing. Pressing and holding this button for 2 seconds while in deep sleep mode will wake up the board. The SIM7000 will attempt to connect to the cell network.
SMS Commands
This step describes the SMS commands that can be sent to the LTE 4G Sensor and the expected response.
Via SMS texts sent to the LTE 4G Sensor you can configure the alarm, enable or disable the alarm, and request the current state of the LTE 4G Sensor.
Commands: (Not case sensitive - setup == SETUP == sEtUp)
- Setup PIN [HxxF] [LxxF]
Makes the sender the target for outgoing messages and optionally sets the alarm high and low temperatures. The setup command expects the first parameter to be the 4 digit PIN as displayed in the Settings panel. The optional high and low temperatures can be set in any order. The high temperature, when included, must have an ‘H’ as the prefix followed by an optional negative sign, then up to 3 integer digits (no decimal point), optionally followed by the temperature unit (C or F.) When the temperature unit isn’t provided, the unit displayed in the Settings panel is assumed. Use the prefix ‘L’ to set the low temperature.
Setup Example: In this example the PIN displayed in the Settings panel is 9595, and the temperature unit is C.
Sending Setup 9999 H30 L0 will be ignored by the LTE 4G Sensor because the PIN in this example is 9595.
Sending Setup 9595 H30 L0 will set the alarm high temperature to 30C, the low temperature to 0C, and will activate the alarm.
The above is the same as sending Setup 9595 H30C L0C
You can also mix the temperature unit suffix: Setup 9595 H30C L32F
If successful, the LTE 4G Sensor will respond with:
- On
Sending on will remotely turn on the alarm. If sent by the same sender that successfully sent the Setup command, the LTE 4G Sensor will respond with:
- Off
Sending off will remotely turn off the alarm. If sent by the same sender that successfully sent the Setup command, the LTE 4G Sensor will respond with:
- ?
Sending ? will return the LTE 4G Sensor status. If sent by the same sender that successfully sent the Setup command, the LTE 4G Sensor will respond with:
- alarm report status ON/OFF
- the alarm high/low temperatures
- the current temperature of each sensor (up to 4 sensors)
- the current signal strength in bars, a number from 1 to 5.
- the battery level as a percentage from 1 to 100.
That’s basically it, pretty simple.
Board Assembly
As noted, I’m not providing step by step instructions on how to assemble a PCB but there are a few unique steps.
- The display board uses double stick tape to adhere the display to the board. I use a 3 strips of 10mm 3M 9080, but any very thin high quality double sided tape should work.
- The SIM7000 module on the LTE 4G Sensor board was soldered after everything else on the board was added. Doing this will limit the amount of heat the module is subjected to.
- The buttons on the 5 button board need to be placed very accurately in order for them to align with the holes in the 3D printed case. The silkscreen on the board should be used to place the buttons.
- The LTE 4G Sensor board has several optional headers and connectors. The pictures below show the empty pads of the optional items. I provided pads on both sides for the reset button. For the case I designed, it makes sense for the reset button to be on the underside.
For the initial LTE 4G Sensor board voltage test you can power the board using the micro USB connector with no other boards connected. Verify that you get 3.3 volts across the ICSP pads shown below. Unplug the USB connector prior to burning the bootloader in the next step.
Loading Software
Download the project sources from GitHub here.
From the Arduino IDE preference dialog, point to the root folder within the project folder hierarchy that contains the LTE4GSensor and Libraries folders.
For this project you’ll need the MightyCore package installed on your IDE. MightyCore supports the ATmega644PA. If you don’t already have it, it can be loaded from the Manage Libraries dialog of the IDE.
From the IDE Tools menu, select the MightyCore ->ATmega644P. The settings should be 8MHz external, BOD 2.7v, Pinout Standard, Variant 644p/644PA, Compiler LTO Disabled.
Open the LTESensor.ino sketch. Verify that it compiles.
To burn the bootloader you'll need a 3.3 volt ISP. You can make your own using any 3.3 volt Arduino with the Arduino as ISP sketch loaded. Any dual voltage AVR ISP such as my AVR SD Hex Loader ISP could also be used.
From the IDE, after selecting the port you have connected to your ISP in the IDE tools menu, connect the ISP to the ICSP connector. The ISP via the ICSP connector will now power some of the board (basically just the ATmega644PA and sensors, which shouldn't be connected at this point.) On my boards I don’t install a 2x3 header for the ICSP because it’s generally only used once. I use an ICSP cable attached to a 2x3 set of pogo pins and hold it in place while burning the bootloader.
From the IDE Tools menu, select Burn Bootloader.
If the bootloader fails to load, check the pins of the ATmega644PA for cold joints.
Once the bootloader has been successfully loaded, disconnect the ISP from the ICSP connector.
To prepare to load the sketch, connect a USB cable from your computer to the micro USB connector on the board. This will power the entire board while it's connected. From the IDE Tools menu, select this USB port as the target port. On the board move the DTR switch located next to the USB connector to the ON position. The ON position is the position closest to the USB connector. Upload the sketch.
Note that when the sketch successfully loads it will attempt to initialize the display, SIM7000 and sensors. When the display isn't connected there's no way for the mcu to detect this because the display is write-only. The sketch will proceed as if a display is connected. Also the SIM7000 doesn't have a SIM card installed at this point, it will report this error to the mcu. The mcu will send to the nonexistent display the message "No SIM Card".
SIM Card
The board requires an activated and provisioned SIM card installed in order to operate. I decided to use Verizon ThingSpace. See my note at the end of this Instructable regarding the possible issues you need to consider when selecting an IoT provider.
Once the SIM card is installed on the board you need to set your IoT provider's SMSC address. For Verizon ThingSpace the SMSC is 9036384682, and would be set by sending AT+CSCA="+19036384682",145 to the SIM7000 via the same USB connection used to load the sketch. The baud rate of the USB serial connection is 19200. You can also perform this step by using my SerialHexLoader utility and choose Set Verizon SMSC from the AT SMS submenu.
The Case and Assembly
The case was designed using Fusion 360 in conjunction with the Eagle feature where you can upload your board(s.) Many of the parts used did not have 3D representations so these were created in Fusion 360 and imported into my library on Eagle. I found it’s very much worth the effort.
Example of some of the 3D parts I created using Fusion 360 using the 2D drawings provided by the parts vendors:
Taking the time to do this allows you to place your boards in the case design without having to create a component representing its geometry and location. If you update the location of a part in Eagle you just sync the changes with Fusion 360.
Materials:
- 2mm acrylic rods used as light guides, source AliExpress.
- Clear epoxy for plastics to attach light guides, source Amazon.
- 2.5mm black heat shrink tubing to be used as a light block for the light guides.
- (32) M2x4 button head machine screws (ISO7380) to attach the boards
- (4) M2x5 flat head machine screws (DIN7991) to attach the cover
- (1) 6cm 4 conductor 1mm pitch A/A (same side contact) flat cable (aka FFC)
- (1) 6cm 6 conductor 1mm pitch A/B (opposite side contact) flat cable (aka FFC)
- (1) 6cm 8 conductor 1mm pitch A/B (opposite side contact) flat cable (aka FFC)
- 18650 Battery
- 1 pair 18650 battery spring plates 16x16.5mm, source AliExpress.
- 1 each 6cm 28AWG red and black cable (UL1007)
- XH2.54-2P Female Socket + female crimp pins
- 4G Antenna, source AliExpress.
Print the 3D Parts:
Download and print the 3D cover and case included in this step. I printed both parts using PLA at 80% fill, support everywhere. I also included a STL of a 18650 Battery Holder that uses the same spring clips as the case.
After printing, clean out the supports and check to see if the buttons on the 5 button board function freely. If not, make sure the buttons are accurately centered on the board. You may also need to ream out the holes depending on the accuracy of your printer.
Ream the (6) 2mm status LED holes using a 2.2mm drill bit. The 2mm acrylic rods I use as light guides are a bit thicker than 2mm. Do NOT ream the 2mm screw holes for the boards and case back.
The Power Cable Assembly:
Attach female XH2.54 crimp pins to one end of 28AWG wire pair, . Insert the pins into the XH2.54-2P socket housing as shown above.
Cut the wires to length as shown above. Solder the red wire to the battery plate without a spring. Solder the black wire to the battery plate with a spring. Fold the solder tabs on both plates back so they’re flush with the plate back.
Slide the plates into the slots in the case by pushing straight down with even pressure. I chuck a short piece of 10mm shaft in my drill press and use it as an arbor press. The plates bend very easily. Using a drill press ensures the pressure is straight down.
Add the LED light guides:
Temporarily install the sensor board using M2x4 button head screws. Insert a length of acrylic rod in one of the 2mm holes above the LEDs till it contacts the LED. Using a flush cutter, cut the acrylic rod. Do the same for the remaining LED holes. With fine sand paper mounted on a block, sand the ends of the rods square. Remove the board from the case. Using a scrap piece of 3D printer filament, mix up a small amount of clear epoxy. Use the printer filament to dab a small amount of epoxy in each LED hole. From the inside of the case, insert the prepared rods till they are flush with the top of the case. Carefully wipe off any epoxy on the case surface. Put the case aside till the epoxy cures.
Once the epoxy cures, cut pieces of heat shrink tubing to mask the surface of the rods within the case, only exposing the ends that face the LED. Shrink the tubing.
Install the boards and finish assembly:
The display board is connected to the sensor board using an 8 pin 6cm 1mm pitch FFC cable A/B.
The 5 button board is connected to the sensor board using an 6 pin 6cm 1mm pitch FFC cable A/B.
The 4 port RJ11 board is connected to the sensor board using an 4 pin 6cm 1mm pitch FFC cable A/A.
Install the 3 button board, display board and 4 port RJ11 boards using M2x4 button head screws. Insert the flat cables in each board. Be aware of the orientation of each cable.
Attach the antenna wire to the sensor board.
Insert the XH2.54 socket into the 2 pin power receptacle next to the SIM7000.
Install the main board using M2x4 button head screws.
Install the SIM card.
Place the antenna as shown in the picture above.
Install the 18650 battery.
The case cover is attached using 4 M2x4 screws. If you use flattop screws you'll need to use a countersink bit on the 4 cover holes to chamfer the edges so that the screws are flush with the cover.
Sensor Assembly
I decided to build my own DS18B20 sensor assemblies. You could buy prewired DS18B20 assemblies and splice on an RJ11 4P4C connector. Be aware that nearly all DS18B20 ICs in a TO92 package on AliExpress and Amazon are counterfeit. Without testing the ICs you can generally tell they’re counterfeit by the price. Any small quantity price for a DS18B20 IC less than $5 is most likely counterfeit. I’m using ICs bought on AliExpress for about USD 0.60 each including shipping with tracking, so I know these are counterfeit. Some counterfeits perform better than others. Very good documentation of the DS18B20 counterfeits issue can be found here.
Materials:
- 6x50mm Stainless Steel Casings source AliExpress
- DS18B20 sensors in a TO-92 case
- 4 conductor phone wire. I bought very long RJ11 6P4C cables (ordinary RJ11 telephone to wall cables) and cut them to size replacing the connectors with the smaller RJ11 4P4C connector. See the Maxim 1-wire design guidelines, in some cases Cat5e cable would be a better choice.
- Epoxy that accepts a mixing nozzle such as the J-B Weld brand.
- Epoxy Adhesive Mixing Nozzle Tip source Amazon
- 6mm heat shrink tubing
- 2mm heat shrink tubing
- Optional: 3M 3090 10mm wide double stick tape
Considerations before you begin:
Maxim, the official manufacturer of the DS18B20, doesn’t recommend the “star” topology used in this design for stub lengths greater than 3 meters. For this reason the lengths should be as short as actually needed, 3 meters per sensor or less due to reflections on the lines that can cause data errors. I tested four cables at 3 meters per line and didn’t have any issues. If you need something longer, daisy chaining them would be more reliable. A small modification of the 4 port RJ11 board would convert the board into a daisy chain topology by using the unused 4th conductor as the data conductor for the next port, and so on. You’d have to plug the sensors in in order without any gaps. See the Maxim guidelines for more information.
Build the Cables:
Solder the sensors to the phone wire as shown below.
The DS18B20 is shown with the flat side facing the camera, G Y B.
As shown below the color order on the RJ11 in the position shown is Y G R B.
The red wire is not used.
Test the cables before encasing them in epoxy within the casings. This can be done using the now completed LTE 4G Sensor.
- Put the sensor board into deep sleep by pressing and holding the power button for 2 seconds.
- Once asleep, insert a single RJ11 connector into any socket on the LTE 4G Sensor by itself, with no other sensors connected.
- Wake up the LTE 4G Sensor by pressing and holding the power button for 2 seconds.
- If successful, a single dashed line will be displayed and then be replaced with the first temperature reading in about 10 seconds.
- Repeat the above for the remaining sensors.
Note that there is no correlation between the index number displayed in the Info Panel and the RJ11 sockets. The indexes are essentially assigned randomly, possibly based on the unique serial number of each sensor.
Add the Stainless Steel Casings:
Once the sensors are working, encase the sensors in the casings.
- Mask off the open end of each casing with painter's tape
- Replace the cap on the epoxy syringe with a mixing nozzle.
- Extrude a small amount of epoxy till the mix is consistent.
- Fill each of the casings by inserting the mixing nozzle and injecting epoxy in each.
- Insert the sensors into the casing, working out air pockets by gently inserting and retracting until the sensor is fully inserted.
- Top off the area around the top of the casing as needed with additional epoxy.
- Carefully wipe any epoxy on the wire after it exits the casing and set the assembly aside to cure
- Once cured you may need to carefully snip off any epoxy you weren’t able to wipe off in the previous step.
- Remove the painters tape.
- Optional: For a more watertight fit, apply a 10mm strip of double sided tape around the casing rim.
- Cut 6mm heat shrink tubing into lengths approximately 3.5cm and slip them over the casing so that only 10mm is in contact with the casing.
- If you added the optional double sided tape, press the tubing onto a portion of the tape just to keep it in place.
- Using a hot air gun, shrink the tubing.
IoT Provider Considerations
The considerations noted below are from my personal experience with this project and may not be totally accurate.
Before you rush out and build this board or attempt to use many of the SIM7000 modules sold in the US, you should be aware of the issues you may encounter.
In the US they have lots of companies that will sell you SIM cards for IoT projects, but they fail to tell you that most of the big cellular network operators are picky about what equipment they allow on their network. The International Mobile Equipment Identity, or IMEI, is the unique 15 digit number that uniquely identifies your specific modem such as the SIM7000. In the US, your goal is to have your IMEI registered with one of the major cellular network operators, such as Verizon. When I say cellular network operator I'm referring to the company that owns the towers.
When any modem module of any manufacturer tries to connect to a network, it’s the combination of the modem’s IMEI and the SIM card that needs to pass a network’s inspection. Your SIM card isn’t going to help you if the IMEI of the module you bought on Amazon isn’t certified and registered. You can self register an uncertified board, but Verizon and AT&T want you to go through a certification process that requires you to, among other things, send your board to a 3rd party for EMI testing. They also prefer you to be a company and have insurance. Even though I designed my own board, I was able to avoid having to do this, but the route I took probably isn’t repeatable.
Caveat: I was told by Verizon Technical Support that there have been cases where hobbyists were able to register a limited number of their IMEIs for a fixed duration (assuming at some point you would fully certify.) I didn't go this route so I can't verify that it is still possible. At the time, as described, it seemed rather onerous.
The end result of certification on Verizon is getting your IMEI onto Verizon’s DMD. The DMD is a database that Verizon’s network uses to determine if they will allow a device to connect, regardless of the SIM provider. Once on Verizon’s DMD your board will connect nearly everywhere in the US. Before you purchase a SIM7000 module you should ask the seller if the IMEI is registered with the network operator prevalent in your area. Even though the SIM7000A is a Verizon-approved module, the board it’s mounted on may not be certified, and that’s the key distinction.
I initially tried a Hologram SIM but for my needs, only SMS texts, the Verizon ThingSpace SIM is a less expensive option. As of now, including taxes, a ThingSpace SIM basic plan is $1.60 per month which includes 100 SMS texts and 1MB data.
ThingSpace technical support is very helpful as far as resolving provisioning and website access issues. For low level cellular network related technical questions they will listen to you and offer to forward your questions to other groups, and after several weeks you might get an answer, but don’t count on it. Their definition of things may be different than yours as well. For instance “connected” for them means you’re connected to their IP network (which my board doesn’t use.) For me connected is when the SIM7000 passes network registration with the local tower. Network registration doesn’t appear to be something Verizon can easily detect, at least not with the tools Verizon technical support has easy access to. This led Verizon to initially claim the problem I was experiencing was with my board, because from their perspective, I wasn’t connecting. The problem turned out to be a provisioning issue. After a few weeks they fixed their provisioning issue and my board was able to connect.
An issue I encountered after my board was able to connect was not being able to send SMS texts. The published Verizon SMSC address (the server that routes SMS texts), doesn't work with ThingSpace SIMs. This was an example where ThingSpace technical support was not able to provide the information I needed (although they probably can now after I let them know what fixed the issue.) I determined the correct SMSC by decoding an incoming SMS in its PDU format. See step 7 for this SMSC address and how to set it.
Conclusion
I hope you found the information contained in this instructable useful. Send me a message if you have any questions.