I need this broken down like I'm in 3rd Grade

I’m sorry if this looks weird when it’s posted; it’s my first time asking anything!

So I’m having issues with the if, else if statements. I’ve read other forums about this, I just can’t understand what is going on and how to translate it into my own code, so here it is:

int greenled=1;
int redled=2;
int blueled=3;
int volt=4;

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(greenled,OUTPUT);
pinMode(redled,OUTPUT);
pinMode(blueled,OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
{

float vin=5.0analogRead(0)/1024.0;
Serial.print(vin);
Serial.print(" “);
float tempC=(1.8663-vin)/0.01169;
Serial.print(tempC);
Serial.print(” ");
float tempF=1.8
tempC+32.0;
Serial.println(tempF);
delay(100);

if (digitalRead((tempF)>=70)&&((tempF)<=80)){
digitalWrite(greenled,HIGH);
}
else if ((69 >= tempF)&&(tempF >= 60));{
digitalWrite(redled,HIGH);
}
else if ((tempF <= 60)&&((tempF)>=50); {
digitalWrite(blueled,HIGH);
}
else {
digitalWrite(blueled,LOW);
digitalWrite(redled,LOW);
digitalWrite(greenled,LOW);
}
}
}
}

My code for my sensor is correct, I’ve already tested that and calibrated it. I just need three different LEDs to light up for three different temperature ranges, and I don’t understand what I’m doing wrong or how to fix it. I’m getting the “‘else’ without a previous ‘if’” error message, and from what I’ve read, it seems like I typed it correctly.

Anyways, if someone could please break it down to me that would be great. I have a math degree and have only taken one computer science class, so I really don’t understand all of the lingo everyone is using either.

Thank you so much! :slight_smile:

(digitalRead((tempF)>=70)&&((tempF)<=80))Somethings are very wrong there.
Did you write this?
The digital read should not be there AT ALL.

Please remember to use code tags when posting code.

I would also connect my greenled to another pin; pin 1 is part of the serial interface.

There were several other errors. Semicolons at the end of if statements, misplaced { and } (curly brackets) and some others. See the comments in the code. I formatted the code with the IDE autoformat tool (ctrl-t ot Tools, Auto Format) and posted it in code tags (see forum guidelines).

int greenled = 1;  // Serial TX pin
int redled = 2;
int blueled = 3;
int volt = 4;

void setup()
{
   // put your setup code here, to run once:
   Serial.begin(9600);
   pinMode(greenled, OUTPUT);
   pinMode(redled, OUTPUT);
   pinMode(blueled, OUTPUT);
}

void loop()
//{   misplaced {
// put your main code here, to run repeatedly:
{
   float vin = 5.0 * analogRead(0) / 1024.0;
   Serial.print(vin);
   Serial.print(" ");
   float tempC = (1.8663 - vin) / 0.01169;
   Serial.print(tempC);
   Serial.print(" ");
   float tempF = 1.8 * tempC + 32.0;
   Serial.println(tempF);
   delay(100);

   //if (digitalRead((tempF) >= 70) && ((tempF) <= 80))  // why digitalRead the pin named tempF?
   if ((tempF >= 70) && (tempF <= 80))
   {
      digitalWrite(greenled, HIGH);
   }
   else if ((69 >= tempF) && (tempF >= 60)) // semicolon; 
   {
      digitalWrite(redled, HIGH);
   }
   else if ((tempF <= 60) && (tempF >= 50)) //;  semicolon and missing )
   {
      digitalWrite(blueled, HIGH);
   }
   else
   {
      digitalWrite(blueled, LOW);
      digitalWrite(redled, LOW);
      digitalWrite(greenled, LOW);
   }
}
} // extra }
} // extra }
else if ((69 >= tempF) && (tempF >= 60))

Is the same as

else if ((tempF <= 69) && (tempF >= 60))

The Yoda notation make it harder to follow.

groundFungus:
The Yoda notation make it harder to follow.

If there are more than a few of these comparisons I use this:

// Range function demo

#include "IS_IN_RANGEr.h"

int lowVal = 4;
int hiVal = 7;

void setup() {
  Serial.begin(115200);
  Serial.print("lowVal = ");
  Serial.print (lowVal);
  Serial.print("\thiVal = ");
  Serial.println (hiVal);
  Serial.println("\t");

  for (byte i = 0; i < 10; i++) {
    Serial.print("Argument = ");
    Serial.print(i);
    //--------------------------
    
    if (isInRange(lowVal, i, hiVal)) {
      
      //------------------------
      Serial.print(F(" returns True\n"));
    } else {
      Serial.print(F(" returns False\n"));
    }
  }
}

void loop() {}

along with:

// jiggy-ninja limit inst header file
//
// Combine two compares into one function in the form:
//
//                  test value
// if (isInRange(var1, var2, var3))
//    low limit --^            ^-- high limit
//
// to create a range or 'limit' function.
//
// If argument is between low limit and high limit logic true is returned,
// false otherwise.

// arduino.cc thread: http://forum.arduino.cc/index.php?topic=529930.msg3627976#msg3627976
//
// Usage example using floating point:

/*  if (isInRangeF(1, 3.3, 7)) {
      Serial.print(F("True\n"));
    } else {
      Serial.print(F("False\n"));
    }
*/
#ifndef IS_IN_RANGE
#define IS_IN_RANGE

template < class T > bool isInRange_helper
( T lowLimit, T argument, T hiLimit ) {

  return ( lowLimit <= argument and argument <= hiLimit );
}

bool isInRange( long lowLimit, long argument, long hiLimit )
{
  return isInRange_helper<long>(lowLimit, argument, hiLimit);
}

bool isInRangeF( float lowLimit, float argument, float hiLimit )
{
  return isInRange_helper<float>(lowLimit, argument, hiLimit);
}
#endif

Hi,
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks. Tom.... :slight_smile: