Strange overwriting of variable

I’m new to this platform, but over the past few weeks have been cobbling together a project which whilst it’s been frustrating, is now functioning fairly well. Most of the time I’ve worked out what error I made to cause it not to function, but this one has me stumped.

I have four DHT11’s that are used to monitor temperature and humidity in four enclosures (viv1, viv2, viv3 and viv4). I want to be able to select just one of these enclosures and compare its humidity to a variable and if the humidity read by the DHT11 is lower than the threshold make a pin high. If it equals the value it then makes the pin low.

If I simply have the void statement as:

void pumpon()
if (viv >4)

if (viv <1)

I can set the value of the viv variable between 1 and 4 and any input outside this range gets truncated as per the logic. The value of the viv variable is also displayed on a TFT screen and it shows what is set.

But if I then add the following to the loop

if (viv=1 && (DHT1humidity) <= (humidityON) )
digitalWrite(pump, HIGH);
if (viv=1 && (DHT1humidity) > (humidityON) )
digitalWrite(pump, LOW);

Regardless of what value I set viv to it momentarily gets set to that value and is then overwritten with zero. If I comment the above out the variable is not overwritten.

I can’t for the life of me see why ?

Hopefully I’ve explained things clear enough




if (viv=1 && (DHT1humidity) <= (humidityON) )

you are assigning viv a value of 1. What you want is:-

if (viv==1 && (DHT1humidity) <= (humidityON) )

which is comparing viv to 1.

There is a big difference between assignment “=” and equivalence “==”.



Thank you - that works as I was hoping.

I tell you, most of the hangups I get are due to me not = instead of ==, or vice versa, and not having the curly brackets where they should be…

It’s only been a little over three weeks since I started on this platform, and compared to PicBasic it’s like learning klingon :slight_smile: - but I’m slowly getting there, so thanks for the support


compared to PicBasic it's like learning klingon

The Klingons never complain about having to learn klingon, or C/C++. Why do basic programmers always complain about having to learn something as simple as C/C++?

The Klingons never complain about having to learn klingon, or C/C++.

They don't like toilet-duck :slight_smile: