Sim900 not connecting to SIM card

Hi all,

it turns out that we are trying to make HTTP requests to a server in Thinkspeak with a SIM900 module and arduino Mega, but when we run the AT connections, it tells us that the connection to the SIM card is not correct (the led flashes every second). The pins connected from the sim (9, 7 and 8) to the arduino mega (9, 10 and 11), and the SIM card is prepaid.

Any idea what could be the error?

Code:

#include <SoftwareSerial.h>
#include <DHT.h>

#define DHTPIN 7 // Pin del sensor DHT22
#define DHTTYPE DHT22 // Tipo del sensor DHT

SoftwareSerial Sim900Serial(10, 11); // RX, TX del módulo SIM900

DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);
  Sim900Serial.begin(9600); 
  
  // Configura el sensor DHT22
  dht.begin();
  pinMode(9, OUTPUT); // Configura el pin 9 como salida
  digitalWrite(9, HIGH);
  delay(2000);
  digitalWrite(9, LOW);
  delay(20000);
  Serial.println("Good morning forum! ;)");
  Serial.println("Calibrating the system");
  Serial.println("");

  // Configura la conexión GPRS con los datos de tu operador
  Sim900Serial.println("AT");
  ver();
  delay(1000);
  Sim900Serial.println("AT+CPIN=\"xxxx\"");
  ver();
  delay(10000);
}

void loop() {
  delay(2000);
  
  // Lee la temperatura y la humedad del sensor DHT22
  float temperatura = dht.readTemperature();
  float humedad = dht.readHumidity();

  Serial.print("Temperatura: ");
  Serial.print(temperatura);
  Serial.println(" °C");
  Serial.print("Humedad: ");
  Serial.print(humedad);
  Serial.println(" %");

  if (isnan(temperatura) || isnan(humedad)) {
    Serial.println("Error al leer el sensor DHT22.");
    return;
  }
  Sim900Serial.println("AT+CREG=1");//Activar registro de red.
  ver();
  delay(1000);
  Sim900Serial.println("AT+CSQ");
  ver();
  delay(1000);
  Sim900Serial.println("AT+CIPMUX=0");//comando configura el dispositivo para una conexión IP única o múltiple 0=única
  ver();
  delay(3000);

  // Registrarse mediante GPRS
  Sim900Serial.println("AT+CGATT=1");
  ver();
  delay(5000);
  
  // Comando para configurar el APN
  Sim900Serial.println("AT+CSTT=\"internet\",\"\",\"\"");
  ver();
  delay(4000);
  //Sim900Serial.println("AT+CGDCONT?");
  //ver();
  //delay(1000);  
  Sim900Serial.println("AT+CSTT?");
  ver();
  delay(1000);  
  
  // Realizar una conexión inalámbrica con GPRS
  Sim900Serial.println("AT+CIICR");
  ver();
  delay(5000);

  
  // Construye la URL de la solicitud a ThingSpeak
  String datos = "GET /update?api_key=xxx&field1=" + String(temperatura) + "&field2=" + String(humedad) + " HTTP/1.1\r\nHost: api.thingspeak.com\r\n\r\n";
  // Envía los datos al servidor ThingSpeak
  Sim900Serial.println("AT+CIPSTART=\"TCP\",\"api.thingspeak.com\",\"80\"");
  ver();
  delay(10000);
  
  // Envía datos a través de una conexión TCP
  Sim900Serial.println("AT+CIPSEND"); //+ String(datos.length()));
  ver();
  delay(3000);
  Sim900Serial.print(datos);
  ver();
  delay(1000);
  Sim900Serial.println((char)26);
  ver();
  delay(4000);
  Sim900Serial.println();
  delay(4000);
/*
  // Lee y muestra la respuesta del servidor
  while (Sim900Serial.available()) {
    char c = Sim900Serial.read();
    Serial.print(c);
  }
  Serial.println();
*/
  // Cierra la conexión GPRS
  Sim900Serial.println("AT+CIPSHUT");
  ver();
  delay(10000); // Pausa aproximada de 10 segundos
}

void ver(){
  while (Sim900Serial.available()!= 0)
    Serial.write(Sim900Serial.read());
}

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