Project tutorial
SmartWay

SmartWay © GPL3+

A smarter way to get to school.

  • 5,170 views
  • 7 comments
  • 13 respects

Components and supplies

Necessary tools and machines

09507 01
Soldering iron (generic)

Apps and online services

About this project

Overview

Parents always worry about their children. Parents want their children to arrive to school punctual and get home on time, taking the assigned path.

SmartWay aims to remove this worry from the parent's everyday life. SmartWay will monitor your child as he/she gets to and from school, ensuring that your child always takes the appropriate path to arrive at his/her destination, school.

SWay will Monitor your child's geolocation using GPS and will immediately send the parent an e-mail if the child deviates form the path you assigned to him/her. SmartWay will also send the parent an e-mail when the child arrives home or to school, as well as informing them if the child is late. This way, parents can sit back and enjoy their coffee knowing that their child arrives safely to school and home.

Functionality

SmartWay will continuously monitor your child's geolocation from when he/she wakes up to when arrived home. The device is also equipped with an RGB LED and a vibrating motor to warn your child if he/she is not taking the correct way to school or is late, and congratulate him/her when he/she arrived to school.

The device works through many functions to ensure your child is safe.

  • The first loop if(off track) detects if the child deviated from the assigned path, the device has a system that detects the amount of times that this occurs; if your child deviates off course the first time, the device will warn him/her by turning the LED red and vibrating the motor, then the child will receive two minutes to come back on course. If the child remains off course for a further two minutes, the parent will receive an e-mail warning them that their child is off course together with his/her geolocation, the email will be receptively sent at intervals of 2 minutes until the Child arrives home or at school.
  • if(school time) and if(home time) loops detect if it is time for school and home, then the device checks if the child arrived to school or home, if he/she arrived in time, the LED will turn green and the device will send the parent an email informing them that their child arrived at his/her destination together with the arrival time. Else, if it is time for school to start and the child is not at school it will also

The device can only send 12 byes of information, therefore a compact packet is needed when sending. Other variables will be configured in the SigFox backend.

There are four packets that the device can send

  • child is off course - ("off course")
  • child arrived home - ("at home")
  • child arrived to school - ("at school")
  • child is late - ("late")

Warning System

The child wearing the device will be alerted whenever he/she arrives to school, arrives home, or is late to arrive at a destination, or has deviated off course

The device in action

Benefits

Parents using this device will benefit in:

  • ensure that their child arrives safely to and from school
  • ensure that their child arrives punctual at these locations
  • ensure that their child does not deviate of course
  • Energy Saving and low cost - Long lasting batteries

Constructing the Project

Step 1: Required Apparatus

To get started with making the project, we need to gather our materials. For this project you will need:

Step 2: Connecting the circuit

The next step is to connect the circuit; the Fritzing images below will illustrate how this is done. There are multiple parts to the wiring, so they are split into different images.

Step 3: Acknowledging the Code

The code consists of multiple functions, each function carries out a specific role in the makeup of the project.

  • Warn System
  • Get GPS
  • Synch RTC
  • Process Location
  • Send Package
  • Do Actions

These sections are explained below.

  • Warn System
void setOutputs()
{
 pinMode(R, OUTPUT);
 pinMode(G, OUTPUT);
 pinMode(B, OUTPUT);
 pinMode(motorPin, OUTPUT);
}
void vibrateMotor() // vibrate the motor cell
{
 digitalWrite(motorPin, HIGH);
 delay(1000);
 digitalWrite(motorPin, LOW);
}
void ledGreen() // LED, Green
{
 analogWrite(R, 0);
 analogWrite(G, 255);
 analogWrite(B, 0);
}
void ledOrange() // LED, Orange
{
 analogWrite(R, 255);
 analogWrite(G, 45);
 analogWrite(B, 0);
}
void ledRed() // LED, Red
{
 analogWrite(R, 255);
 analogWrite(G, 0);
 analogWrite(B, 0);
}
void resetLED() // Turn off LED
{
 analogWrite(R, 0);
 analogWrite(G, 0);
 analogWrite(B, 0);
}

This section of the code is found in the functions.h file. The code will notify the child wearing the device on the current state. Overall these loops control the RGB LED and the vibrating motor cell.

  • Get GPS
bool getGPS(int run)
{
 while(Serial1.available() > 0)
 {
   if(gps.encode(Serial1.read()))
   {
     if(run == 1)
     {
       processData();
     }
     else if(run == 2)
     {
       synchRTC();
     }
     if(gps.location.isValid() && gps.time.isValid() && gps.date.isValid())
     {
       return true;
     }
     else
     {
       return false;
     }
   }
 }
 if(millis() > 10000 && gps.charsProcessed() < 10)
 {
   Serial.println("Error - GPS Module Responded with Error");
   Serial.println("  Terminating Code");
   Serial.println("________________________________________");
   while(1) {};
 }
}

This is the loop in charge of receiving the location and time from the GPS module. There are 3 things that this loop does, it is used in the setup loop to synch the GPS, it is then used to synch the onboard RTC to the GPS' and it is used in the main loop to get the geolocation of the device.

  • Synch RTC
void synchRTC()
{
 Serial.println("Synching RTC");
 Serial.println("________________________________________");
 Serial.println("  OK - Initialising RTC");
 rtc.begin();
 Serial.println("  OK - Synching Time");
 // we have to trim the variable's first 2 digits (2018 -> 18)
 uint16_t yearRAW = gps.date.year();
 String yearString = String(yearRAW);
 yearString.remove(0,1);
 uint16_t year = yearString.toInt();
 rtc.setTime(gps.time.hour(), gps.time.minute(), gps.time.second());
 rtc.setDate(gps.date.day(), gps.date.month(), year);
 Serial.println("  Success - RTC Synched");
 Serial.println("________________________________________");
 Serial.println("");
 Serial.println("");
 Serial.println("");
}

This section of code synchs the onboard RTC to the time received from the GPS module, it firsts reads the data from the GPS module then processing it. The loop then sets the current time of the onboard RTC to the time received and starts the RTC.

  • Process Location
bool processData()
{
 if(gps.location.isValid())
 {
   latitude = gps.location.lat();
   longitude = gps.location.lng();
   latitude = 53.355504;
   longitude = -6.258452;
   if(check.isOut())
   {
     if(check.track())
     {
       Serial.println("OUT OF BOUNDS");
       warn.offTrackLoop();
     }
   }
   if(check.isHomeTime() && arrivedSchool)
   {
     if(check.isHome())
     {
       Serial.println("AT HOME");
       warn.arrivedHomeLoop();
     }
     else
     {
       Serial.println("LATE -> HOME");
       warn.lateLoop();
     }
   }
   else if(check.isSchoolTime() && arrivedHome)
   {
     Serial.println(".");
     if(check.isSchool())
     {
       Serial.println("AT SCHOOL");
       warn.arrivedSchoolLoop();
     }
     else
     {
       Serial.println("LATE -> SCHOOL");
       warn.lateLoop();
     }
   }
   else
   {
     Serial.println("ON WAY");
   }
 }
}

This loop will process the location of the device and compare it to the current time to see where the child should be at this time. It will then do the appropriate action based on the result.

  • Do Actions
struct Do
{
 void offTrackLoop()
 {
   if(offTrackVar)
   {
     parseData(0);
   }
   vibrateMotor();
   ledRed();
   delay(1000);
   vibrateMotor();
   resetLED();
   offTrackVar = true;
   delay(120000);
 }
 void lateLoop()
 {
   if(!lateVar)
   {
     parseData(1);
   }
   vibrateMotor();
   ledOrange();
   delay(1000);
   resetLED();
   lateVar = true;
 }
 void arrivedHomeLoop()
 {
   lateVar = false;
   offTrackVar = false;
   vibrateMotor();
   ledGreen();
   delay(1000);
   resetLED();
   parseData(2);
   arrivedHome = true;
   arrivedSchool = false;
 }
 void arrivedSchoolLoop()
 {
   lateVar = false;
   offTrackVar = false;
   vibrateMotor();
   ledGreen();
   delay(1000);
   resetLED();
   parseData(3);
   arrivedHome = false;
   arrivedSchool = true;
 }
};

This struct is called to take action on the response given by Process Location, it will warn the child toggling the RGB LED and the vibrating motor cell. It will also send a package to SigFox if necessary.

  • Send Package
void parseData(int state)
{
 SigFox.beginPacket(); // begin the message sending process
 if(state == 0) // off track
 {
   SigFox.print("off track"); // send the message
 }
 else if(state == 1) // late
 {
   SigFox.print("late"); // send the message
 }
 else if(state == 2) // arrived home
 {
   SigFox.print("at home"); // send the message
 }
 else // arrived school
 {
   SigFox.print("at school"); // send the message
 }
 SigFox.endPacket();
}

This function sends the data to SigFox, the packet sending is commenced and then the appropriate value is parsed.

Setting Up the Variables

The code will contain multiple variables with TODO written as a comment after them, these variable must be customised to fit the client, the client will be asked to setup

  • Time For school
  • Time it takes the child to travel
  • Time at which school ends
  • Debugging?
  • School Geolocation (LAT, LNG);
  • Home Geolocation (LAT, LNG);

The guide below guides you through setting up the variables.

Libraries

SigFox - copyright (c) 2016 Arduino LLC GNU Lesser General Public Licence this library is in the public domain

ctype - copyright (c) 2006 Free Software Foundation under the GNU General Public Licence, this library is in the public domain

RTCZero - copyright (c) 2015 Arduino LLC under the GNU Lesser General Public Licence, this library is in the public domain

String - copyright (c) 2009-10 Hernando Barragan, copyright (c) 2011 Paul Stoffrengen under the GNU Lesser General Public Licence, this library is in the public domain

TinyGPS++ - copyright (c) 2008-13 Mikal Hart under the GNU Lesser General Public Licence, this library is in the public domain

Setup

Ensure that the circuit is correctly wired. For details on setting up your MKR fox, click here for the Arduino tutorial. If you would wish to know more about the Arduino SigFox library, click here.

Backend Program

You must have a registered Arduino MKR1200 fox to program the backend.

  • Step 1

Open the SigFox backend and sign into your SigFox account.

  • Step 2

click on the "Device Type" in the dropdown menu at the top of the page

  • Step 3:

select your Arduino MKRfox and click edit

  • Step 4:

Select callbacks from the menu on the left and navigate to the "new" button in the top right corner.

  • Step 5:

After you clicked new, you will be presented with a number of callback configuration options, click on Custom Callbacks

Next a window will open, you must fill in the given form to create your callback

set type to Data, Uplink
set channel to email
custom payload will read the data sent by the board and then format it, you must declare a variable str fallowed by two :: then the variable type char and the amount of characters that this variable occupies, in our case 10 . Finally you should have something like this str::char:10
Set the recipient to the email address to which the data will be sent.
Set the subject of the email as you prefer.
In the message field, there are multiple variables that you can use by default, without sending them from your device, we will be using {device} (device ID), {lat} (module's latitude) and {lng} (module's longitude), these variables will be automatically sent to SigFox onto of the 12 bytes payload, so you can use them without specifically sending these strings from your device. We will also be using the variable {customData#str} this variable holds the data that has been sent by the Arduino MKR1200 fox, customData refers to the fact that it is the personalised data the device has sent #str states that the device will read the str string sent by the device.
We will also add a website to check the received co-ordinates with, using google maps, we can pinpoint the received data on a map. this is the url https://www.google.com/maps/?q={lat},{lng} , lat and lng will automatically change to the latitude and longitude variables.

At the end your message should look like this:

Now click ok and you are all set.

Final

The last thing you need to do is upload the code below make sure that you have customised the variable marked with "TODO" to your preference, wait for the blue light on the GOS module to blink and then disconnect the micro controller from your computer and place batteries in the battery box. You are all set.

I designed an enclosure to keep the device safe and to make it look attractive, I used two pieces of acrylic and melted the edges curving them at 90 degrees. I placed all the circuit inside and the battery box below them and then strapped the pieces of plastic together using two cable ties.

In the end I covered a piece of the top (transparent cover) to hide all the wires from view and only allow the brain of the project visible.

Background

I personally know how stressful it can be to execute the simple task of sending your child to school, everyone worries about all the things that can happen to their child as he makes his/her way to school.

This project is aimed at all the people who feel stressed when they send their child to school. SWay will allow you to relax, knowing that your child will safely arrive to school.

Code

SmartWay
The Full Code

Custom parts and enclosures

MKRfox 1200
Not included in Fritzing by default
arduino_mkr_fox_1200_fixed_gwlzp1tuih_uh8ucYEGxI.fzpz

Schematics

overall_WZeRYkIUCF.fzz

Comments

Submitted to Contest

A Seeed Studio Grove Kit

Arduino MKR FOX 1200 Contest

Author

Lightpro
Andrei Florian
  • 13 projects
  • 72 followers

Additional contributors

  • Inspired me to make this project by My Uncle

Published on

November 14, 2017

Members who respect this project

Carmen nwzdqc769jPhotoLightproAdambenzProfile eooucbil68Eunate sigfoxeducationDefault

and 6 others

See similar projects
you might like

Similar projects you might like

Fox Advisor

Project tutorial by Celia Garrido Hidalgo

  • 3,368 views
  • 2 comments
  • 12 respects

SmartPostBox

Project tutorial by Andrei Florian

  • 9,335 views
  • 13 comments
  • 45 respects

MyRiver

Project tutorial by Andrei Florian

  • 12,389 views
  • 3 comments
  • 55 respects

Sigfox kWh Meter

Project tutorial by jassak

  • 6,372 views
  • 8 comments
  • 15 respects

Carfox: A Device to Find Them All

Project tutorial by Luis Roda Sánchez

  • 6,498 views
  • 2 comments
  • 28 respects
Add projectSign up / Login