I want to be able to send message to the GSM module and whenever I do send one, it will reply with the pH level and temperature the sensors have sensed that it also connected to the arduino. but i keep getting the error message "xxx is not declared in this scope" unsure what it means as i am a beginner to coding, this is a school project i hope someone can help, thanks!
this is the full code
#include <SoftwareSerial.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2 // Data wire is plugged into digital pin 2 on the Arduino
OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire device
DallasTemperature sensors(&oneWire); // Pass oneWire reference to DallasTemperature library
SoftwareSerial myGSM(8, 9);
float calibration_value = 21.34 + 1.1;
int phval = 0;
unsigned long int avgval;
int buffer_arr[10],temp;
float ph_act;
#define MPLa 4 //left peristaltic motor 1st pin
#define MPLb 5 //left peristaltic motor 2nd pin
#define MPRa 6 //right peristaltic motor 1st pin
#define MPRb 7 //right peristaltic motor 2nd pin
#define MWa 3 //right water motor 1st pin
#define MWb 10 //right water motor 2nd pin
char incomingChar;
//pin used, 2-temp, 8,9-gsm, a0-ph, hydropump-3, waterpump-4
void setup() {
sensors.begin();
myGSM.begin(19200);
Serial.begin(19200);// initialize serial monitor with 19200 baud
delay(100);
myGSM.print("AT+CMGF=1\r");
delay(100);
// Set module to send SMS data to serial out upon receipt
myGSM.print("AT+CNMI=2,2,0,0,0\r");
delay(100);
pinMode(MPLa, OUTPUT); // Set Motor Pins As O/P
pinMode(MPLb, OUTPUT);
pinMode(MPRa, OUTPUT);
pinMode(MPRb, OUTPUT);
pinMode(MWa, OUTPUT);
pinMode(MWb, OUTPUT);
digitalWrite(MWa, LOW);
digitalWrite(MWb, HIGH);
}
void loop()
{
sensors.requestTemperatures();
float t = sensors.getTempCByIndex(0);//print the temperature in Celsius
Serial.print("Temperature: ");
Serial.print(t);//Serial.print((char)176);//shows degrees character
Serial.print("C");
delay(100);
for(int i=0;i<10;i++)
{
buffer_arr[i]=analogRead(A0);
delay(30);
}
for(int i=0;i<9;i++)
{
for(int j=i+1;j<10;j++)
{
if(buffer_arr[i]>buffer_arr[j])
{
temp=buffer_arr[i];
buffer_arr[i]=buffer_arr[j];
buffer_arr[j]=temp;
}
}
}
avgval=0;
for(int i=2;i<8;i++)
avgval+=buffer_arr[i];
float volt=(float)avgval*5.0/1024/6;
ph_act = -5.70 * volt + calibration_value;
Serial.println(" ");
delay(100);
Serial.print("PH Val: ");
delay(100);
Serial.print(ph_act);
delay(100);
if (t>26)
{
SendMessagetemp();
delay(4000);
}
if (ph_act>20)
{
SendMessageresvalEmpty();
delay(4000);
digitalWrite(MWa, LOW);
digitalWrite(MWb, LOW);
}
delay(1000);
}
void loop()
{
if (SMSRequest()){
if(readData()){
delay(10);
// REPLACE THE X's WITH THE RECIPIENT'S MOBILE NUMBER
// USE INTERNATIONAL FORMAT CODE FOR MOBILE NUMBERS
myGSM.println("AT + CMGS = \"+639193280950\"");
delay(100);
// REPLACE WITH YOUR OWN SMS MESSAGE CONTENT
String dataMessage = ("Temperature: " + String(t) + "*C " + " pH: " + String(int) + "level");
// Uncomment to change message with farenheit temperature
// String dataMessage = ("Temperature: " + String(f) + "*F " + " Humidity: " + String(h) + "%");
// Send the SMS text message
myGSM.print(dataMessage);
delay(100);
// End AT command with a ^Z, ASCII code 26
myGSM.println((char)26);
delay(100);
myGSM.println();
// Give module time to send SMS
delay(5000);
}
}
delay(10);
}
void SendMessagetemp()
{
float t = sensors.getTempCByIndex(0);
myGSM.println("AT+CMGF=1"); //AT command that sets the gsm module to text mode
delay(100);
myGSM.println("AT+CMGS=\"09193280950\"\r");
delay(100);
myGSM.print("TEMPERATURE ALERT:"); //sms you want to send
delay(100);
myGSM.print(t); //sms you want to send
delay(100);
//myGSM.print((char)176); //sms you want to send
//delay(100);
myGSM.print("C"); //sms you want to send
delay(100);
myGSM.println((char)26); //ascii code of ctrl z
delay(100);
}
void SendMessageph()
{
myGSM.println("AT+CMGF=1"); //AT command that sets the gsm module to text mode
delay(100);
myGSM.println("AT+CMGS=\"09193280950\"\r");
delay(100);
myGSM.println("PH LEVEL ALERT:"); //sms you want to send
delay(100);
myGSM.println(ph_act); //sms you want to send
delay(100);
myGSM.println((char)26); //ascii code of ctrl z
delay(100);
}
void SendMessageresvalEmpty()
{
myGSM.println("AT+CMGF=1"); //AT command that sets the gsm module to text mode
delay(100);
myGSM.println("AT+CMGS=\"09193280950\"\r");
delay(100);
myGSM.println("Water Tank: Empty"); //sms you want to send
delay(100);
myGSM.println((char)26); //ascii code of ctrl z
delay(100);
}
//void callGSM()
//{
//myGSM.print("ATD"); //AT command that sets the gsm module to call mode
//delay(100);
//myGSM.print("09995650695"); //the mobile number to make a call to
//delay(100);
//myGSM.println(";");
//delay(2000); //delay of 20seconds
//myGSM.print("ATH"); //AT command to end call
//(100);
//}
this is the error message
Arduino: 1.8.19 (Mac OS X), Board: "Arduino Uno"
/var/folders/c4/5k41m7kn4d330stjq67x_zn80000gn/T/arduino_modified_sketch_423438/sketch_oct07c.ino: In function 'void loop()':
sketch_oct07c:98:6: error: redefinition of 'void loop()'
void loop(){
^~~~
/var/folders/c4/5k41m7kn4d330stjq67x_zn80000gn/T/arduino_modified_sketch_423438/sketch_oct07c.ino:43:6: note: 'void loop()' previously defined here
void loop()
^~~~
sketch_oct07c:99:7: error: 'SMSRequest' was not declared in this scope
if (SMSRequest()){
^~~~~~~~~~
sketch_oct07c:100:8: error: 'readData' was not declared in this scope
if(readData()){
^~~~~~~~
/var/folders/c4/5k41m7kn4d330stjq67x_zn80000gn/T/arduino_modified_sketch_423438/sketch_oct07c.ino:100:8: note: suggested alternative: 'radians'
if(readData()){
^~~~~~~~
radians
sketch_oct07c:107:54: error: 't' was not declared in this scope
String dataMessage = ("Temperature: " + String(t) + "*C " + " pH: " + String(int) + "level");
^
sketch_oct07c:107:83: error: expected primary-expression before '(' token
String dataMessage = ("Temperature: " + String(t) + "*C " + " pH: " + String(int) + "level");
^
sketch_oct07c:107:84: error: expected primary-expression before 'int'
String dataMessage = ("Temperature: " + String(t) + "*C " + " pH: " + String(int) + "level");
^~~
Multiple libraries were found for "OneWire.h"
Used: /Users/mac/Documents/Arduino/libraries/OneWire
Not used: /Users/mac/Documents/Arduino/libraries/OneWireNg
exit status 1
redefinition of 'void loop()'
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.