Why does my sim800l does not receiving message when it was compile with oled screen?

hello, why does my sim800l does not receiving message when it was compile with oled screen. This is my code


#include <SoftwareSerial.h>
#include <Arduino.h>
#include <U8g2lib.h>
#include <Wire.h> // Include the Wire library for I2C communication
#include <BH1750.h> // Include the BH1750 library
#include <Servo.h>
#include <NewPing.h>

U8G2_SSD1309_128X64_NONAME2_1_HW_I2C u8g2(U8G2_R0, /*clock=*/SCL, /*data=*/ SDA,/* reset=*/ U8X8_PIN_NONE);
BH1750 lightMeter; // Create an instance of the BH1750 sensor

// End of constructor list
#include "DHT.h"
#define DHTPIN 8// Digital pin connected to the DHT sensor
// Uncomment whatever type you're using!
#define DHTTYPE DHT11  // DHT 11
//#define DHTTYPE DHT22 // DHT 22
#define rxPin 2
#define txPin 3
#define RELAY_1 13

char str[10];

SoftwareSerial sim800(rxPin,txPin);
DHT dht(DHTPIN, DHTTYPE);
// Threshold values
#define TEMP_UPPERLIMIT 28
#define TEMP_LOWERLIMIT 5
#define HUM_UPPERLIMIT 96
#define HUM_LOWERLIMIT 10
#define LUX_UPPERLIMIT 2000.00
#define LUX_LOWERLIMIT 10.00
#define SENSOR_EXE_INTERVAL 500
#define EXE_INTERVAL 60000

unsigned long lux_lastExecutedMillis = 0;
unsigned long hum_lastExecutedMillis = 0;
unsigned long temp_lastExecutedMillis = 0;
unsigned long sensor_fetch_lastExecutedMillis = 0;
const unsigned long OneMinute = 60UL * 1000UL;
const unsigned long OneHour = 60UL * OneMinute;
const unsigned long TwentyFourHours = 24 * OneHour;
unsigned long stopTime = 1 * OneMinute;
unsigned long startTime = 0;
bool lux_ready_state = true;
bool hum_ready_state = true;
bool temp_ready_state = true;
boolean STATE_RELAY_1 = 0;
float lux = 0;
float humidity = 0;
float temp = 0;
// const String PHONE = "";
const String PHONE = "YourPhoneNumber";
String smsStatus,senderNumber,receivedDate,msg;


void setup() {
  Serial.begin(9600);
  Serial.println(F("Hello GreMoR 2.0 !"));
  Serial.println("SIM800L software serial initialize");
  
  dht.begin(); 
  u8g2.begin();  
    lightMeter.begin(); // Initialize the BH1750 sensor
    Wire.begin();

    if (lightMeter.begin()) {
    Serial.println(F("BH1750 initialised"));
  }
  else {
    Serial.println(F("Error initialising BH1750"));
  }

  Serial.println(F("BH1750 Test begin"));
  
  pinMode(RELAY_1, OUTPUT); //Relay 1
  digitalWrite(RELAY_1, LOW);

  sim800.begin(9600);
  sim800.println("AT+CMGF=1");
  delay(1000);
  sim800.println("AT+CNMI=1,1,0,0,0"); 
  delay(1000);
}

void loop(){
  // Reading temperature or humidity takes about 250 milliseconds!
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) ) {
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }

  float hic = dht.computeHeatIndex(t, h, false);
  u8g2.firstPage();  
  do {
    u8g2.setFont(u8g_font_helvB08);
    u8g2.clearBuffer();
    u8g2.drawStr( 0, 15, "GreMoR 2.0");
    
    u8g2.drawStr( 0, 30, "Humidity:");
    u8g2.drawStr( 80, 30, dtostrf(h, 5, 2, str));
    u8g2.drawStr( 110, 30, "%");
    
    u8g2.drawStr( 0, 40, "Temperature:");
    u8g2.drawStr( 80, 40, dtostrf(t, 5, 2, str));
    u8g2.drawStr( 110, 40, "\260C");

    u8g2.drawStr( 0, 55, "Light Int:");
    u8g2.drawStr( 60, 55, dtostrf(lux, 5, 2, str));
    u8g2.drawStr( 110, 55, "lux");
       
  } while( u8g2.nextPage() ); {

  }
   while(sim800.available()){
    parseData(sim800.readString());
  }
  //////////////////////////////////////////////////
  while(Serial.available())  {
    sim800.println(Serial.readString());
  }
  unsigned long currentMillis = millis();

 if (!lux_ready_state && currentMillis - lux_lastExecutedMillis >= EXE_INTERVAL) {
    lux_ready_state = true;
  }
  if (!hum_ready_state && currentMillis - hum_lastExecutedMillis >= EXE_INTERVAL) {
    hum_ready_state = true;
  }
  if (!temp_ready_state && currentMillis - temp_lastExecutedMillis >= EXE_INTERVAL) {
    temp_ready_state = true;
  }

  if ( currentMillis - sensor_fetch_lastExecutedMillis >= SENSOR_EXE_INTERVAL) {
   lux = get_sensor_lux();
   humidity = get_sensor_humidity();
   temp = get_sensor_temperature();
  sensor_fetch_lastExecutedMillis = currentMillis;
  }
   
  if(lux_ready_state && lux >= LUX_UPPERLIMIT){
    // stop wheels 
    Reply(create_message("Light Intensity","lux",lux));
    lux_lastExecutedMillis = currentMillis; // save the last executed time
    lux_ready_state = false;
  }

  if(hum_ready_state && humidity >= HUM_UPPERLIMIT){
    Reply(create_message("Humidity","%",humidity));
    hum_lastExecutedMillis = currentMillis; // save the last executed time
    hum_ready_state = false;
  }

  if(temp_ready_state && temp >= TEMP_UPPERLIMIT){
    Reply(create_message("Temperature","Celcius",temp));
    temp_lastExecutedMillis = currentMillis; // save the last executed time
    temp_ready_state = false;
  }

  if(STATE_RELAY_1 == 1 and startTime > 0){
  //____________________________________________
    if(currentMillis - startTime >= stopTime) {
      STATE_RELAY_1 = 0;
      digitalWrite(RELAY_1, LOW);
      startTime = 0;
    }
  }
}

void parseData(String buff) {
  Serial.println(buff);
  
  unsigned int len, index;
  //Remove sent "AT Command" from the response string.
  index = buff.indexOf("\r");
  buff.remove(0, index+2);
  buff.trim();

  if(buff != "OK"){
    index = buff.indexOf(":");
    String cmd = buff.substring(0, index);
    cmd.trim();
    
    buff.remove(0, index+2);
    
    if(cmd == "+CMTI"){
      //get newly arrived memory location and store it in temp
      index = buff.indexOf(",");
      String temp = buff.substring(index+1, buff.length()); 
      temp = "AT+CMGR=" + temp + "\r"; 
      //get the message stored at memory location "temp"
      sim800.println(temp); 
    }
    else if(cmd == "+CMGR"){
      extractSms(buff);
      Serial.println(msg);
      Serial.println(senderNumber);
      
      if(senderNumber == PHONE && msg == "get parameters"){
          Reply(get_temperature());
      }
    }
  }
   else{
  //The result of AT Command is "OK"
  }
  if(buff.indexOf("RING") > -1)
  {
    //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
    //+CLIP: "03001234567",129,"",0,"",0
    if(buff.indexOf("+CLIP:")){
     unsigned int index, index1;
      index = buff.indexOf("\"");
      index1 = buff.indexOf("\"", index+1);
      //get phone like this format 03001234567
      senderNumber = buff.substring(index+1, index1);
      senderNumber.trim();
      Serial.println("Caller ID: ");
    }
    //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
    //terminate the call
    sim800.println("ATH");
    delay(100);
    //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
    //turn on the relay1
    if(STATE_RELAY_1 == 0){
      STATE_RELAY_1 = 1;
      digitalWrite(RELAY_1, HIGH);
      startTime = millis();
      Serial.println("Relay 1 is ON");   
    }
    //turn off the relay1
    else {
      STATE_RELAY_1 = 0;
      digitalWrite(RELAY_1, LOW);
      startTime = 0;
      Serial.println("Relay 1 is OFF");
    }
    return;
  }
  //Remove sent "AT Command" from the response string.
  index = buff.indexOf("\r");
  buff.remove(0, index+2);
  buff.trim();
  //---------------------------------------------------------------------
  //do nothing
  if(buff == "OK")
    {return;}
}
//************************************************************
String get_temperature()
{
  float h = dht.readHumidity();
  //Read temperature as Celsius (the default)
  float t = dht.readTemperature();
  float lux = lightMeter.readLightLevel();
    
  
  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t)) {
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }
  
  float hic = dht.computeHeatIndex(t, h, false);
  //°C
  String humidity = "Humidity: " + String(h) + "%";
  String temperature = "Temperature: " + String(t) + " Celsius";
  String light_intensity = "Light Intensity: " + String(lux) + " lux";

  return humidity + "\n" + temperature + "\n" + light_intensity + "\n";
}

void Reply(String text)
{
    Serial.println("Replying");
    sim800.print("AT+CMGF=1\r");
    delay(1000);
    sim800.print("AT+CMGS=\""+PHONE+"\"\r");
    delay(1000);
    sim800.print(text);
    delay(1000);
    sim800.write(0x1A); //ascii code for ctrl-26 //sim800.println((char)26); //ascii code for ctrl-26
    delay(1000);
    Serial.println("SMS Sent Successfully.");
}

void extractSms(String buff){
   unsigned int index;
   
    index = buff.indexOf(",");
    smsStatus = buff.substring(1, index-1); 
    buff.remove(0, index+2);
    
    senderNumber = buff.substring(0, 13);
    buff.remove(0,19);
   
    receivedDate = buff.substring(0, 20);
    buff.remove(0,buff.indexOf("\r"));
    buff.trim();
    
    index =buff.indexOf("\n\r");
    buff = buff.substring(0, index);
    buff.trim();
    msg = buff;
    buff = "";
    msg.toLowerCase();
}

 String create_message(String name, String unit, float value){  
  return name + " (" + String(value) + " " + unit + ") exceeds the threshold.";
 }
 float get_sensor_humidity(){
  //Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();

  // Check if any reads failed and exit early (to try again).
  if (isnan(h)) {
    Serial.println(F("Failed to read from Humidity sensor!"));
    return 0;
  }
  return h;
 }
float get_sensor_lux(){
  //Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float lux = lightMeter.readLightLevel();

  // Check if any reads failed and exit early (to try again).
  if (isnan(lux)) {
    Serial.println(F("Failed to read from BH1750 sensor!"));
    return 0;
  }
  return lux;
  }
float get_sensor_temperature(){
  //Read temperature as Celsius (the default)
  float t = dht.readTemperature();

  // Check if any reads failed and exit early (to try again).
  if (isnan(t)) {
    Serial.println(F("Failed to read from Temperature sensor!"));
    return 0;
  }
  return t;
}`

Please don't hijack threads @francis_02. I have split your post out to its own topic and deleted the other hijack post.

Hijacking is against the Arduino forum rules. The reason is that it may sidetrack the discussion, even preventing the creator of the topic from getting the assistance they need. It also reduces your own chances of getting assistance.

Cross-posting is against the Arduino forum rules. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend a lot of time investigating and writing a detailed answer on one topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting can result in a suspension from the forum.

This is basic forum etiquette, as explained in the "How to get the best out of this forum" guide. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

Please edit your post, select all code and click the <CODE/> button; next save your post. This will apply codce tags which will make the code easier to read, easier to copy and the forum software will display it correctly.

Please provide links to any non-standard libraries (or tell us which one you installed from library manager) so we don't have to hunt for them in case we don't have them and possibly end up with the wrong one.

Is it correct to say that your SIM receives messages when you remove the OLED code and does not receive messages when you include the OLED code?

Which board are you compiling for? What does the memory report say at the end of the compilation; any chance that you are low on memory?

Yes, it is correct. The board that I am using is Uno R3

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.