0
#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

asked Feb 25, 2020 at 6:30
3
  • The board, that you are compiling for, does not have Serial1 and Serial2. Why did you try to use them? Or are you simply compiling for the wrong board type? What Arduino do you have? Commented Feb 25, 2020 at 8:50
  • 1
    What board are you using? If it's not one of the bigger boards then what makes you think it would have Serial1 and Serial2? Commented Feb 25, 2020 at 10:02
  • If you had formatted your code in a readable manner you would see, that there are too many closing curly braces . One in your loop function and two in the code at the end. Correct formatting makes the code readable and let you find your mistakes easier. Commented Feb 25, 2020 at 12:15

1 Answer 1

1

The only SoftwareSerial you a declaring is SoftwareSerial mySerial(10, 11); // RX, TX (And you you didn't use it afterwards).

If the hardware serials Serial1, Serial2 or Serial3 are available
(and already declared in the arduino.h header depends on the board you are using.

answered Feb 25, 2020 at 8:04

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.