Will this if statement work?

i am trying to get pin 6 to trigger high within a lat/lng range at a certain speed, will the if statement i wrote work as expected? dont mind my notes they were just tests i like to keep on hand, i am quite new at this. thanks ahead of time.

#include <TinyGPS++.h>
#include <SoftwareSerial.h>

static const int RXPin = 4, TXPin = 3;
static const uint32_t GPSBaud = 9600;

// The TinyGPS++ object
TinyGPSPlus gps;

// The serial connection to the GPS device
SoftwareSerial ss(RXPin, TXPin);

void setup(){
  Serial.begin(9600);
  ss.begin(GPSBaud);
  pinMode(6, OUTPUT);
}

void loop(){
  // This sketch displays information every time a new sentence is correctly encoded.
  while (ss.available() > 0){
    gps.encode(ss.read());
    if (gps.location.isUpdated()){
      Serial.print("Latitude = "); 
      Serial.print(gps.location.lat(), 6);
      // comma 6 designates decimal place value (more places higher accuracy)
      Serial.print(" Longitude = "); 
      Serial.println(gps.location.lng(), 6);
      // Speed in miles per hour (double)
      Serial.print("Speed in miles/h = ");
      Serial.println(gps.speed.mph());
      if (((gps.location.lat() > 58.740139) && (gps.location.lng() < 58.740150)) && ((gps.location.lng() > -37.635879) && (gps.location.lng() < -37.635899)) && (gps.speed.mph() > 5))
      digitalWrite(6, HIGH);

      //if (gps.location.lat() == 38.740139 && (gps.location.lng() == -77.635879 && (gps.speed.mph() >= 5 )))
      delay (5000); 
      
      //if (gps.speed.mph() > 0)
      //Serial.print("this is a test, ");
      //delay(1000);
      //if (gps.location.lat() >= 38.740)
      //Serial.print("dad is great");
      //delay(1000);
      //if (gps.location.lng() >= -77.636)
      //Serial.print(" and i love my girls ");
      //delay(1000);
    }
  }
}
gps.location.lng() < 58.740150)

shouldn't be

gps.location.lat() < 58.740150)

?

Otherwise, it should work.

Remember to add an else that turns off the LED

1 Like

Thanks Max, i guess i typed it in too fast, just wrote this during my work break. lol
so would i say "else (6, LOW);" or do i need to designate a range again?

else digitalWrite(6, LOW);

that's enough.

thanks, Max you are the man!