Dear community
I am trying to create a gps alarm (if the item moves the alarm goes on)
So I need to set the initial coordinates as a fix location, after that save them and measure the distance from saved location. if the distance exeeds radius then the alarm goes on.
I have no previous experience in coding and any help is greatly appretiated
I'm trying to compile and get the following errors:
///////////////////////code//////////////////////////////
#include <TinyGPS++.h>
TinyGPSPlus gps;
#define Radius 0.00003 // Alarm Radius = 3.3 m
const int buzzerPin = 7;
const int gpspin = 13;
void setup()
{
Serial.begin(9600);
pinMode(gpspin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
}
void loop()
{
while (Serial.available() > 0)
{
if (gps.encode(Serial.read()))
{
bool status = move();
if (status == true)
{
TurnOnAlarm();
}
else
{
TurnOffAlarm();
}
}
}
}
}
bool move()
{
if (gps.location.isValid())
{
double lat, lng, latmove, lngmove;
// Extract GPS co-ordinates
lat = gps.location.lat();
lng = gps.location.lng();
// Print GPS co-ordinates on Serial monitor
Serial.print(F("Location: "));
Serial.print(lat, 5);
Serial.print(F(","));
Serial.print(lng, 5);
latmove = setLat - lat;
lngmove = setLng - lng;
if( ((latmove >= Radius) && (latmove <= (Radius * -1)))
&& ((lngmove >= Radius) && (lngmove <= (Radius * -1))) )
{
return true;
}
}
else
{
Serial.print(F("GPS Err"));
}
return false;
}
}
void TurnOnAlarm()
{
Serial.println(" \t Alarm ON");
digitalWrite(gpspin, HIGH);
tone(buzzerPin, 1000);
}
}
void TurnOffAlarm()
{
Serial.println(" \t Alarm Off");
}
noTone(buzzerPin);
}
//////////////////////// err msg: /////////////////////////////////
Arduino: 1.8.14 Hourly Build 2020/09/14 03:35 (Mac OS X), Board: "Arduino MKR WiFi 1010"
/Users/yannis/Documents/Arduino/sketch_sep28a_project_geofence_2.1/sketch_sep28a_project_geofence_2.1.ino: In function 'void loop()':
sketch_sep28a_project_geofence_2.1:22:21: error: 'move' was not declared in this scope
bool status = move(); // Check if reached the destination and Print required data.
^~~~
/Users/yannis/Documents/Arduino/sketch_sep28a_project_geofence_2.1/sketch_sep28a_project_geofence_2.1.ino:22:21: note: suggested alternative: 'remove'
bool status = move(); // Check if reached the destination and Print required data.
^~~~
remove
sketch_sep28a_project_geofence_2.1:26:9: error: 'TurnOnAlarm' was not declared in this scope
TurnOnAlarm(); // Trigger the alarm to notify the user
^~~~~~~~~~~
sketch_sep28a_project_geofence_2.1:30:9: error: 'TurnOffAlarm' was not declared in this scope
TurnOffAlarm();
^~~~~~~~~~~~
/Users/yannis/Documents/Arduino/sketch_sep28a_project_geofence_2.1/sketch_sep28a_project_geofence_2.1.ino: At global scope:
sketch_sep28a_project_geofence_2.1:36:1: error: expected declaration before '}' token
}
^
exit status 1
'move' was not declared in this scope
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.