GPS trigger when leaving gps range

I am testing simple gps trigger, that turns on relay, when I am in GPS range and it should turn this relay off, when I am out of the range.

At the moment relay is turned on, when I enter the GPS range, but not turned off when I leave range. I have one GPS Trigger in Blynk app on Android phone, assigned to V1 and trigger option is to “Enter”.

Do you have same suggestion, how to trigger relay turn off, when I am leaving the GPS range?

#define BLYNK_PRINT Serial

#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "123123123123123213123";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "12121";
char pass[] = "1212";

// Hardware Serial on Mega, Leonardo, Micro...
//#define EspSerial Serial1

// or Software Serial on Uno, Nano...
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // RX, TX

// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600

ESP8266 wifi(&EspSerial);

BlynkTimer timer;

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void myTimerEvent()
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, millis() / 1000);
  int relejastavoklis = digitalRead(8);
  Blynk.virtualWrite(V6, relejastavoklis);

  int GpsState = param.asInt();
  if (GpsState){
    Serial.print("ienāca, ieslēdz, gps state:");
    digitalWrite(8, LOW);//iesleedz
    Serial.print("izgaja, izslēdz, gps state: ");
    digitalWrite(8, HIGH);//izsleedz

void setup()
  // Debug console
  digitalWrite(8, HIGH);//izsleedz
  // Set ESP8266 baud rate

  Blynk.begin(auth, wifi, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, wifi, ssid, pass, "", 80);
  //Blynk.begin(auth, wifi, ssid, pass, IPAddress(192,168,1,100), 8080);

  // Setup a function to be called every second
  timer.setInterval(1000L, myTimerEvent);

void loop()
{;; // Initiates BlynkTimer

Add another widget on another vPin and set to trigger on EXIT :slight_smile:

Thank you, that works. Only on Android devices it is needed to disable Battery optimisation setting for Blynk app.