# errors, errors and more errors

**URL:** <https://forum.arduino.cc/t/errors-errors-and-more-errors/525474>\
**Category:** Programming\
**Created:** [May 11, 2018, 4:13am UTC](https://forum.arduino.cc/t/errors-errors-and-more-errors/525474 "2018-05-11T04:13:23Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![bobbybonez](https://avatars.discourse-cdn.com/v4/letter/b/ecd19e/32.png) [@bobbybonez](https://forum.arduino.cc/u/bobbybonez)\
**Post date:** [May 11, 2018, 4:13am UTC](https://forum.arduino.cc/t/errors-errors-and-more-errors/525474/1 "2018-05-11T04:13:23Z")

</div>

Hey guys,

ive been searching for quite a while and cant come up with a reason that I keep getting errors with this code. I've got some explanation inside the code of what im trying to acomplish. I keep getting

expected primary-expression before '||' token

or

expected ')' before ';' token

depending on what I do to try and remedy the other issues.

```cpp
int fan = 2;
int switchpin = 3;
int led1 = 4;
int led2 = 6; 
int led3 = 9;
int led4 = 10;
int sensorpin = A0; //potentiometer
int fanspeed = 255;
int brightness1 = 0;
int brightness2 = 0; 
int brightness3 = 0;
int brightness4 = 0;

void setup() {
  // put your setup code here, to run once:
pinMode(fan, OUTPUT);
pinMode(switchpin, INPUT_PULLUP);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
//if potentiometer reads ~50% or more then turn led 4 on and turn the fan onto full speed
if (analogRead(sensorpin) >= || == 500) {
  digitalWrite(led4, HIGH);
  analogWrite(fan, 255);
}
//if button is low turn all leds on high
else if (analogRead(switchpin) == LOW){ 
  digitalWrite(led1, HIGH);
  digitalWrite(led2, HIGH);
  digitalWrite(led3, HIGH);
  digitalWrite(led4, HIGH);
}
// if button is low and potentiometer reads less then or equal to ~ 49%
//fade all lights in sequence
if (analogRead(switchpin) == LOW && analogRead(sensorpin) <= || == 499) {
  digitalWrite(led1, HIGH);
  delay(1000);
  digitalWrite(led1, LOW);
  (brightness2 = 255; brightness2 >=0; brightness2 -= 3)
  analogWrite(led2, brightness2);
  delay(30);
  (brightness3 = 255; brightness3 >=0; brightness3 -= 3)
  analogWrite(led3, brightness3);
  delay(30);
()  (brightness4 = 255; brightness4 >=0; brightness4 -= 3)
  analogWrite(led4, brightness4);
  delay(30);
}
// in all other occasions
else (analogRead(switchpin) == HIGH){
  digitalWrite(led1, HIGH);
  delay(300);
  digitalWrite(led1, LOW);
  delay(300);
  digitalWrite(led2, HIGH);
  delay(300);
  digitalWrite(led2, LOW);
  delay(300);
  digitalWrite(led3, HIGH);
  delay(300);
  digitalWrite(led3, LOW);
  delay(300);
  digitalWrite(led4, HIGH);
  delay(300);
  digitalWrite(led4, LOW);
}
}

```

also, is anyone aware of any site or video that really dumbs down what all the functions and terms mean? I have a basic understanding, but when I try to figure out some of the more advanced stuff i get kinda confused. the reference and language page are not written in laymens terms and most other pages i can find go over the very basic stuff that i already have done or know.

THANKS!!!

---

<div class="post-metadata">

**Author:** ![sterretje](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sterretje/32/391294_2.png) [@sterretje](https://forum.arduino.cc/u/sterretje)\
**Post date:** [May 11, 2018, 4:26am UTC](https://forum.arduino.cc/t/errors-errors-and-more-errors/525474/2 "2018-05-11T04:26:08Z")

</div>

In

```cpp
  if (analogRead(switchpin) == LOW && analogRead(sensorpin) <= || == 499) {

```

what is _analogRead(sensorpin) \<= || == 499_ supposed to mean / do? You have plenty of that type of constructions.

---

<div class="post-metadata">

**Author:** ![ChrisTenone](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/christenone/32/219804_2.png) [@ChrisTenone](https://forum.arduino.cc/u/ChrisTenone)\
**Post date:** [May 11, 2018, 6:25am UTC](https://forum.arduino.cc/t/errors-errors-and-more-errors/525474/3 "2018-05-11T06:25:02Z")

</div>

Yeah, those are pretty typical syntax errors. You are constructing your compound conditionals wrong. Each comparison needs to be written out in full. [This](https://www.arduino.cc/reference/en) site describes the keywords and usage pretty well.

> bobbybonez:  
> Hey guys,
> 
> ive been searching for quite a while and cant come up with a reason that I keep getting errors with this code. I've got some explanation inside the code of what im trying to acomplish. I keep getting
> 
> expected primary-expression before '||' token
> 
> or
> 
> expected ')' before ';' token
> 
> depending on what I do to try and remedy the other issues.
> 
> ```arduino
> int fan = 2;
> 
> ```

int switchpin = 3;  
int led1 = 4;  
int led2 = 6;  
int led3 = 9;  
int led4 = 10;  
int sensorpin = A0; //potentiometer  
int fanspeed = 255;  
int brightness1 = 0;  
int brightness2 = 0;  
int brightness3 = 0;  
int brightness4 = 0;

void setup() {  
&nbsp; // put your setup code here, to run once:  
pinMode(fan, OUTPUT);  
pinMode(switchpin, INPUT\_PULLUP);  
pinMode(led1, OUTPUT);  
pinMode(led2, OUTPUT);  
pinMode(led3, OUTPUT);  
pinMode(led4, OUTPUT);  
}

void loop() {  
&nbsp; // put your main code here, to run repeatedly:  
//if potentiometer reads ~50% or more then turn led 4 on and turn the fan onto full speed  
if (analogRead(sensorpin) \>= || == 500) {  
&nbsp; digitalWrite(led4, HIGH);  
&nbsp; analogWrite(fan, 255);  
}  
//if button is low turn all leds on high  
else if (analogRead(switchpin) == LOW){  
&nbsp; digitalWrite(led1, HIGH);  
&nbsp; digitalWrite(led2, HIGH);  
&nbsp; digitalWrite(led3, HIGH);  
&nbsp; digitalWrite(led4, HIGH);  
}  
// if button is low and potentiometer reads less then or equal to ~ 49%  
//fade all lights in sequence  
if (analogRead(switchpin) == LOW && analogRead(sensorpin) \<= || == 499) {  
&nbsp; digitalWrite(led1, HIGH);  
&nbsp; delay(1000);  
&nbsp; digitalWrite(led1, LOW);  
&nbsp; (brightness2 = 255; brightness2 \>=0; brightness2 -= 3)  
&nbsp; analogWrite(led2, brightness2);  
&nbsp; delay(30);  
&nbsp; (brightness3 = 255; brightness3 \>=0; brightness3 -= 3)  
&nbsp; analogWrite(led3, brightness3);  
&nbsp; delay(30);  
()&nbsp; (brightness4 = 255; brightness4 \>=0; brightness4 -= 3)  
&nbsp; analogWrite(led4, brightness4);  
&nbsp; delay(30);  
}  
// in all other occasions  
else (analogRead(switchpin) == HIGH){  
&nbsp; digitalWrite(led1, HIGH);  
&nbsp; delay(300);  
&nbsp; digitalWrite(led1, LOW);  
&nbsp; delay(300);  
&nbsp; digitalWrite(led2, HIGH);  
&nbsp; delay(300);  
&nbsp; digitalWrite(led2, LOW);  
&nbsp; delay(300);  
&nbsp; digitalWrite(led3, HIGH);  
&nbsp; delay(300);  
&nbsp; digitalWrite(led3, LOW);  
&nbsp; delay(300);  
&nbsp; digitalWrite(led4, HIGH);  
&nbsp; delay(300);  
&nbsp; digitalWrite(led4, LOW);  
}  
}

> ```arduino
> 
> also, is anyone aware of any site or video that really dumbs down what all the functions and terms mean? I have a basic understanding, but when I try to figure out some of the more advanced stuff i get kinda confused. the reference and language page are not written in laymens terms and most other pages i can find go over the very basic stuff that i already have done or know.
> 
> THANKS!!!
> ```

---

<div class="post-metadata">

**Author:** ![MarkT](https://avatars.discourse-cdn.com/v4/letter/m/c89c15/32.png) [@MarkT](https://forum.arduino.cc/u/MarkT)\
**Post date:** [May 11, 2018, 10:22am UTC](https://forum.arduino.cc/t/errors-errors-and-more-errors/525474/4 "2018-05-11T10:22:41Z")

</div>

```cpp
  if (analogRead(sensorpin) >= || == 500) {

```

You have two operators in a row without an expression between, so its saying it expected an expression.

```cpp
  (brightness2 = 255; brightness2 >=0; brightness2 -= 3)

```

You are missing the keyword 'for', so its completely confused.

---

<div class="post-metadata">

**Author:** ![TomGeorge](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/tomgeorge/32/215261_2.png) [@TomGeorge](https://forum.arduino.cc/u/TomGeorge)\
**Post date:** [May 11, 2018, 10:30am UTC](https://forum.arduino.cc/t/errors-errors-and-more-errors/525474/5 "2018-05-11T10:30:04Z")

</div>

Hi,  
This might help.

> **[Arduino Tutorial](https://www.tutorialspoint.com/arduino/index.htm)**
>
> Arduino Tutorial - Arduino is a prototype platform (open-source) based on an easy-to-use hardware and software. It consists of a circuit board, which can be programed (referred to as a microcontroller) and a ready-made software called Arduino IDE...

Look up "operators"

Tom... 🙂

---

<div class="post-metadata">

**Author:** ![bobbybonez](https://avatars.discourse-cdn.com/v4/letter/b/ecd19e/32.png) [@bobbybonez](https://forum.arduino.cc/u/bobbybonez)\
**Post date:** [May 11, 2018, 2:44pm UTC](https://forum.arduino.cc/t/errors-errors-and-more-errors/525474/6 "2018-05-11T14:44:28Z")

</div>

What I am going for here is if the button is low (pressed in) and the potentiometer is at less then 50% then it will blink the led. I actually just saw the brightness stuff below that and I'm not sure why I have it. It doesn't need to be there.

> sterretje:  
> In
> 
> ```arduino
>   if (analogRead(switchpin) == LOW && analogRead(sensorpin) <= || == 499) {
> 
> ```
> 
> what is _analogRead(sensorpin) \<= || == 499_ supposed to mean / do? You have plenty of that type of constructions.

---

<div class="post-metadata">

**Author:** ![bobbybonez](https://avatars.discourse-cdn.com/v4/letter/b/ecd19e/32.png) [@bobbybonez](https://forum.arduino.cc/u/bobbybonez)\
**Post date:** [May 11, 2018, 2:51pm UTC](https://forum.arduino.cc/t/errors-errors-and-more-errors/525474/7 "2018-05-11T14:51:06Z")

</div>

I only half understand what they are getting at on this site. I'm looking for something that explains it in a little simpler format.

What am I missing for the compound conditionals?

> ChrisTenone:  
> Yeah, those are pretty typical syntax errors. You are constructing your compound conditionals wrong. Each comparison needs to be written out in full. [This](https://www.arduino.cc/reference/en) site describes the keywords and usage pretty well.

---

<div class="post-metadata">

**Author:** ![slipstick](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@slipstick](https://forum.arduino.cc/u/slipstick)\
**Post date:** [May 11, 2018, 3:13pm UTC](https://forum.arduino.cc/t/errors-errors-and-more-errors/525474/8 "2018-05-11T15:13:48Z")

</div>

You're missing the fact that each comparison has to be complete. If you say (x \> 10 || x == 5) the compiler know what you mean. If you say (x \>10 || == 5) it doesn't. The compiler doesn't remember the x and guess that it is supposed to apply to the next comparison too.

To check if you're talking sense try putting parentheses round each comparison ((x\>10) || (==5)). The ==5 on it's own makes no sense at all. What is supposed to be equal to 5? You haven't said.

Steve

---

<div class="post-metadata">

**Author:** ![sterretje](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sterretje/32/391294_2.png) [@sterretje](https://forum.arduino.cc/u/sterretje)\
**Post date:** [May 11, 2018, 3:46pm UTC](https://forum.arduino.cc/t/errors-errors-and-more-errors/525474/9 "2018-05-11T15:46:45Z")

</div>

To make your construction correct, it would look like

```cpp
a <= 499 || a == 499

```

But \<= means less than or equal. So you don't need the ||

---

<div class="post-metadata">

**Author:** ![TomGeorge](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/tomgeorge/32/215261_2.png) [@TomGeorge](https://forum.arduino.cc/u/TomGeorge)\
**Post date:** [May 12, 2018, 12:20am UTC](https://forum.arduino.cc/t/errors-errors-and-more-errors/525474/10 "2018-05-12T00:20:32Z")

</div>

Hi,  
You need to restructure you code so that at the start of the void loop(), you read ALL your inputs and assign the values to variables, then ONLY use those variable through the rest of you code.  
The values being up dated each time the code loops back to the start.  
For example;

```cpp
switchState = digitalRead(switchPin);
sensorVal = analogRead(sensorPin);

// instead of
// if (analogRead(switchpin) == LOW && analogRead(sensorpin) <= || == 499) {

if (switchState == LOW && sensorVal <= 499) {

// which says..  if switchState is LOW AND sensorVal is LESS THAN OR EQUAL To 499.
}

```

analogReading each time that you need the value makes reading your code cumbersome, and not needed because of the speed of the loop.

In fact doing repeated unnecessary analogRead will probably slow the loop down.

So read ALL your variables and assign their values to meaningfull variable names at the start of the loop.  
Then use the variables when you do tests. 🙂

Did you read the link, look at operators.

> **[Arduino - Operators](https://www.tutorialspoint.com/arduino/arduino_operators.htm)**
>
> Arduino Operators - An operator is a symbol that tells the compiler to perform specific mathematical or logical functions. C language is rich in built-in operators and provides the following types of operators −

Tom... 🙂

---

<div class="post-metadata">

**Author:** ![ChrisTenone](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/christenone/32/219804_2.png) [@ChrisTenone](https://forum.arduino.cc/u/ChrisTenone)\
**Post date:** [May 13, 2018, 6:44pm UTC](https://forum.arduino.cc/t/errors-errors-and-more-errors/525474/11 "2018-05-13T18:44:32Z")

</div>

> bobbybonez:  
> I only half understand what they are getting at on this site. I'm looking for something that explains it in a little simpler format.
> 
> What am I missing for the compound conditionals?

Here is a phrase from your original code:

```arduino
 if (analogRead(sensorpin) >= || == 500) {
  digitalWrite(led4, HIGH);
  analogWrite(fan, 255);
}

```

The conditional is the part in parenthesis between "if" and "}", specifically:  
`(analogRead(sensorpin) >= || == 500)`.

If you read this in English, it says "analogRead(sensorpin) is greater than or equal to, or (something unspecified) is equal to five hundred". What you want it to say is "analogRead(sensorpin) is greater than or equal to five hundred". Since \>= means "greater than or equal to" - the "or" is implicit in the keyword \>=. Simplify this expression to read:  
`(analogRead(sensorpin) >= 500)`.

You made this error in several places. Correct them all then move on to the next error (the above mentioned missing `for`.)

Try compiling after each correction, then once it compiles, (_Yay!_) move on to the optimization that Tom describes in the post right above this one.

ps, you can use the alternate keywords "and' and "or" instead of && and ||. I do this, and it makes it so much easier to read the code!

---

<div class="post-metadata">

**Author:** ![sterretje](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/sterretje/32/391294_2.png) [@sterretje](https://forum.arduino.cc/u/sterretje)\
**Post date:** [May 14, 2018, 4:05am UTC](https://forum.arduino.cc/t/errors-errors-and-more-errors/525474/12 "2018-05-14T04:05:11Z")

</div>

Adding, it's far better to read once and store in a variable. E.g.

```cpp
int val = analogread(A0);
if (val >= 500 && val <600)
{
  // do something
}

```

There are two advantages: analogRead takes approx. 100 uS so only reading once speeds up the process. And in those 100 uS the input signal might have changed and you would have been comparing two different readings if you used two analogReads.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 5, 2021, 11:11pm UTC](https://forum.arduino.cc/t/errors-errors-and-more-errors/525474/13 "2021-05-05T23:11:04Z")

</div>

Closed on May 5, 2021, 11:11pm UTC


