How To Use If Between Two Values? - Arduino Forum

How to use if between two values? Projects Programming January 27, 2015, 8:26pm 1

As topic, is there any way to use if between two values? I have only found exaples like

if (val <= 1400)digitalWrite(5, HIGH);

How can I use for example val between 1400 to 1700?

January 27, 2015, 8:29pm 2 if ((x >=1400) && (x<= 1700)) 3 Likes January 27, 2015, 9:08pm 3

Thanks, that did the work :slight_smile:

Do you also know how to get the diode on in two areas (4 values)

Like for example: 850 to 1300 and 1600 to 2000

January 27, 2015, 9:12pm 4

Well it can't be in both ranges, so you'd need an ||

January 27, 2015, 9:27pm 5

What does ll mean? I have tried with just adding another if sentence under, but that does not work

January 27, 2015, 9:32pm 6

Arduino - Home

Open-source electronic prototyping platform enabling users to create interactive electronic objects.

January 27, 2015, 9:35pm 7

Adding an if statement under an if statement acts as a logical AND, and as AWOL said, you x cannot be in both ranges. It will either will fail the first if statement and never get to the second if statement or it will succeed the first if statement and fail the second if statement.

As AWOL said, use || which means logical OR

Your problem is "is x greater than or equal to 850 AND less than or equal to 1300 OR x is greater than or equal to 1600 AND x is less than or equal to 2000"

Now use this logical sentence to make your if statement

Topic Replies Views Activity
How to define a range in an 'If' statement Programming 7 13450 May 5, 2021
Multiple variables for an if statement Programming 3 1465 May 5, 2021
Stato compreso tra Software 2 2102 May 7, 2021
Cant Set A Range Programming 4 712 May 5, 2021
Between Two Threshold Values Programming 2 942 May 5, 2021
Unfortunately, your browser is unsupported. Please switch to a supported browser to view rich content, log in and reply.

Tag » Arduino If Statement Between Two Values