Water Level Indicator, Wrong Output

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);
  }

byte sensorPin[] = {11, 12, 13}; //Input pins

I did tried to switch to 8, 9, 10, still the same

What do you get without the Arduino...?? i.e. collector voltage on each.

What do you actually have connected?

Can you show what is connected to the Arduino.

btw... naming a variable a or b, instead of wasHigh or wasMeduim (for example) is just making life hard for yourself.

i can't really test it out as I don't have a multimeter

Use a couple of LEDs

5v, gnd, and 11, 12, 13 only


d

Hello
Did you check each transistor stage using a led+r simply?

no, I don't have led yet

What does Serial.print say ????

I would not use the transistors.
Arduino pins are sensitive enough by themselves.

I would do this:

  1. enable internal pull up on every input pin.
    pinMode(sensorPin[i], INPUT_PULLUP);
  2. use the 220k resistors (for pin safety) between pins and container wires.
  3. connect the common wire to ground (not to 5volt).

Now the pin will read HIGH when not in the water, and will hopefully read LOW when submerged.
If that doesn't work (not enough conductivity), then move to analogue pins, and read the analogue values. Exposed will then read close to 1023, and submerged maybe 1000 or lower.
Leo..

Hi,
Try this code;

// 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
bool pinState;

void setup()
{
  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("Initializing Water Level Indicator");
  delay(2000);
}
void loop()
{
  for (int i = 0; i < sensors; i++)
  {
    pinState = digitalRead(sensorPin[i]);
    Serial.print("\t   Pin ");
    Serial.print(sensorPin[i]);
    Serial.print(" is ");
    if (pinState == HIGH)
    {
      Serial.print("HIGH");
    }
    else
    {
      Serial.print("LOW");
    }
  }
  Serial.println(" <<<< ");
  delay(250);
}

Look in the monitor and check each of your probes.
This the first bit of code you should have written to prove your input circuitry.

Tom... :grinning: :+1: :coffee: :australia:

i have tried this, when I connect pin 12 it says pin 12 and 13 is low
pin 11 also says pin 12 and 13 is low
pin 13 also says pin 12 and 13 is low

Hi,

When all the HIGH, AVERAGE and LOW are not connected to anything what do you get?

When you connect just HIGH to the 22K, what do you get?
When you connect just AVERAGE to the 22K, what do you get?
When you connect just LOW to the 22K, what do you get?

Thanks.. Tom... :grinning: :+1: :coffee: :australia:

justHigh = HIGH, LOW, LOW
justAverage = HIGH, LOW, LOW
justLow = HIGH, LOW, LOW
NOwater= HIGH, HIGH, HIGH

I will remove the transistors and directly connect them from the ground to the pin?

Hi,
You need to add some jumpers to your protoboard, the red and black wire bus down the sides have a break in them, as shown by the broken red and black printed lines.

Tom... :grinning: :+1: :coffee: :australia:

i am also suspecting this, will try, updating in a few minutes, thanks

I tried moving the pins around then suddenly the low water will return LOW at times