APPENDIX A: Programming for This Project
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
static const int RXPin = 4, TXPin = 5 ; // GPIO 4=D2(conneect Tx of GPS) and GPIO
5=D1(Connect Rx of GPS
static const uint32_t GPSBaud = 9600; //if Baud rate 9600 didn't work in your case then
use 4800
TinyGPSPlus gps; // The TinyGPS++ object
WidgetMap myMap(V0); // V0 for virtual pin of Map Widget
WidgetLCD lcd(V10);
SoftwareSerial ss (RXPin, TXPin); // The serial connection to the GPS device
BlynkTimer timer;
float spd; //Variable to store the speed
float sats; //Variable to store no. of satellites response
String bearing; //Variable to store orientation or direction of GPS
char auth[] = "L-QGOUmduimCnCjlwaCEBdA5TDg6Tatp"; //Your Project
authentication key
char ssid[] = "OppoA93"; // Name of your network (HotSpot or
Router name)
char pass[] = "aqilahizni"; // Corresponding Password
//unsigned int move_index; // moving index, to be used later
unsigned int move_index = 1; // fixed location for now
int smokeA0 = A0;
int analogSensor = 0;
void setup()
[Link](115200);
[Link]();
[Link](GPSBaud);
[Link](auth, ssid, pass);
pinMode(smokeA0, INPUT);
pinMode(15,OUTPUT);
[Link](); //Use it to clear the LCD Widget
[Link] (3, 0," SENSOR "); // use: (position X: 0-15, position Y: 0-1, "Message you want
to print")
[Link] (2, 1,"A B");
[Link](1000L, checkGPS); // every 5s check if GPS is connected, only really needs
to be done once
void checkGPS(){
if ([Link]() < 10)
[Link](F("No GPS detected: check wiring."));
[Link](V4, "GPS ERROR"); // Value Display widget on V4 if GPS not detected
}
void loop()
{
// analogSensor=analogRead(A0);
while ([Link]() > 0)
{
// sketch displays information every time a new sentence is correctly encoded.
if ([Link]([Link]()))
// Please use timed events when LCD printintg in void loop to avoid sending too many
commands
// It will cause a FLOOD Error, and connection will be dropped
displayInfo();
}
[Link]();
[Link]();
}
void displayInfo()
{
analogSensor = analogRead(smokeA0);
if ([Link]() )
{
float latitude = ([Link]()); //Storing the Lat. and Lon.
float longitude = ([Link]());
[Link]("LAT: ");
[Link](latitude, 6); // float to x decimal places
[Link]("LONG: ");
[Link](longitude, 6);
[Link]("Sensor: ");
[Link](analogSensor);
[Link](V4, String(latitude, 6));
[Link](V5, String(longitude, 6));
[Link](V6, analogSensor);
[Link](move_index, latitude, longitude, "GPS_Locations");
}
if(analogSensor>250)
{
[Link]("SENSOR B");
digitalWrite(15,HIGH); // ikut GPIO pinout
else
{
digitalWrite(15,LOW); // ikut GPIO pinout
}
[Link]();