/* 1. Define connection and data*/
#define RLED 15
#define GLED 13
#define buzzer 4
#include <LiquidCrystal_I2C.h>
#include <TinyGPS++.h>
#include <HardwareSerial.h>
#include <Arduino.h>
#include "HX711.h"
const int LOADCELL_DOUT_PIN = 26;
const int LOADCELL_SCK_PIN = 25;
LiquidCrystal_I2C lcd(0x27,20,4);
TinyGPSPlus gps;
HardwareSerial sim(2);
HardwareSerial gpsSerial(1);
HX711 scale;
float latitude,longitude,speed;
long load;
bool status;
unsigned int i=0;
String myNumber="xxxxxxxxxx";
const int maxLoad=350;
void setup()
{
lcd.init();
lcd.backlight();
loadingdisplay();
pinMode(GLED,OUTPUT);
pinMode(RLED,OUTPUT);
pinMode(buzzer,OUTPUT);
digitalWrite(buzzer,LOW);
digitalWrite(GLED,LOW);
digitalWrite(RLED,LOW);
Serial.begin(115200);
delay(500);
sim.begin(9600, SERIAL_8N1, 17, 16);
delay(500);
gpsSerial.begin(9600, SERIAL_8N1, 19, 18);
Serial.println();
Serial.println("HX711 Demo");
Serial.println("Initializing the scale");
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
digitalWrite( RLED,LOW);
digitalWrite(GLED,LOW);
homedisplay();
delay(2000);
}
void loop()
{
readGPS();
getWeight();
home_display();
if(load>maxLoad)
{
digitalWrite(GLED,HIGH);
digitalWrite(RLED,HIGH);
Alert(2);
String mytext="BAJAJI WITH PLATE NO:Z001ABC AT https://www.google.com/maps?q="+String(latitude)+","+String(longitude)+ "IS OVERLOADED TO "+ String(load)+ "kg";
sendsms(mytext);
status=LOW;
}
else
{
digitalWrite(GLED,HIGH);
digitalWrite(RLED,LOW);
status=HIGH;
}
}
void sendsms(String mytext)
{
sim.println("AT+CMGF=1\r");
delay(100);
sim.println("AT+CMGS=\"" + myNumber + "\"\r");
// sim.println("AT+CMGS=\"" + Phone + "\"\r");
delay(500);
//String message = notification;
sim.println(mytext);
delay(500);
sim.println((char)26);
delay(500);
Serial.println("SMS SENT SUCCESSFULLY");
}
void readGPS()
{
/*
unsigned long start = millis();
while (millis() - start < 1000) {
while (gpsSerial.available() > 0) {
gps.encode(gpsSerial.read());
}
if (gps.location.isUpdated()) {
latitude=gps.location.lat();
longitude=gps.location.lng();
speed=gps.speed.kmph();
Serial.print("LAT: ");
Serial.println(latitude);
Serial.print("LONG: ");
Serial.println(longitude);
Serial.print("SPEED (km/h) = ");
Serial.println(speed);
}
}*/
latitude= random(-900000, 900000) / 10000.0;
longitude = random(-1800000, 1800000) / 10000.0;
Serial.print("LAT: ");
Serial.println(latitude);
Serial.print("LONG: ");
Serial.println(longitude);
}
void getWeight()
{
load=scale.get_units(10);
load=map(load,0,2100,0,500);
Serial.print("LOAD CAPACITY IS:");
Serial.println(load);
}
void loadingdisplay()
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" TRICYCLE OVERLOAD ");
lcd.setCursor(0,1);
lcd.print("*DETECTION & ALERT*");
lcd.setCursor(0,2);
lcd.print(" SYSTEM INITIALIZE ");
lcd.setCursor(0,3);
lcd.print("PLEASE WAIT");
for(int k=11;k<20;k++)
{
lcd.setCursor(k,3);
lcd.print(".");
delay(500);
}
}
void homedisplay()
{
lcd.setCursor(0,0);
lcd.print("TRICYCLE MONITORING ");
lcd.setCursor(0,1);
lcd.print("DETECTION & ALERTING");
lcd.setCursor(0,2);
lcd.print(">OPERATION ACTIVATED");
lcd.setCursor(0,3);
lcd.print("--------<OO>--------");
}
void home_display()
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("TRICYCLE MONITORING ");
lcd.setCursor(0,1);
lcd.print("LOAD (KG):");
lcd.setCursor(10,1);
lcd.print(load);
lcd.setCursor(0,2);
lcd.print("STATUS:");
lcd.setCursor(7,2);
lcd.print(status?"NORMAL":"OVERLOAD");
lcd.setCursor(0,3);
lcd.print("LAT:");
lcd.setCursor(4,3);
lcd.print(latitude);
lcd.setCursor(10,3);
lcd.print("LON:");
lcd.setCursor(14,3);
lcd.print(longitude);
}
void alert_display()
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("OVER LOAD DETECTED");
lcd.setCursor(0,1);
lcd.print("PLEASE TAKE ACTION");
lcd.setCursor(0,2);
lcd.print("SENDING REPORT...");
lcd.setCursor(0,3);
lcd.print("--------<!!>--------");
}
void Alert(uint8_t num)
{
for(num;num>0;num--)
{
tone(buzzer,300);
delay(1000);
noTone(buzzer);
delay(1000);
}
}
TRICYCLE TRACKING AND MONITORING SYSTEM