Receive 1st text message from sensor but not the other??? HELP PLS????

Can someone please take a quick look at this and tell me why the first sensor text messages me when it reaches its pre defined but the 2nd sensor does not??? It would seem as though it tries to but no message is received??? Also, can somebody please please please tell me how to send the message only onetime or a better method to do so as it keeps repeatedly sending me a text message whilst the sensor stays at the same value.

Thanks to anyone who can help. Much appreciated!

PS. I had to do digital inputs with the analog sensors and use RCTime because the analog inputs wouldnt function correctly.

#include <NewSoftSerial.h> //Include the NewSoftSerial library to send serial commands to the cellular module.
#include <string.h> //Used for string manipulations

char incoming_char=0; //Will hold the incoming character from the Serial Port.

NewSoftSerial cell(2,3); //Create a ‘fake’ serial port. Pin 2 is the Rx pin, pin 3 is the Tx pin.

int sensorPin = 8; // 220 or 1k resistor connected to this pin.
int sensorPin10 = 10; // 220 or 1k resistor connected to this pin
long result = 0;
void setup() // run once, when the sketch starts
{

Serial.begin(9600);
Serial.println(“Start the SIM and Register Network”);
cell.begin(9600);
}

void loop() // run over and over again
{
if(cell.available() >0)
{
incoming_char=cell.read();
Serial.print(incoming_char);
}
if(Serial.available() >0)
{
incoming_char=Serial.read();
cell.print(incoming_char);
}
Serial.println( RCtime(sensorPin) );
delay(500);
Serial.println( RCtime(sensorPin10) );
delay(600);

if ( RCtime(sensorPin) == 9) //Hopefully will execute when level reaches defined level
{
cell.println(“at+cmgf=1”); //Sets the message mode to text
delay (100);
cell.print(“at+cmgs=”); //The start of the send message command
cell.print(34,BYTE); //This sends the character "
cell.print(“xxxxxxxxxx”); //Mobile Number!
cell.println(34,BYTE); //Another "
cell.print(“xxxxxxxxxx”); //The message
cell.print(26,BYTE); //This sends ‘ctrl-z’ to end the command
}
}
long RCtime(int sensorPin){
long result = 0;
pinMode(sensorPin, OUTPUT); // make pin OUTPUT
digitalWrite(sensorPin, HIGH); // make pin HIGH to discharge capacitor - study the schematic
delay(1); // wait a ms to make sure cap is discharged

pinMode(sensorPin, INPUT); // turn pin into an input and time till pin goes low
digitalWrite(sensorPin, LOW); // turn pullups off - or it won’t work
while(digitalRead(sensorPin)){ // wait for pin to go low
result++;
}

return result; // report results

if(cell.available() >0)
{
incoming_char=cell.read();
Serial.print(incoming_char);
}
if(Serial.available() >0)
{
incoming_char=Serial.read();
cell.print(incoming_char);
}
if ( RCtime(sensorPin10) == 2) //Hopefully will execute when level reaches defined level
{
cell.println(“at+cmgf=1”); //Sets the message mode to text
delay (100);
cell.print(“at+cmgs=”); //The start of the send message command
cell.print(34,BYTE); //This sends the character "
cell.print(“xxxxxxxxxx”); //Mobile Number!
cell.println(34,BYTE); //Another "
cell.print(“xxxxxxxxxx”); //The message
cell.print(26,BYTE); //This sends ‘ctrl-z’ to end the command

long RCtime(int sensorPin10);
long result = 0;
pinMode(sensorPin10, OUTPUT); // make pin OUTPUT
digitalWrite(sensorPin10, HIGH); // make pin HIGH to discharge capacitor - study the schematic
delay(1); // wait a ms to make sure cap is discharged

pinMode(sensorPin10, INPUT); // turn pin into an input and time till pin goes low
digitalWrite(sensorPin10, LOW); // turn pullups off - or it won’t work
while(digitalRead(sensorPin10)){ // wait for pin to go low
result++;
}

return result; // report results

Can someone please take a quick look at this and tell me why

I tried. But, that code is very hard to read.

First, it is posted incorrectly. You did not use the code icon (the one with the # on it) when posting the code.

Second, you did not use Tools + Auto Format to clean up the incorrect indentation before posting the code.

Third, that code will not even compile. There are missing } at least at the end.

if ( RCtime(sensorPin) == 9)  //Hopefully will execute when level reaches defined level

This comment is useless. Why would RCtime() return 9? What significance does 9 have? THAT is what the comment should explain.

   while(digitalRead(sensorPin)){    // wait for pin to go low
      result++;
   }

What is the significance of incrementing result as fast as possible while waiting for the pin to go LOW? The value that ends up in result is only indirectly a measure of time. The amount of time that it measures is a function of how long digitalRead() takes. Do you know how long that is? Do you see the unlikelyhood of it being exactly 9?

   return result;                   // report results 
 
   if(cell.available() >0)
  {
    incoming_char=cell.read();
    Serial.print(incoming_char);
  }
  if(Serial.available() >0)
  {
    incoming_char=Serial.read();
    cell.print(incoming_char);
  }
if ( RCtime(sensorPin10) == 2)  //Hopefully will execute when level reaches defined level
{
  cell.println("at+cmgf=1");   //Sets the message mode to text
  delay (100);
  cell.print("at+cmgs=");      //The start of the send message command
  cell.print(34,BYTE);         //This sends the character "
  cell.print("xxxxxxxxxx");        //Mobile Number!
  cell.println(34,BYTE);       //Another "
  cell.print("xxxxxxxxxx");          //The message
  cell.print(26,BYTE);         //This sends 'ctrl-z' to end the command

long RCtime(int sensorPin10);
   long result = 0;
   pinMode(sensorPin10, OUTPUT);       // make pin OUTPUT
   digitalWrite(sensorPin10, HIGH);    // make pin HIGH to discharge capacitor - study the schematic
   delay(1);                       // wait a  ms to make sure cap is discharged

   pinMode(sensorPin10, INPUT);        // turn pin into an input and time till pin goes low
   digitalWrite(sensorPin10, LOW);     // turn pullups off - or it won't work
   while(digitalRead(sensorPin10)){    // wait for pin to go low
      result++;
   }

   return result;                   // report results

The return statement says “We’re done”. None of the rest of the code after that is ever executed. You might as well delete it.

long RCtime(int sensorPin10);

You want to explain what you think this is doing? It is not calling the function.

Thanks PaulS for your reply.

Sorry for all my mistakes. I copy n pasted and left out the }} at the end.

Have Corrected long RCtime(int sensorPin10); to long RCtime(int sensPin); and every other instance also.

Sorry again this was meant to read if ( RCtime(sensorPin) == X)  //Hopefully will execute when level reaches defined level X ofcourse being a predefined/calculated value.

This is not my problem though. I can monitor the values via serial monitor and the sim connects successfully to the network. The issue i am having is this: I have the 1st sensor sending a text message when it reads a certain value. However the 2nd sensor does not send a text message when it reads its value.

The following code works perfectly but it is for one sensor only. Can someone please extend it so i can use more sensors. I extended it but the 2nd sensor does not send the message. There is an extremely high chance i extended it incorrectly. Any Help would be greatly appreciated!!

#include <NewSoftSerial.h>  //Include the NewSoftSerial library to send serial commands to the cellular module.
#include <string.h>         //Used for string manipulations
char incoming_char=0;      //Will hold the incoming character from the Serial Port.
NewSoftSerial cell(2,3);  //Create a 'fake' serial port. Pin 2 is the Rx pin, pin 3 is the Tx pin.

int sensorPin = 8;              // 220 or 1k resistor connected to this pin
long result = 0;
void setup()                    // run once, when the sketch starts
{
   Serial.begin(9600);
   Serial.println("Start SIM and Register Network");
     cell.begin(9600);
  }

void loop()                     // run over and over again
{
   if(cell.available() >0)
  {
    incoming_char=cell.read();
    Serial.print(incoming_char);
  }
  if(Serial.available() >0)
  {
    incoming_char=Serial.read();
    cell.print(incoming_char);
  }
    Serial.println( RCtime(sensorPin) );
   delay(500);
  
if ( RCtime(sensorPin) == X)  //Hopefully will execute when level reaches defined level 
{
  cell.println("at+cmgf=1");   //Sets the message mode to text
  delay (100);
  cell.print("at+cmgs=");      //The start of the send message command
  cell.print(34,BYTE);         //This sends the character "
  cell.print("xxxxxxxxxx");        //Mobile Number!
  cell.println(34,BYTE);       //Another " 
  cell.print("xxxxxxxxxx");          //The message
  cell.print(26,BYTE);         //This sends 'ctrl-z' to end the command
}
}
long RCtime(int sensorPin){
   long result = 0;
   pinMode(sensorPin, OUTPUT);       // make pin OUTPUT
   digitalWrite(sensorPin, HIGH);    // make pin HIGH to discharge capacitor - study the schematic
   delay(1);                       // wait a  ms to make sure cap is discharged

   pinMode(sensorPin, INPUT);        // turn pin into an input and time till pin goes low
   digitalWrite(sensorPin, LOW);     // turn pullups off - or it won't work
   while(digitalRead(sensorPin)){    // wait for pin to go low
      result++;
   }

   return result;                   // report results   
}

Oh and can we stop it from repeatedly sending the text message while the sensor keeps ready the predefined value? Can we make it so that it only sends 1 text once when its reads the required value?? Thanks Heaps!

Post the code where you tried two sensors. One thing that would probably make it easier to do would be to write a function that takes a string and sends it as a text message. You could also pass the phone number, but I doubt it's necessary in this case.

I have the 1st sensor sending a text message when it reads a certain value. However the 2nd sensor does not send a text message when it reads its value.

With that last code, you are only calling the function for one sensor.

Second, you did not use Tools + Auto Format to clean up the incorrect indentation before posting the code.

And you still haven't. Although that code looks a LOT better, it will not compile. X is not defined.

The function still doesn't make sense. The value you get from that function is n time intervals, where it does not appear that you have any idea what the time interval is. So, how can the number of intervals mean anything?

Oh and can we stop it from repeatedly sending the text message while the sensor keeps ready the predefined value?

Yes. Store the return value from the function in a variable. If the value this time is not the same as the value last time, and it is the correct value, send a message.

int prevVal = 0; // global

void loop()
{
  // some stuff
  int currVal = RCtime(sensorPin1);
  if(currVal != prevVal && currVal == X)
  {
     // send a mesage
  }
  prevVal = currVal;
  // more stuff
}

Thank you for everyones help. Final code for 2x Sensors- works great.

#include <NewSoftSerial.h>  //Include the NewSoftSerial library to send serial commands to the cellular module.
#include <string.h>         //Used for string manipulations

char incoming_char=0;      //Will hold the incoming character from the Serial Port.

NewSoftSerial cell(2,3);  //Create a 'fake' serial port. Pin 2 is the Rx pin, pin 3 is the Tx pin.

int sensorPin = 8;              // 220 resistor connected to this pin
int sensorPin10 = 10;              // 220 resistor connected to this pin
long result = 0;
int prevVal = 0; 
int prevVal2 =0;

void setup()                    
{

  Serial.begin(9600);
  Serial.println("Start the SIM and Register Network");
  cell.begin(9600);
  Serial.println("Sim Initialised...");

}

void loop()                     
{
  if(cell.available() >0)
  {
    incoming_char=cell.read();
    Serial.print(incoming_char);
  }
  if(Serial.available() >0)
  {
    incoming_char=Serial.read();
    cell.print(incoming_char);
  }
  Serial.println( RCtime(sensorPin) );
  delay(500);
  Serial.println( RCtime(sensorPin10) );
  delay(600);

  int currVal = RCtime(sensorPin);

  if(currVal != prevVal && currVal == 20)
  {
    cell.println("at+cmgf=1");   //Sets the message mode to text
    delay (100);
    cell.print("at+cmgs=");      //The start of the send message command
    cell.print(34,BYTE);         //This sends the character "
    cell.print("xxxxxxxxxx");        //Mobile Number!
    cell.println(34,BYTE);       //Another " 
    cell.print("xxxxxxxxxx");          //The message
    cell.print(26,BYTE);         //This sends 'ctrl-z' to end the command
  }
  prevVal = currVal;

  int currVal2 = RCtime(sensorPin10);
  if(currVal2 != prevVal2 && currVal2 == 25)
  {
    cell.println("at+cmgf=1");   //Sets the message mode to text
    delay (100);
    cell.print("at+cmgs=");      //The start of the send message command
    cell.print(34,BYTE);         //This sends the character "
    cell.print("xxxxxxxxxx");        //Mobile Number!
    cell.println(34,BYTE);       //Another " 
    cell.print("xxxxxxxxxx");          //The message
    cell.print(26,BYTE);         //This sends 'ctrl-z' to end the command
  }
  prevVal2 = currVal2;

}
long RCtime(int sensPin){
  long result = 0;
  pinMode(sensPin, OUTPUT);       // make pin OUTPUT
  digitalWrite(sensPin, HIGH);    // make pin HIGH to discharge capacitor - study the schematic
  delay(1);                       // wait a  ms to make sure cap is discharged

  pinMode(sensPin, INPUT);        // turn pin into an input and time till pin goes low
  digitalWrite(sensPin, LOW);     // turn pullups off - or it won't work
  while(digitalRead(sensPin)){    // wait for pin to go low

    result++;
  }

  return result;                   // report results 

}

As for this part

int currVal = RCtime(sensorPin);

  if(currVal != prevVal && currVal == 20)

the value being 20. This is the reading specific to the size of capacitor i am using. Smaller/Larger capacitors = different value in RC Circuit.

So if anyone is wanting to do what i have done my setup is as follows. Arduino UNO + SMB100B-D Cellular module + eTape Milone Sensors connected to Digital ins via RC circuit using etape as a variable resistor. There are many applications that this could be used for. Remote water tank monitoring etc etc.

Thanks again.