[SOLVED]Is there anything i had missed? I can't let my boolean function well...

Greeding everyone, I’m recently using 3 ultrasonic sensor(HC-SR04) to build an people counter. I’m trying to use these sensors to track the movement of the people which pass through, stay on the spot or passing by.

First I used the boolean to track the movement of people, then use a variable to contain value for each sensor. After that, simply substract the value from the sensors to become the final people counted value.

I had try both 1&0, true&false, but it’s not going works and even printed on Serial Monitor…

If full coding is required, I will post it later on.

bool sensed1 = 0; //people sensed at sensor 1
bool sensed2 = 0; //people sensed at sensor 2
bool sensed3 = 0; //people sensed at sensor 3

sensedHeight3 = oriHeight3 - pulseDistance3;

  if(sensedHeight1 >= humanHeight)
  {
    sensed1 = 1;
    timer1.start(timerValue);
      if(sensed1 = 1 && sensedHeight1 < humanHeight)
      {
        sensorValue1++;
        delay(250);
        sensed1 = 0;
      }
  }
  if(sensedHeight2 >= humanHeight)
  {
    sensed2 = 1;
    timer2.start(timerValue);
      if(sensed2 = 1 && sensedHeight2 < humanHeight)
      {
        sensorValue2++;
        delay(250);
        sensed2 = 0;
      }
  }
  if(sensedHeight3 >= humanHeight)
  {
    sensed3 = 1;
    timer3.start(timerValue);
      if(sensed3 = 1 && sensedHeight3 < humanHeight)
      {
        sensorValue3++;
        delay(250);
        sensed3 = 0;
      }
  }

if (sensorValue1 == 1 && sensorValue2 == 1)
  {
    peopleCounted++;
    sensorValue1--;
    sensorValue2--;    
  }
  if (sensorValue3 == 1 && sensorValue2 == 1)
  {
    peopleCounted--;
    sensorValue3--;
    sensorValue2--;
  }
  if (timer1.justFinished())
  {
    sensed1 = 0;
  }
  if (timer2.justFinished())
  {
    sensed2 = 0;
  }
  if (timer3.justFinished())
  {
    sensed3 = 0;
  }

if(sensed1 = 1 Oops

Please remember to use code tags when posting code

TheMemberFormerlyKnownAsAWOL: Please remember to use code tags when posting code

Ohh, it have to type manually, no wonder I can't find when writing this topic.

if(sensed1 = 1Oops Is there any problem if I use boolean like this? It's been the third day I'm trying to fix this.

if(sensed1 = 1 is always true.
Use ==

See the reference for the if structure.

Beware of accidentally using the single equal sign (e.g. if (x = 10) ). The single equal sign is the assignment operator, and sets x to 10 (puts the value 10 into the variable x). Instead use the double equal sign (e.g. if (x == 10) ), which is the comparison operator, and tests whether x is equal to 10 or not. The latter statement is only true if x equals 10, but the former statement will always be true.

winterpie:
Ohh, it have to type manually, no wonder I can’t find when writing this topic.

Not true. There is a visible icon at the left side of the menu bar of the edit window. It looks like </>. First highlight the text you want to use, then click on that.

OHHHHHHH!!! What a silly mistake I had made!

I'm very appreciate for the solution, thank you very much. :D