#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
#include <SoftwareSerial.h>
char Mob[20]="+923319020922";
String stringGPS = "";
String stringGPS1 = "";
char c=0;
int t=0,i;
int buzzer = 9;
int buttonState = 0;
SoftwareSerial mySerial(10, 11); // RX, TX
//const int buttonPin1 =9 ;
int buttonState1 = 0;
int helmetstate=0;
const int relay=8;
char inByte=0;
void setup()
{
lcd.begin(20, 4);
lcd.setCursor(0, 0);
pinMode(relay, OUTPUT);
pinMode(buzzer, OUTPUT);
Serial.begin(9600);
Serial1.begin(9600);
Serial2.begin(9600);
digitalWrite(relay, LOW);
delay(15000);
lcd.print("Config modem....");
Config();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Smart helmet ");
}
void loop()
{
if(Serial2.available())
{
inByte = Serial2.read();
//Serial.write(inByte);
if(inByte=='A'||inByte=='B'||inByte=='C'){
inByte=0;
SMS(Mob);
while(Serial2.available()>0)
{
i = Serial2.read();
}
}
if(inByte=='D')
{
digitalWrite(relay, LOW);
inByte=0;
}
if(inByte=='E')
{
digitalWrite(relay, HIGH);
inByte=0;
}
else
{
}
}
//buttonState = digitalRead(buttonPin);
// if (buttonState == LOW) {
//Serial.print("ok");
//lcd.clear();
// lcd.setCursor(0, 0);
//lcd.print("Sending msg ");
// lcd.setCursor(0, 0);
//lcd.print("Smart helmet ");
// checkGPS();
// SMS(Mob);
//helmet();
checkGPS();
lcd.setCursor(0, 1);
lcd.print(stringGPS1);
//Serial.println(stringGPS1);
}
/*
void helmet()
{
buttonState1 = digitalRead(buttonPin1);
if (buttonState1 == HIGH)
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("SWITCH ON ....... ");
digitalWrite(relay, HIGH);
}
else
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("SWITCH OFF ....... ");
digitalWrite(relay, LOW);
}
}
*/
void checkGPS()
{
// Serial.print("check gps");
// while (Serial.available())
// {
if (Serial.available()>0)
{
// c = Serial.read();
// stringGPS = c;
//Serial.print(c);
while (c != 'R')
{
c = Serial.read();
// Serial.print(c);
}
// if (c== 'R')
// {
// Serial.print(c );
while(t!=41)
{
if (Serial.available())
{
c = Serial.read();
stringGPS += c;
t++;
//Serial.print(stringGPS );
}
}
stringGPS1= stringGPS.substring(15, 41);
// Serial.println(stringGPS1);
t=0;
c=0;
stringGPS = "";
// }
}
}
void SMS(char Mob[20])
{
digitalWrite(buzzer, HIGH);
lcd.setCursor(0, 0);
lcd.print("Sending msg ");
Serial1.print("AT+CMGS=\""); // send the SMS number
Serial1.print(Mob);/// Send mobile number
Serial1.print("\"\r");
delay(4000);
Serial1.print(stringGPS1);// send the SMS Data
Serial1.print("\r");
delay(2000);
Serial1.write(0x1A); ///Ctrl+Z
delay(1000);
Serial1.write(0x0A); ///Carrige return
delay(1000);
Serial1.write(0x0D); ///line feed
delay(1000);
stringGPS1 = "";
lcd.setCursor(0, 0);
lcd.print("Smart helmet ");
digitalWrite(buzzer, LOW);
}
void Config()/////configuration for sim900
{
delay(4000);
Serial1.print("ATE0\r"); ////Disable Echo
delay(4000);
Serial1.print("AT\r"); ///checking echo
delay(4000);
Serial1.print("AT+CMGF=1\r");///msg format
delay(4000);
}
when i run this code it give me error that serial1 was not decleared in the scope
Serial1andSerial2. Why did you try to use them? Or are you simply compiling for the wrong board type? What Arduino do you have? – chrisl Feb 25 '20 at 08:50