Sending Voltage using SIM900

Hi,

I’m trying to send the voltage of a battery (12V) with a voltage sensor but i’m struggling and I can’t find why.

In my Serial I can properly see my voltage but nothing happens with my GSM (no SMS received). I’m using an arduino MEGA + GSM module SIM900, I know the wire is good because i can send normal text throught SMS.

But when the part bellow is on the code my GSM module won’t send anything,

“value = analogRead(A1);
vout = (value * 5.0) / 1024.0;
vin = vout / (R2/(R1+R2));
VoltageString = String(vin,2);
delay(500);”

So I’m asking you if anyone knows where it can come from and maybe how to solve it.

#include <SoftwareSerial.h>
SoftwareSerial SIM900(10, 11);

float vout = 0.0;
float vin = 0.0;
float R1 = 30002.0;
float R2 = 7501.0;
int value = 0;

String VoltageString;
String voltagemessage;

void setup()
{
  Serial.begin(9600);
  SIM900.begin(9600);
  delay(1000);
  Serial.println("GSM start...");
}

void loop()
{
  value = analogRead(A1); 
  vout = (value * 5.0) / 1024.0;
  vin = vout / (R2/(R1+R2));
  VoltageString = String(vin,2);
  delay(500);
  
  String voltagemessage = "Voltage = " + VoltageString;
  Serial.println(voltagemessage);

  SIM900.println("at+cmgf=1\r"); // use full functionality (calls, sms, gprs) - see app note
  delay(500);
  SIM900.println("at+clip=1\r"); // enable presentation number
  delay(500);
  SIM900.println("at+cscs=\"GSM\"\r"); // configure sms as standard text messages
  delay(500);
  SIM900.println("at+cnmi=1,2,0,0,0\r"); // alert our GSM shield and now whenever it will receive message
  delay(500);
  SIM900.println("AT+CMGS=\"+33XXXXXXXXX\"");
  delay(500);
  SIM900.println(voltagemessage);
  delay(2000);
  SIM900.println((char)26);
  
  delay(10000);
}

Thanks in advance,

NawaeK

How do you send "normal" text through SMS and how it is different? Maybe try this

//String voltagemessage = "Voltage = " + VoltageString;
String voltagemessage = "Test Message";

Does that work? If so, maybe the '=' or decimal point is messing things up.
If it doesn't work, maybe it has something to do with String?

What I meant when i say “normal text throught SMS” was just like you told me to do so, just text without variable like that :

  /*value = analogRead(A1); 
  vout = (value * 5.0) / 1024.0;
  vin = vout / (R2/(R1+R2));
  VoltageString = String(vin,2);
  delay(500);*/
  
  String voltagemessage = "Voltage = "; //+ VoltageString;
  Serial.println(voltagemessage);

If I’m doing that my code is working perfectly fine. I can receive on my phone "Voltage = ".

But when I start using this :

  value = analogRead(A1); 
  vout = (value * 5.0) / 1024.0;
  vin = vout / (R2/(R1+R2));
  VoltageString = String(vin,2);
  delay(500);

My code stop sending me text messsage, and that’s the weird thing about it.

NawaeK

I allow myself to UP this subject and change his categories.

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