Hello so I have finally assembled my circuit as my Arduino Uno arrived. When simulating with tinkercad, it worked pretty well but now that I have made it, I am only getting one output which is High Level even if I try to connect the Low and Medium, High is always the result.
thanks for the help
// I have remove the myserial temporarily to work on serial monitor
byte sensorPin[] = {11, 12, 13}; //Input pins
byte ledPin[] = {4, 5, 6}; // Output pins
const byte sensors = 3; // Number of sensors
int level = 0; //Level of water
char phonenum[] = "09"; //Phone Numbers
//declare boolean flags to prevent SMS loop
int a=0; //Lvl 3
int b=0; //Lvl 2
int c=0; //Lvl 1
int d=0; //Lvl 0
void setup()
{
mySerial.begin(9600); // Setting the baud rate of GSM Module
Serial.begin(9600); // Setting the baud rate of Serial Monitor (Arduino)
for(int i = 0; i < sensors; i++)
{
pinMode(sensorPin[i], INPUT);
pinMode(ledPin[i], OUTPUT);
}
Serial.println("AT+CMGF=1");
delay(500);
Serial.print("AT+CMGS=\""); //Phone Number
Serial.print(phonenum);
Serial.println("\"");
delay(500);
Serial.println("Initializing Water Level Indicator");
delay(2000);
}
void loop()
{
level = 0;
for(int i = 0; i < sensors; i++)
{
if(digitalRead(sensorPin[i]) == LOW)
{
digitalWrite(ledPin[i], HIGH);
level = sensors - i;
}
else
{
digitalWrite(ledPin[i], LOW);
}
}
switch(level)
{
case 1:
if(a==0)
{
Serial.println("AT+CMGF=1");
delay(500);
Serial.print("AT+CMGS=\"");//Phone Number
Serial.print(phonenum);
Serial.println("\"");
delay(500);
Serial.print("Alert Warning: High Level."); //the message you want to send
delay(500);
Serial.write(26);
delay(500);
a++; b=0, c=0; d=0;
}
break;
case 2:
if(b==0)
{
Serial.println("AT+CMGF=1");
delay(500);
Serial.print("AT+CMGS=\""); //Phone Number
Serial.print(phonenum);
Serial.println("\"");
delay(500);
Serial.print("Alert Warning: Moderate Level."); //the message you want to send
delay(500);
Serial.write(26);
delay(500);
b++; a=0, c=0; d=0;
}
break;
case 3:
if(c==0)
{
Serial.println("AT+CMGF=1");
delay(500);
Serial.print("AT+CMGS=\""); //Phone Number
Serial.print(phonenum);
Serial.println("\"");
delay(500);
Serial.print("Alert Warning: Low Level."); //the message you want to send
delay(500);
Serial.write(26);
delay(500);
c++; a=0; b=0; d=0;
}
break;
default:
if(d==0)
{
Serial.println("AT+CMGF=1");
delay(500);
Serial.print("AT+CMGS=\""); //Phone Number
Serial.print(phonenum);
Serial.println("\"");
delay(500);
Serial.print("Alert Warning: No Water Detected"); //the message you want to send
delay(500);
Serial.write(26);
delay(500);
d++; a=0; b=0; c=0;
}
break;
}
delay(50);
}