Our Blog

Moving Truck Alarm System With An Arduino & Twilio

Summary:To protect our moving truck (with all of our things inside) on the night before our move I used a WiFi-enabled Arduino and a motion sensor to to create a DIY alarm system that would trigger if someone opened the loading door on the truck.

The Problem

When we moved last month we decided to load the truck up the night before we drove off to Indianapolis so we could get there and unload our things in the morning. While this makes the move overall easier because it makes it easier to clean up the old place and set up things in the new place, it leads to a nerve-wracking scenario. My wife was very worried about our stuff sitting in the back of a moving truck overnight. It is an understandable fear as it feels like your whole life is sitting in the back of a truck ready to be stolen. So we did the sensible thing and bought a lock to go on the truck. However, this still wasn’t a perfect comfort to my pregnant wife who wants to be able to sleep well on the night before the big move.

The Solution

So, I told her that I would make an alarm system. I had an Arduino Diamondback which has a WiFi module attached. It was already placed in a housing and attached to two range-finding sensors for a different project. So I decided to repurpose it and use it for the security system.

The idea of a security system seemed to put my wife at ease, especially since I didn’t purchase a single thing to make it. The device was simple. This is how it worked:

I connected the Arduino to the my wireless network.  I powered the device through a wall outlet. Using one of the sensors connected to the board, I set a trigger so that when it sensed a movement my wife and I would receive a text message to alert us of possible nefarious activity. It rung both our phones because I wanted to have an alarm that scared off the would-be burglars as well. So, I recorded a custom voice message on my Android phone that said, “You’ve been caught. The cops are coming. You better run!” I of course did this in as creepy a voice as possible as you can hear in the above video.

The device was a smashing success, and worked great, minus the fact that it was very difficult to get my WiFi to penetrate the metal box that is a moving truck. Because of that make sure that you device is close to your router though as we kept getting kicked off the WiFi because of the truck.

The best news though was that there were no burglars or would-be burglars. But, if there were we were ready!

moving truck security system
Here the device is set up at the end of the  truck. The phone was hidden out of view in a bag when we sent it live.


I just wanted to give a bit of an update to clarify things that have been said on the comments on the web. On this trip, I only moved my home and we loaded up the night before we were to drive off. I only used this to protect our stuff at home over night. We weren’t too concerned as we traveled, because we weren’t making any overnight stops on this trip. Thanks for all the comments.

Technical How To

For those interested in building your own DIY alarm system using an Arduino and Twilio for notifications, below is the code I used and the hardware that I built.

Hardware Build

The following are the main ingredients that were used for this project.

arduino security system

There is a 9V battery option, but the battery life is pretty poor currently so I just plugged it in.

The circuit was simple as all that was needed was for the range-finding sensors to connect to the analog pins. I also mounted the sensor to the outside of the project box. I cut the whole using a Dremel tool.

Software Build

For the software one of the first things that you need to do is set up Twilio on your server. Twilio is a tool that let’s you program SMS messages very quickly and easily. They have a great tutorial that allows you to send a text message to a list of phone numbers when a webpage is hit. I simply set up the page to be hit on the site and made the Arduino hit the page when the sensor was tripped.

Twilio Setup [Link to Twilio Tutorial]

Below is the final sketch for the project. Remember if you happen to get ahold of a Diamondback, that you need to use the latest codebase for the WifiShield. You would also want to use the previous version of the Arduino software. Certain omissions have been made such as ip address, passwords, and urls. If they have been changed I have generally placed them with x’s.

* A simple sketch that uses WiServer to send a text message when someone trips a motion sensor in a moving truck.



// Define the number of samples to keep track of. The higher the number,
// the more the readings will be smoothed, but the slower the output will
// respond to the input. Using a constant rather than a normal variable lets
// use this value to determine the size of the readings array.
const int numReadings = 3;

int readings[numReadings]; // the readings from the analog input
int index = 0; // the index of the current reading
int total = 0; // the running total
int average = 0; // the average

// Wireless configuration parameters —————————————-
unsigned char local_ip[] = {192,168,1,XX}; // IP address of WiShield
unsigned char gateway_ip[] = {192,168,1,XXX}; // router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network
const prog_char ssid[] PROGMEM = {“xxxxxx”}; // max 32 bytes

unsigned char security_type = 3; // 0 – open; 1 – WEP; 2 – WPA; 3 – WPA2

// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {“xxxxxxxx”}; // max 64 characters

// WEP 128-bit keys
// sample HEX keys
prog_uchar wep_keys[] PROGMEM = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, // Key 0
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 1
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 2
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Key 3

// setup the wireless mode
// infrastructure – connect to AP
// adhoc – connect to another WiFi device
unsigned char wireless_mode = WIRELESS_MODE_INFRA;

unsigned char ssid_len;
unsigned char security_passphrase_len;
// End of wireless configuration parameters —————————————-

// IP Address for Google Analytics
uint8 ip[] = {74,208,81,43};

// A request that calls the GA tracking pixel
GETrequest getAnalyticsIN(ip, 80, “www.flintanalytics.com”, “/sms-test” );

const int analogInPin1 = 0; // Analog input pin that the sensor is attached to

int sensorValue1 = 0; // value read from the ir sensor

void setup() {
// Initialize WiServer (we’ll pass NULL for the page serving function since we don’t need to serve web pages)

// initialize all the readings to 0:
for (int thisReading = 0; thisReading < numReadings; thisReading++) readings[thisReading] = 0; } // Time (in millis) when the data should be retrieved long updateTime = 0; void loop(){ // subtract the last reading: total= total – readings[index]; // read from the sensor: readings[index] = analogRead(analogInPin1); // add the reading to the total: total= total + readings[index]; // advance to the next position in the array: index = index + 1; // if we’re at the end of the array… if (index >= numReadings)
// …wrap around to the beginning:
index = 0;

// calculate the average:
average = total / numReadings;

// Determine door was opened
if (average >= SENSOR_THRESHOLD) {

// Run WiServer


Tags: , ,

This is a unique website which will require a more modern browser to work! Please upgrade today!