AnswerBun.com

serial 1 was not declared in the scope

Arduino Asked by Mian Yasir shah on July 30, 2020

#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("ATE0r"); ////Disable Echo
  delay(4000);
  Serial1.print("ATr"); ///checking echo
  delay(4000);
  Serial1.print("AT+CMGF=1r");///msg format
  delay(4000);     
}

when i run this code it give me error that serial1 was not decleared in the scope

One Answer

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 by theSealion on July 30, 2020

Add your own answers!

Related Questions

IMU (MPU9250) and Ticker on ESP32

1  Asked on December 10, 2020 by r-ho

     

Where this function is defined?

1  Asked on December 7, 2020 by ravi-s

 

Ultrasonic Sensor(HC-SR04) recording random distance

1  Asked on December 1, 2020 by shubham-bajaj

         

How to save data in arduino when it’s power goes off

3  Asked on December 1, 2020 by user63158

     

Max7219 7-segment display not working

0  Asked on November 29, 2020 by elayer213

   

Unresolved reference to public function from library

1  Asked on November 6, 2020 by omar_hussein

 

SG 90 servos randomly spinning

0  Asked on October 25, 2020

       

void loop() stops running after an hour or so

1  Asked on October 22, 2020 by imrobert7

 

Multiple sensors I2C stop working suddenly

0  Asked on October 6, 2020 by zaffresky

   

Is it possible to exit a loop on the change of an input state?

1  Asked on September 15, 2020 by jabawokjayuk

   

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP