connecting 3 sensors in a arduino uno and send it through GSM

hi guys :slight_smile:

can u help me with my program?
i would like to send 3 data from 3 different sensors , via GSM module . but my program didn't work , when i see the serial monitor of the arduino there are many different readings that i cannot understand.
PLEASE HELP ME FIXED IT :frowning:

here's my program

#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3);
float conductivity =A0;
float meter = 0;
float sensorValue = 0; // value read from the pot
float outputValue = 0; // value output to the PWM (analog out)

float turbidity =A1;
float sensorValuet = 0; // value read from the pot
float outputValuet = 0;

float chlorine =A2;
float sensorValuec = 0; // value read from the pot
float outputValuec = 0;

void setup()
{
Serial.begin(57600);
Serial.println(" \t\t WATER QUALITY MONITORING");

// set the data rate for the SoftwareSerial port
mySerial.begin(19200);
//mySerial.println("Hello, world?");
}

void loop()
{
delay(10000);
SendTextMessage();

//reading = analogRead(conductivity);

}

///SendTextMessage()
///this function is to send a sms message
void SendTextMessage()
{
//reading();
delay(1000);
sensorValue = analogRead(conductivity);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 7, 0);
// change the analog out value:
//analogWrite(analogOutPin, outputValue);

// print the results to the serial monitor:
Serial.print("\t reading ph = " );
Serial.print(sensorValue);
Serial.print("\t output = ");
Serial.println(outputValue);
//turbidity
sensorValuet = analogRead(turbidity);
// map it to the range of the analog out:
outputValuet = map(sensorValuet, 0, 1023, 0, 255);
// change the analog out value:
//analogWrite(analogOutPin, outputValue);

// print the results to the serial monitor:
Serial.print("\t reading turbidity = " );
Serial.print(sensorValuet);
Serial.print("\t output = ");
Serial.println(outputValuet);
//chlorine

sensorValuec = analogRead(chlorine);
// map it to the range of the analog out:
outputValuec = map(sensorValuec, 0, 1023, 0, 255);

// print the results to the serial monitor:
Serial.print("\t reading residual= " );
Serial.print(sensorValuec);
Serial.print("\t output = ");
Serial.println(outputValuec);

delay(100);
mySerial.print("AT+CMGF=1\r"); //Because we want to send the SMS in text mode
delay(100);
mySerial.println("AT+CMGS ="+639996385881"");//send sms message, be careful need to add a country code before the cellphone number
delay(100);

mySerial.println(outputValue);//the content of the message
mySerial.println(" ph ");
//delay(100);
//mySerial.print(outputValuet);//the content of the message
//mySerial.print("NTU");
// delay(100);
//mySerial.print(outputValuec);//the content of the message
//mySerial.print("mg/l");
//delay(100);
// mySerial.println((char)26);//the ASCII code of the ctrl+z is 26
delay(1000);
//mySerial.println();
}
void reading()
{
sensorValue = analogRead(conductivity);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 7, 0);
// change the analog out value:
//analogWrite(analogOutPin, outputValue);

// print the results to the serial monitor:
Serial.print("\t reading ph = " );
Serial.print(sensorValue);
Serial.print("\t output = ");
Serial.println(outputValue);
//turbidity
sensorValuet = analogRead(turbidity);
// map it to the range of the analog out:
outputValuet = map(sensorValuet, 0, 1023, 0, 255);
// change the analog out value:
//analogWrite(analogOutPin, outputValue);

// print the results to the serial monitor:
Serial.print("\t reading turbidity = " );
Serial.print(sensorValuet);
Serial.print("\t output = ");
Serial.println(outputValuet);
//chlorine

sensorValuec = analogRead(chlorine);
// map it to the range of the analog out:
outputValuec = map(sensorValuec, 0, 1023, 0, 255);
// change the analog out value:
//analogWrite(analogOutPin, outputValue);

// print the results to the serial monitor:
Serial.print("\t reading residual= " );
Serial.print(sensorValuec);
Serial.print("\t output = ");
Serial.println(outputValuec);
}

With a project like this is probably makes sense to get the sensor side of things working properly before you complicate matters with trying to send text messages.

But that aside, when you say this:

but my program didn't work , when i see the serial monitor of the arduino there are many different readings that i cannot understand.

.... it would help if you post those messages and show what it is that you don't understand

Why are your pin numbers stored in floats? That's mistake number one.
Why are you taking the readings in SendTextMessage()? The readings are what you want to send, but taking them is NOT part of SendTextMessage(). That's mistake number two.
You do not need all those intermediate values to read the sensors. They most definitely do NOT need to be globals. That's mistake number three.

You also posted your code incorrectly. That's mistake number four.

And, as has been explained, you left out a lot of information. That's mistake number five.

That's more than enough for anyone to work on before expecting more help.

plz can you correct my wrongs? i dont know how to fixed it , :frowning: plz

i dont know how to fixed it

You need to learn. Look at the reference page. Find analogRead(). Look at the type of value that the function takes as input. Modify your code to supply a value of that type, by changing the variable type.

If you think about it, can you reasonably expect to read from pin 3.14159?

Separating what SendTextMessage() does to send a text message from what it does to get the data to send is not hard. Move the stuff that is NOT related to sending a text message out of the function.

There are details in the sticky that you didn't bother to read that tell you how to post code correctly. Read them.

Three of your five problems solved!

As PaulS said:

Separating what SendTextMessage() does to send a text message from what it does to get the data to send is not hard. Move the stuff that is NOT related to sending a text message out of the function.

I'd even go so far as to suggest you remove everything to do with sending the SMS from the sketch for now. Merely read the three inputs, and show them with Serial.print().

I see you have a function reading() but you don't call it (because the call is commented out) and then take the readings in the main flow of your program (in the SMS sending part in fact). It's your choice to do it either way, but if you're more comfortable with it in the main flow well that's cool.

So to summarise, in my opinion:

  • Tidy up the data types a la PaulS' suggestion
  • Ditch all the SMS-related stuff
  • Read the sensors and Serial.print() their results and nothing more
  • Then add the send stuff, which merely has to send what you've already read in from the sensors.