Flood Detector compililing problems

Hi everyone. I’m currently doing a Flood Detector project and there’s quite a problem that I can’t seem to resolve.

I used an Arduino WeMos D1, a SIM900A GSM Module, and an ultrasonic sensor.

Here’s the details on my project:

  1. I used Arduino WeMos D1 acting as an ESP8266 to send my ultrasonic sensor data through Blynk app.
  2. I used SIM900A GSM Module to send warnings through SMS to my phone number.
  3. I created 3 types of warning level which will be displayed on Blynk app. (This works fine.)

The problem that I confront is that I can’t seem to compile the code.

Here’s my code:

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Wire.h>
#include <SoftwareSerial.h>
#include <GSM.h>

SoftwareSerial SIM900A(D10, D11);

#define BLYNK_PRINT Serial
#define trigPin D14
#define echoPin D15

char auth[] = "XXXXXXXX";
char ssid[] = "XXXXXXXX";
char pass[] = "XXXXXXXX";

BlynkTimer timer;

long duration;
int distance;

WidgetLCD lcd(V0);

void setup(){
  Serial.begin(9600);
  SIM900A.begin(9600);
  
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(1000, sendSensor);

  delay(20000);

  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
}

BLYNK_READ(V1){
  Blynk.virtualWrite(V1, distance);
}

void loop(){
  Blynk.run();
  timer.run();
}

void sendSensor(){
  digitalWrite(trigPin, LOW);
  delayMicroseconds(5);

  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  
  digitalWrite(trigPin, LOW);

  duration = pulseIn(echoPin, HIGH);

  distance = (duration/2)/29.1;

  Serial.print("Distance = ");
  Serial.print(distance);
  Serial.println(" cm");

  if(distance <= 100 && distance >= 0){
    lcd.clear();
    lcd.print(4, 0, "DANGER");
    lcd.print(4, 1, "LEVEL");
    SendSMS();
  }
  if(distance <= 299 && distance >= 101){
    lcd.clear();
    lcd.print(4, 0, "WARNING");
    lcd.print(4, 1, "LEVEL");
    SendSMS();
  }
  if(distance <= 400 && distance >= 300){
    lcd.clear();
    lcd.print(4, 0, "SAFE");
    lcd.print(4, 1, "LEVEL");
    SendSMS();
  }
  delay(200);
}

void SendSMS(){
  SIM900A.println("AT+CMGF=1\r");
  delay(1000);
  SIM900A.println("AT+CMGS=\"+xxxxxxxxxxx\"\r"); //Insert phone number
  delay(1000);
  if(distance <= 100 && distance >= 0){
    SIM900A.println("DANGER LEVEL. PLEASE EVACUATE IMMEDIATELY.");
    delay(100);
    SIM900A.println((char)26);
    delay(1000);
  }
  if(distance <= 299 && distance >= 101){
    SIM900A.println("WARNING LEVEL. PLEASE BE PREPARED TO EVACUATE.");
    delay(100);
    SIM900A.println((char)26);
    delay(1000);
  }
  if(distance <= 400 && distance >= 300){
    SIM900A.println("SAFE LEVEL.");
    delay(100);
    SIM900A.println((char)26);
    delay(1000);
  }
}

And here’s my compiler error:

C:\Users\User\Desktop\arduino-nightly\libraries\GSM\src\GSM3SoftSerial.cpp:36:27: fatal error: avr/interrupt.h: No such file or directory

Alternatives for avr/interrupt.h: [] #include <avr/interrupt.h>

                           ^



compilation terminated.

ResolveLibrary(avr/interrupt.h)

  -> candidates: []

Using library ESP8266WiFi at version 1.0 in folder: C:\Users\User\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\libraries\ESP8266WiFi 

Using library Blynk at version 0.6.1 in folder: C:\Users\User\Documents\Arduino\libraries\Blynk 

Using library Wire at version 1.0 in folder: C:\Users\User\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\libraries\Wire 

Using library SoftwareSerial at version 6.9.0 in folder: C:\Users\User\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\libraries\SoftwareSerial 

Using library GSM at version 1.0.6 in folder: C:\Users\User\Desktop\arduino-nightly\libraries\GSM 

exit status 1

Error compiling for board WeMos D1 R1.

I really hoped anyone could help me as I’ve tried few ways to resolve this. Thank you.

Fang.

Yep that is the problem with the GSM.h libarary. It creates it's own version of softwareSerial, using the interrupt vectors for avr boards. Also it doesn't accept passing of a reference to another Serial object. So all in all it's great when used on an AVR board when you want to use swSerial for communicating with the unit. I've looked at modifying the library to accept a referenced Serial object, but it is rather complex. The functionality of GSM.h is very complete, but for most functions it is not difficult to write lines that send commands to the GSM directly. There is full documentation available online on the GSM unit that you have, including a full set of AT commands that you can use. I suggest you go with that.

Deva_Rishi:
Yep that is the problem with the GSM.h libarary. It creates it's own version of softwareSerial, using the interrupt vectors for avr boards. Also it doesn't accept passing of a reference to another Serial object. So all in all it's great when used on an AVR board when you want to use swSerial for communicating with the unit. I've looked at modifying the library to accept a referenced Serial object, but it is rather complex. The functionality of GSM.h is very complete, but for most functions it is not difficult to write lines that send commands to the GSM directly. There is full documentation available online on the GSM unit that you have, including a full set of AT commands that you can use. I suggest you go with that.

Hi, Deva. Thank you for the reply. So all I have to do is to find another way to send SMS directly? If that's what you meant, then I look forward on doing that. Thank you again.
Fang.

So all I have to do is to find another way to send SMS directly? If that's what you meant, then I look forward on doing that.

yep that's what i meant. here there is a pretty elaborate tutorial, and the full list.
Wow that sim900 is huge, i have an 800, which is a lot smaller.