1

I am a beginner in using Arduino and programming in c/c++. I am trying to connect a 10-segment LED and a moisture sensor to my Arduino Uno, and when the moisture level is very low, the first 2 red LEDs will be turned on, when it is slightly higher, the next three orange LEDs will be turned on, when it is slightly higher the next three green LEDs will be turned on, and finally when the moisture level is above the threshold for the green LEDs, the final blue LED segment will turn on.

I have written a program that works, and I have tested both the moisture sensor and the 10 segment LED separately to ensure they are working. Although the program works how I intend it, about 30-40% of the time I am unable to run the program due to an error message in the process of uploading. To be clear, I do not change the code at all from the working state of the code to the error message appearing. I wanted to know why this message appears, and how to avoid/resolve this issue.

I have included my code below:

/*
   Arduino LED Bar Graph with Moisture Sensor
   Started June 25, 2020

   edited 6/28
    (added blue LED)
*/

int redLED = 13;
int yellowLED = 12;
int greenLED = 11;
int blueLED = 10;

#define SensorPin A0
float sensorValue = 0;
float moistureLevel = 0;

void setup()
{
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(redLED, OUTPUT);
  pinMode(yellowLED, OUTPUT);
  pinMode(greenLED, OUTPUT);
  pinMode(blueLED, OUTPUT);
}

void loop()
{
  if  (Serial.available() > 900)
  {
    moistureLevel = Serial.read();//set the var moistureLevel
    digitalWrite = (redLED, HIGH);
    digitalWrite = (yellowLED, LOW);
    digitalWrite = (greenLED, LOW);
    digitalWrite = (blueLED, LOW)
  }
  else if (Serial.available() > 750)
  {
    moistureLevel = Serial.read();//set the var moistureLevel
    digitalWrite = (yellowLED, HIGH);
    digitalWrite = (redLED, LOW);
    digitalWrite = (greenLED, LOW);

  }
  else(Serial.available() > 550)
  {
    moistureLevel = Serial.read();//set the var moistureLevel
    digitalWrite = (greenLED, HIGH);
    digitalWrite = (redLED, LOW);
    digitalWrite = (yellowLED, LOW);
    digitalWrite = (blueLED, LOW);
  }
  else(Serial.available() < 549)
  {
    moistureLevel = Serial.read();//set the var moistureLevel
    digitalWrite = (greenLED, HIGH);
    digitalWrite = (redLED, LOW);
    digitalWrite = (yellowLED, LOW);
    digitalWrite = (blueLED, HIGH);
  }
  for (int i = 0; i <= 100; i++)
  {
    sensorValue = sensorValue + analogRead(SensorPin);
    delay(1);
  }
  sensorValue = sensorValue / 100.0;
  Serial.println(sensorValue);
  delay(100);
}

And here is a copy of the exact error message:

/tmp/777165248/sketch_jun25a/sketch_jun25a.ino: In function 'void loop()':

/tmp/777165248/sketch_jun25a/sketch_jun25a.ino:33:33: error: assignment of function 'void digitalWrite(uint8_t, uint8_t)'

digitalWrite = {redLED, HIGH};

^

/tmp/777165248/sketch_jun25a/sketch_jun25a.ino:33:33: error: cannot convert '<brace-enclosed initializer list>' to 'void(uint8_t, uint8_t) {aka void(unsigned char, unsigned char)}' in assignment

/tmp/777165248/sketch_jun25a/sketch_jun25a.ino:34:35: error: assignment of function 'void digitalWrite(uint8_t, uint8_t)'

digitalWrite = (yellowLED, LOW);

^

/tmp/777165248/sketch_jun25a/sketch_jun25a.ino:34:35: error: cannot convert 'int' to 'void(uint8_t, uint8_t) {aka void(unsigned char, unsigned char)}' in assignment

/tmp/777165248/sketch_jun25a/sketch_jun25a.ino:35:34: error: assignment of function 'void digitalWrite(uint8_t, uint8_t)'

digitalWrite = (greenLED, LOW);

^

/tmp/777165248/sketch_jun25a/sketch_jun25a.ino:35:34: error: cannot convert 'int' to 'void(uint8_t, uint8_t) {aka void(unsigned char, unsigned char)}' in assignment

/tmp/777165248/sketch_jun25a/sketch_jun25a.ino:36:33: error: assignment of function 'void digitalWrite(uint8_t, uint8_t)'

digitalWrite = (blueLED, LOW)

^

/tmp/777165248/sketch_jun25a/sketch_jun25a.ino:36:33: error: cannot convert 'int' to 'void(uint8_t, uint8_t) {aka void(unsigned char, unsigned char)}' in assignment

/tmp/777165248/sketch_jun25a/sketch_jun25a.ino:41:36: error: assignment of function 'void digitalWrite(uint8_t, uint8_t)'

digitalWrite = (yellowLED, HIGH);

^

/tmp/777165248/sketch_jun25a/sketch_jun25a.ino:41:36: error: cannot convert 'int' to 'void(uint8_t, uint8_t) {aka void(unsigned char, unsigned char)}' in assignment

/tmp/777165248/sketch_jun25a/sketch_jun25a.ino:42:32: error: assignment of function 'void digitalWrite(uint8_t, uint8_t)'

digitalWrite = (redLED, LOW);

^

/tmp/777165248/sketch_jun25a/sketch_jun25a.ino:42:32: error: cannot convert 'int' to 'void(uint8_t, uint8_t) {aka void(unsigned char, unsigned char)}' in assignment

/tmp/777165248/sketch_jun25a/sketch_jun25a.ino:43:34: error: assignment of function 'void digitalWrite(uint8_t, uint8_t)'

digitalWrite = (greenLED, LOW);

^

/tmp/777165248/sketch_jun25a/sketch_jun25a.ino:43:34: error: cannot convert 'int' to 'void(uint8_t, uint8_t) {aka void(unsigned char, unsigned char)}' in assignment

/tmp/777165248/sketch_jun25a/sketch_jun25a.ino:47:3: error: expected ';' before '{' token

{

^

/tmp/777165248/sketch_jun25a/sketch_jun25a.ino:54:3: error: 'else' without a previous 'if'

else(Serial.available() < 549)

^~~~

/tmp/777165248/sketch_jun25a/sketch_jun25a.ino:55:3: error: expected ';' before '{' token

{

^

exit status 1
1
  • 2
    the error message occurs during code compilation, not during upload ... you always get that error, not only sometimes .... the obvious thing to do, is to review the digitalWrite command, to see if you made a mistake ... please do that – jsotola Jan 2 at 21:17
2

You have:

digitalWrite = (redLED, HIGH);

This is incorrect since digitalWrite is a function not a variable. Instead you likely want:

digitalWrite(redLED, HIGH);

This calls the digitalWrite function with the two arguments.

7
  • 1
    please don't write Answer to syntax error questions. they are off-topic – Juraj Jan 3 at 6:33
  • 3
    @Juraj I'm having trouble finding where the site policy prohibits such questions or answers. Please post a reference to it. Thanks. – jwh20 Jan 3 at 12:34
  • arduino.stackexchange.com/help/on-topic "Off topic: General Coding: " – Juraj Jan 3 at 13:02
  • 2
    @Juraj. The coding question is very much Arduino related. I think you're reading way more into the guideline than is there. – jwh20 Jan 3 at 20:20
  • 2
    Trivial for you is not trivial for a beginner. – jwh20 Jan 3 at 21:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.