IDENTIFICATION OF NEEDS
Individuals who travel with low sight could benefit from a solution that could provide location-based notifications, specifically notifying individuals when they leave the desired 'home' location. Using an on-board button and audible feedback, I introduced a button-triggered function using the on-board button to easily set the home location, making the system accessible and intuitive.
This project utilizes Blue's notecard's wireless GPS to notify the user if they left an area around the specific position they set.
Using the Swan as a Host MCU, we're able to take in data and feed it to the microcontroller, which then determines when it should buzz the piezo buzzer. Let's take a look at the code to see how it works.
First, we initialize the variables
#include <Arduino.h>
#include <Notecard.h>
#define usbSerial Serial
#define productUID "your.product.UID"
#define OnBoardButton USER_BTN
Notecard notecard;
int BUZZER_PIN = 11;
volatile bool homeisset = false;
double homelat = 0;
double homelon = 0;
double lat =0;
double lon = 0;
double maxrange = 2/(10^10);
As
we can see, the variables 'maxrange' will determine how far the user should go before the buzzer starts activating.
void setHome(){ // Uses the notecard to set a location as "Home". Beeps the buzzer when it is done.
homeisset = true;
}
// the setup function runs once when you press reset or power the board
void setup()
{
tone(BUZZER_PIN,15);
delay(500);
noTone(BUZZER_PIN);
delay(2500);
usbSerial.begin(115200);
notecard.begin();
notecard.setDebugOutputStream(usbSerial);
J *resetreq = notecard.newRequest("card.restore");
JAddBoolToObject(resetreq,"delete",true);
notecard.sendRequest(resetreq);
J *req1 = notecard.newRequest("hub.set");
JAddStringToObject(req1, "product", productUID);
JAddStringToObject(req1, "mode", "periodic");
JAddNumberToObject(req1, "outbound", 30);
notecard.sendRequest(req1);
J *req2 = notecard.newRequest("card.location.mode");
JAddStringToObject(req2, "mode", "periodic");
JAddNumberToObject(req2, "seconds", 180);
notecard.sendRequest(req2);
J *req3 = notecard.newRequest("card.location.track");
JAddBoolToObject(req3, "start", true);
JAddBoolToObject(req3, "heartbeat", true);
JAddNumberToObject(req3, "hours", -4);
notecard.sendRequest(req3);
pinMode(BUZZER_PIN,OUTPUT);
attachInterrupt(digitalPinToInterrupt(OnBoardButton), setHome, FALLING);
}
The code utilizes the onboard button on the Swan as an interrupt. When the button is pressed, we're able to set home. This grabs the data from the Notecard and saves it to the MCU. Once home is set, we can set the location tracking mode back to periodic.
void loop()
{
if (homeisset) {
{
J *req4 = notecard.newRequest("card.location.mode");
JAddStringToObject(req4, "mode", "continuous");
notecard.sendRequest(req4);
}
J *req5 = notecard.newRequest("card.location");
J *rsp1 = notecard.requestAndResponse(req5);
Serial.println("Location:");
while (homelat == 0) {
Serial.println("No location found yet...");
J *req6 = notecard.newRequest("card.location");
J *rsp2 = notecard.requestAndResponse(req6);
Serial.println("Location:");
homelat = JGetNumber(rsp2, "lat");
homelon = JGetNumber(rsp2, "lon");
delay (10000);
}
tone(BUZZER_PIN,15);
delay(500);
noTone(BUZZER_PIN);
J *req7 = notecard.newRequest("card.location.mode");
JAddStringToObject(req7, "mode", "periodic");
JAddNumberToObject(req7, "seconds", 180);
notecard.sendRequest(req7);
J *req8 = notecard.newRequest("card.location.track");
JAddBoolToObject(req8, "start", true);
JAddBoolToObject(req8, "heartbeat", true);
// JAddStringToObject(req3, "file", "locations.db");
JAddNumberToObject(req8, "hours", -4);
notecard.sendRequest(req8);
homeisset = false;
}
else {
J *req9 = notecard.newRequest("card.location");
J *rsp5 = notecard.requestAndResponse(req9);
J *req10 = notecard.newRequest("card.location.mode");
J *rsp6 = notecard.requestAndResponse(req10);
lat = JGetNumber(rsp6, "lat");
lon = JGetNumber(rsp6, "lon");
delay(4000);
if (((homelat - lat) > (maxrange)) || ((homelon - lon) > (maxrange))){
tone(BUZZER_PIN,5);
delay(500);
noTone(BUZZER_PIN);
delay(500);
}
}
}
The loop function of the code checks to see if the homeisset variable is true. If it is, it then sets home by setting the GPS to continuous to force it to activate. Once it receives a location, it's a matter of simply switching the mode back and using new data to determine whether the user is out of range or not. If it does, then they get a buzz! This design could easily be powered with a Lipo battery, as well.
Comments