0% found this document useful (0 votes)
62 views

Ztable 2

This document contains code for an Arduino project that collects data from a GPS module, BME280 sensor, and sends it to a Blynk dashboard. It includes code to initialize libraries and pins for the sensors, read data from the sensors, send it to Blynk, and code for a button to trigger sending an email with a report of the sensor data.

Uploaded by

Yosua Siregar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views

Ztable 2

This document contains code for an Arduino project that collects data from a GPS module, BME280 sensor, and sends it to a Blynk dashboard. It includes code to initialize libraries and pins for the sensors, read data from the sensors, send it to Blynk, and code for a button to trigger sending an email with a report of the sensor data.

Uploaded by

Yosua Siregar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

#include <Ethernet.

h>
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <TimeLib.h>
#include <WidgetRTC.h>

#define D5 14
#define D6 12
#define D7 13
#define D8 15

const int konek = 5;

// assign the SPI bus to pins


#define BME_SCK D5
#define BME_MOSI D6
#define BME_CS D7
#define BME_MISO D8

unsigned count = 0;

byte Simbol_derajat = B11011111;

#define SEALEVELPRESSURE_HPA (1013.25)

Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK);

static const int RXPin = 0, TXPin = 2; // 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

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

BlynkTimer timer;

WidgetRTC rtc;

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[] = "5a8d7166f26440a3a056c0bda946f2b1"; //Your Project


authentication key
char ssid[] = "Vrostia"; // Name of your
network (HotSpot or Router name)
char pass[] = "agungkurniawan"; //
Corresponding Password
const int kirim = 16;

int button1 = 0;

void clockDisplay()
{
// You can call hour(), minute(), ... at any time
// Please see Time library examples for details

String currentTime = String(hour()) + ":" + minute() ":" + second();


String currentDate = String(day()) + " " + month() + " " + year();
Serial.print("Current time: ");
Serial.print(currentTime);
Serial.print(" ");
Serial.print(currentDate);
Serial.println();

// Send time to the App


Blynk.virtualWrite(V10, currentTime);
// Send date to the App
Blynk.virtualWrite(V11, currentDate);
}

//unsigned int move_index; // moving index, to be used later


unsigned int move_index = 1; // fixed location for now

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println();
Wire.begin(4,5);
bool status;

//default settings
status = bme.begin();
if (!status) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}

Serial.println("-- Default Test --");

Serial.println();

ss.begin(GPSBaud);
Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
timer.setInterval(500L, checkGPS); // every 5s check if GPS is connected, only
really needs to be done once
pinMode (konek, OUTPUT);
setSyncInterval(10 * 60); // Sync interval in seconds (10 minutes)
timer.setInterval(500L, clockDisplay);

pinMode (kirim, INPUT);


pinMode (kirim, LOW);

/* Blynk.email("arifpariaman16@gmail.com", "Subject", "My Blynk project is


online.");
// Setting the button
pinMode(10, INPUT_PULLUP);
// Attach pin 10 interrupt to our handler
attachInterrupt(digitalPinToInterrupt(10), emailOnButtonPress, CHANGE);
*/
}
BLYNK_CONNECTED(){
rtc.begin();
digitalWrite(konek, HIGH);
//Blynk.syncVirtual(V14);

void checkGPS(){
if (gps.charsProcessed() < 10)
{
Serial.println(F("No GPS detected: check wiring."));
Blynk.virtualWrite(V4, "GPS ERROR"); // Value Display widget on V4 if GPS
not detected
}

void loop() {
// put your main code here, to run repeatedly:
while (ss.available() > 0)
{
// sketch displays information every time a new sentence is correctly
encoded.
if (gps.encode(ss.read()))
displayInfo();
}
Blynk.run();
timer.run();
}

void displayInfo()
{
float latitude = (gps.location.lat()); //Storing the Lat. and Lon.
float longitude = (gps.location.lng());
if (gps.location.isValid() )
{

//float latitude = (gps.location.lat()); //Storing the Lat. and Lon.


//float longitude = (gps.location.lng());

Serial.print("LAT: ");
Serial.println(latitude, 6); // float to x decimal places
Serial.print("LONG: ");
Serial.println(longitude, 6);
Blynk.virtualWrite(V1, String(latitude, 6));
Blynk.virtualWrite(V2, String(longitude, 6));
myMap.location(move_index, latitude, longitude, "GPS_Location");
spd = gps.speed.kmph(); //get speed
Blynk.virtualWrite(V3, spd);
sats = gps.satellites.value(); //get number of satellites
Blynk.virtualWrite(V4, sats);

bearing = TinyGPSPlus::cardinal(gps.course.value()); // get the direction


Blynk.virtualWrite(V5, bearing);

Serial.println();
float h = bme.readHumidity();
float t = bme.readTemperature();
float p = bme.readPressure() / 100.0F;
float alt = bme.readAltitude(SEALEVELPRESSURE_HPA);
Serial.print("Temperature = ");
Serial.print(bme.readTemperature());
Serial.println(" °C");
Blynk.virtualWrite(V6, t);

Serial.print("Pressure = ");

Serial.print(bme.readPressure() / 100.0F);
Serial.println(" hPa");
Serial.println(" ");
Blynk.virtualWrite(V8, p);

Serial.print("Approx. Altitude = ");


Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
Serial.println(" m");
Blynk.virtualWrite(V9, alt);

Serial.print("Humidity = ");
Serial.print(bme.readHumidity());
Serial.println(" %");
Blynk.virtualWrite(V7, h);

Serial.println();

delay(2000);

String currentTime = String(hour()) + ":" + minute()+ ":" + second();


String currentDate = String(day()) + " " + month() + " " + year();
String emailbody = "laporan cuaca hari ini " + currentDate + " Start from 00.00
WIB (GMT+7) until now " + currentTime +"Lokasi alat"+ "Latitude" + latitude+
"Longitude" + longitude + t + " C" + h + "%" + p + "pa" + alt + "m";

button1 = digitalRead(kirim);
if (button1 == HIGH) //You can write any condition to trigger e-mail sending
{
Serial.println("Button is pressed."); // This can be seen in the Serial Monitor
Blynk.virtualWrite(V15,">Sending email to : arifpariaman16@gmail.com",
emailbody);
Blynk.email("arifpariaman16@gmail.com", "Subject: cuaca hari ini", emailbody );

}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy