I cannot get our LEDs to work on our Arduino project

/* Change these values based on your calibration values */
#define Ripe 120 // Define max value that we consider sober
#define underripe 400 // Define min value that we consider drunk

#define MQ3pin 0

float sensorValue; //variable to store sensor value

void setup() {
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
Serial.begin(9600); // sets the serial port to 9600
Serial.println("MQ3 warming up!");
delay(20000); // allow the MQ3 to warm up
}

void loop() {
sensorValue = analogRead(MQ3pin); // read analog input pin 0

Serial.print("Sensor Value: ");
Serial.print(sensorValue);

// Determine the status
if (sensorValue < ripe) {
Serial.println(" | Status: Ripe");
pinMode(5, HIGH);
pinMode(5, LOW);
pinMode(5, HIGH);
pinMode(5, LOW);
} else if (sensorValue >= Ripe && sensorValue < Underripe) {
Serial.println(" | Status: Not quite Ripe");
pinMode(4, HIGH);
pinMode(4, LOW);
pinMode(4, HIGH);
pinMode(4, LOW);
} else {
Serial.println(" | Status: Underripe");
pinMode(3, HIGH);
pinMode(3, LOW);
pinMode(3, HIGH);
pinMode(3, LOW);
}

delay(2000);
}

here is my code can anyone tell me what changes I need to use? thanks in advance

That's a lot of pinModes.

Did you mean to use digitalWrite?

Please remember to use code tags when posting code.

Sorry about the tags. I don't know as this is a group project and one of my group members wrote the code

Why not get them to fix it?

I cannot get my LEDs to work on my arduino project

Did you mean "our Arduino project"?

We can't figure out how to fix it, it seems like everything we've tried doesn't work.

Did you try digitalWrite?

Why not?

Even if these were digitalWrite, you won't see anything.
What did you expect?

C++ is case sensitive.


Lookup what these lines of code do:
pinMode( . . . );
and
digitalWrite( . . . );

in C++ ripe and Ripe are 2 different variables

{facepalm} I saw "doesn't work" - completely ignored the possibility that it "doesn't compile".
Embarrassing.

Hello matthew_everett
Try this sketch example untested:

/* Change these values based on your calibration values */
#define ripe 120 // Define max value that we consider sober
#define underripe 400 // Define min value that we consider drunk
#define MQ3pin A0
constexpr byte LedPins[] {5, 4, 3};
int sensorValue; //variable to store sensor value
void setup() {
  for (auto LedPin:LedPins)  pinMode(LedPin, OUTPUT);
  /*  pinMode(3, OUTPUT);
    pinMode(4, OUTPUT);
    pinMode(5, OUTPUT);*/
  Serial.begin(9600); // sets the serial port to 9600
  Serial.println("MQ3 warming up!");
  delay(20000); // allow the MQ3 to warm up
}
void loop() {
  sensorValue = analogRead(MQ3pin); // read analog input pin 0
  Serial.print("Sensor Value: ");
  Serial.print(sensorValue);
  for (auto LedPin : LedPins)  digitalWrite(LedPin, LOW);
  // Determine the status
  switch (sensorValue) {
    case 0 ... ripe:
      Serial.println(" | Status: Ripe");
      digitalWrite(5, HIGH);
      break;
    case ripe+1 ... underripe:
      Serial.println(" | Status: Not quite Ripe");
     digitalWrite(4, HIGH);
      break;
    default:
      Serial.println(" | Status: Underripe");
      digitalWrite(3, HIGH);
      break;
  }
  delay(2000);
}

Have a nice day and enjoy coding in C++.

Why pinMode?

Why does the sensor value have global scope?

is that parameter pack?

Not "pinMode, use "digitalWrite" and without a "delay", the pin will appear to be "LOW" all the time as you have no delay between your Highs and Lows.

digitalWrite (5,HIGH);
delay (1000);
digitalWrite (5,LOW);
delay(1000);
digital.Write (5,HIGH);
delay (1000);
digitalWrite (5,LOW);
delay(1000);

All four instructions should be “digitalWrite”, with no period (“.”) in between

I fixed the typo. Thanks mancera1979

Hello killzone_kid
I would say that are "condensed" cases statements to do coding more easy. On the otherhand the ussage of constrain() function would be nice too.
Have a nice day and enjoy coding in C++.

I gotcha, but when you’re comparing a range of values > val1 && <= val2, switch/case is not a suitable construct

Hello killzone_kid
What is the meaning of "suitable " in this context?
Does this construct violate any C++ rules?
Have a nice day and enjoy coding in C++.

If you try to compile your sketch C++ compiler should tell you that you cannot do this (assuming you substituted …)