# Can anyone help me solve the errors?

**URL:** <https://forum.arduino.cc/t/can-anyone-help-me-solve-the-errors/962235>\
**Category:** Programming\
**Created:** [February 22, 2022, 3:05pm UTC](https://forum.arduino.cc/t/can-anyone-help-me-solve-the-errors/962235 "2022-02-22T15:05:18Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![randy\_serv](https://avatars.discourse-cdn.com/v4/letter/r/d9b06d/32.png) [@randy\_serv](https://forum.arduino.cc/u/randy_serv)\
**Post date:** [February 22, 2022, 3:05pm UTC](https://forum.arduino.cc/t/can-anyone-help-me-solve-the-errors/962235/1 "2022-02-22T15:05:18Z")

</div>

```cpp
#include <Wire.h>
#include <Adafruit_MLX90614.h>
#include <Adafruit_GFX.h>
#include <MCUFRIEND_kbv.h>

#define BLACK 0x0000
#define RED 0xF800
#define WHITE 0xFFFF
#define GREEN 0x07E0
#define DARKGREEN 0x03E0
#define DARKGREY 0x7BEF

Adafruit_MLX90614 mlx = Adafruit_MLX90614();

MCUFRIEND_kbv tft;

float roomTemp;
float objectTemp, stemp;

int readcount = 0;
int threshold = 0;

// ULTRASONIC SENSOR PREPARATION
#define echoPin 11
#define trigPin 12
int maximumRange = 25;
int minimumRange = 15;
long distance;
long duration;
int dtime;

void setup()
  {
    uint16_t ID = tft.readID();
    tft.begin(ID);
    pinMode(trigPin, OUTPUT);
    pinMode(echoPin, INPUT);
    Serial.begin(9600);
    tft.begin();
    delay(1000);
    
    tft.setTextColor(WHITE);
    }
void loop()
  {
  digitalWrite (trigPin, LOW);
  delayMicroseconds (2);
  digitalWrite (trigPin, HIGH);
  delayMicroseconds (10);
  digitalWrite (trigPin, LOW);

  duration = pulseIn(echoPin, HIGH);
  distance = duration*0.034/2;

  objectTemp = threshold + mlx.readObjectTempC();
  roomTemp = mlx.readAmbientTempC();

  Serial.println("Object:" + String(objectTemp) + ", Ambient:" + String(roomTemp));
  Serial.println(distance);

  
  tft.setTextSize(1);
  tft.setCursor(0, 25);
  tft.print("Dis:" + String(distance) + "cm");
  tft.setCursor(65, 25);
  tft.print("Room:" + String(roomTemp).substring(0, 4) + "C");
  tft.setTextSize(2);
  tft.setCursor(0, 0);

  if (distance > maximumRange)
    {
      tft.print("GET CLOSER");
    }
    if (distance < minimumRange)
      {
        tft.print("TOO CLOSE!");
      }
        if (readcount == 5)
          {
            distemp();
          }
             else 
             {
              tft.print("HOLD ON");
              stemp = stemp + objectTemp;
              readcount++;
              dtime = 200;
             }
    }
    
    else{
      dtime = 100;
      readcount = 0;
      stemp = 0;
      }
        
        delay(dtime);
        tft.println("count :" + String(readcount));

void distemp()
{
  objectTemp = stemp / 5;
  tft.setTextSize(1);
  tft.print("YOUR TEMP:");
  tft.setTextSize(2);
  tft.setCursor(60, 5);
  tft.print(String(objectTemp).substring(0, 4) + "C");
  readcount = 0;
  stemp = 0;

  if (objectTemp >= 37.5)
    {
      play_alert();
    }
    else
      {
        play_ok();
      }
      dtime = 5000;
}

    void play_ok()
      {
        tone (3, 600, 1000);
        delay (200);
        tone (3, 750, 500);
        delay (100);
        tone (3, 1000, 500);
        delay (200);
        noTone(3);
      }

    void play_alert()
      {
        tone (3, 2000, 1000);
        delay (1000);
        tone (3, 3000, 100);
        delay (1000);
        tone (3, 4000, 1000);
        delay (1000);
        noTone(3);
      }

```

**Arduino: 1.8.19 (Windows 10), Board: "Arduino Uno"**

**02-22-22:91:5: error: expected unqualified-id before 'else'**

\*\* else{\*\*

\*\* ^~~~\*\*

**02-22-22:97:14: error: expected constructor, destructor, or type conversion before '(' token**

\*\* delay(dtime);\*\*

\*\* ^\*\*

**02-22-22:98:9: error: 'tft' does not name a type**

\*\* tft.println("count :" + String(readcount));\*\*

\*\* ^~~\*\*

**exit status 1**

**expected unqualified-id before 'else'**

**This report would have more information with**  
**"Show verbose output during compilation"**  
**option enabled in File -\> Preferences.**

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [February 22, 2022, 3:13pm UTC](https://forum.arduino.cc/t/can-anyone-help-me-solve-the-errors/962235/2 "2022-02-22T15:13:17Z")

</div>

Make sure you indented the code in the IDE, that's done by pressing ctrlT on a PC or cmdT on a Mac)

You'll see that you have an wrongly placed closing } in the loop (line 90), which makes some of the code fall out any function.

![image](https://europe1.discourse-cdn.com/arduino/original/4X/9/5/3/9532d7ac83259e4ddfbc5994ab9002d38fab2ed3.png)

if you fix this you'll still have other challenges, make sur all your else are attached to an if and that () and {} are balanced

---

<div class="post-metadata">

**Author:** ![randy\_serv](https://avatars.discourse-cdn.com/v4/letter/r/d9b06d/32.png) [@randy\_serv](https://forum.arduino.cc/u/randy_serv)\
**Post date:** [February 22, 2022, 3:20pm UTC](https://forum.arduino.cc/t/can-anyone-help-me-solve-the-errors/962235/3 "2022-02-22T15:20:32Z")

</div>

NOW THIS IS THE ERROR

```cpp
#include <Wire.h>
#include <Adafruit_MLX90614.h>
#include <Adafruit_GFX.h>
#include <MCUFRIEND_kbv.h>

#define BLACK 0x0000
#define RED 0xF800
#define WHITE 0xFFFF
#define GREEN 0x07E0
#define DARKGREEN 0x03E0
#define DARKGREY 0x7BEF

Adafruit_MLX90614 mlx = Adafruit_MLX90614();

MCUFRIEND_kbv tft;

float roomTemp;
float objectTemp, stemp;

int readcount = 0;
int threshold = 0;

// ULTRASONIC SENSOR PREPARATION
#define echoPin 11
#define trigPin 12
int maximumRange = 25;
int minimumRange = 15;
long distance;
long duration;
int dtime;

void setup()
{
  uint16_t ID = tft.readID();
  tft.begin(ID);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  Serial.begin(9600);
  tft.begin();
  delay(1000);

  tft.setTextColor(WHITE);
}
void loop()
{
  digitalWrite (trigPin, LOW);
  delayMicroseconds (2);
  digitalWrite (trigPin, HIGH);
  delayMicroseconds (10);
  digitalWrite (trigPin, LOW);

  duration = pulseIn(echoPin, HIGH);
  distance = duration * 0.034 / 2;

  objectTemp = threshold + mlx.readObjectTempC();
  roomTemp = mlx.readAmbientTempC();

  Serial.println("Object:" + String(objectTemp) + ", Ambient:" + String(roomTemp));
  Serial.println(distance);

  tft.setTextSize(1);
  tft.setCursor(0, 25);
  tft.print("Dis:" + String(distance) + "cm");
  tft.setCursor(65, 25);
  tft.print("Room:" + String(roomTemp).substring(0, 4) + "C");
  tft.setTextSize(2);
  tft.setCursor(0, 0);

  if (distance > maximumRange)
  {
    tft.print("GET CLOSER");
  }
  if (distance < minimumRange)
  {
    tft.print("TOO CLOSE!");
  }
  if (readcount == 5)
  {
    distemp();
  }
  else
  {
    tft.print("HOLD ON");
    stemp = stemp + objectTemp;
    readcount++;
    dtime = 200;
  }
  else {
    dtime = 100;
    readcount = 0;
    stemp = 0;
  }

  delay(dtime);
  tft.println("count :" + String(readcount));
}
void distemp()
{
  objectTemp = stemp / 5;
  tft.setTextSize(1);
  tft.print("YOUR TEMP:");
  tft.setTextSize(2);
  tft.setCursor(60, 5);
  tft.print(String(objectTemp).substring(0, 4) + "C");
  readcount = 0;
  stemp = 0;

  if (objectTemp >= 37.5)
  {
    play_alert();
  }
  else
  {
    play_ok();
  }
  dtime = 5000;
}

void play_ok()
{
  tone (3, 600, 1000);
  delay (200);
  tone (3, 750, 500);
  delay (100);
  tone (3, 1000, 500);
  delay (200);
  noTone(3);
}

void play_alert()
{
  tone (3, 2000, 1000);
  delay (1000);
  tone (3, 3000, 100);
  delay (1000);
  tone (3, 4000, 1000);
  delay (1000);
  noTone(3);
}

```

**Arduino: 1.8.19 (Windows 10), Board: "Arduino Uno"**

**C:\Users\user\Documents\Arduino\02-22-22\02-22-22.ino: In function 'void loop()':**

**02-22-22:90:3: error: 'else' without a previous 'if'**

\*\* else {\*\*

\*\* ^~~~\*\*

**exit status 1**

**'else' without a previous 'if'**

**This report would have more information with**  
**"Show verbose output during compilation"**  
**option enabled in File -\> Preferences.**

---

<div class="post-metadata">

**Author:** ![anon46966594](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@anon46966594](https://forum.arduino.cc/u/anon46966594)\
**Post date:** [February 22, 2022, 3:25pm UTC](https://forum.arduino.cc/t/can-anyone-help-me-solve-the-errors/962235/4 "2022-02-22T15:25:24Z")

</div>

```cpp
  if (distance > maximumRange)
  {
    tft.print("GET CLOSER");
  }
  if (distance < minimumRange)
  {
    tft.print("TOO CLOSE!");
  }
  if (readcount == 5)
  {
    distemp();
  }
  else
  {
    tft.print("HOLD ON");
    stemp = stemp + objectTemp;
    readcount++;
    dtime = 200;
  }
  else {
    dtime = 100;
    readcount = 0;
    stemp = 0;
  }

```

You can only have one 'else' per 'if'. You can have multiple 'elseif's but only one 'else'. Not too sure of your logic, maybe you needed nested if/else statements to achieve what you were going for?

---

<div class="post-metadata">

**Author:** ![johnwasser](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/johnwasser/32/214270_2.png) [@johnwasser](https://forum.arduino.cc/u/johnwasser)\
**Post date:** [February 22, 2022, 3:26pm UTC](https://forum.arduino.cc/t/can-anyone-help-me-solve-the-errors/962235/5 "2022-02-22T15:26:11Z")

</div>

> [@randy\_serv](#):
>
> ```arduino
> else
> {
> tft.print("HOLD ON");
> stemp = stemp + objectTemp;
> readcount++;
> dtime = 200;
> }
> else {
> 
> ```

You can't have an `'else {} else {}'`. You can only put an 'else' on an 'if': `'if () {} else {}'`

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [February 22, 2022, 3:28pm UTC](https://forum.arduino.cc/t/can-anyone-help-me-solve-the-errors/962235/6 "2022-02-22T15:28:49Z")

</div>

> [@randy\_serv](#):
>
> NOW THIS IS THE ERROR

yes, as I said above

> [@J-M-L](#):
>
> you'll still have other challenges, make sur all your else are attached to an if and that () and {} are balanced

---

<div class="post-metadata">

**Author:** ![randy\_serv](https://avatars.discourse-cdn.com/v4/letter/r/d9b06d/32.png) [@randy\_serv](https://forum.arduino.cc/u/randy_serv)\
**Post date:** [February 22, 2022, 3:45pm UTC](https://forum.arduino.cc/t/can-anyone-help-me-solve-the-errors/962235/7 "2022-02-22T15:45:20Z")

</div>

how about this one?

**Arduino: 1.8.19 (Windows 10), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"**

**Sketch uses 26944 bytes (10%) of program storage space. Maximum is 253952 bytes.**

**Global variables use 622 bytes (7%) of dynamic memory, leaving 7570 bytes for local variables. Maximum is 8192 bytes.**

**avrdude: verification error, first mismatch at byte 0x036c**

\*\* 0x30 != 0x70\*\*

**avrdude: verification error; content mismatch**

**avrdude: verification error; content mismatch**

**This report would have more information with**  
**"Show verbose output during compilation"**  
**option enabled in File -\> Preferences.**

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [February 22, 2022, 3:53pm UTC](https://forum.arduino.cc/t/can-anyone-help-me-solve-the-errors/962235/8 "2022-02-22T15:53:05Z")

</div>

initially you were compiling for a UNO and now for a MEGA....

which board do you have?

---

<div class="post-metadata">

**Author:** ![randy\_serv](https://avatars.discourse-cdn.com/v4/letter/r/d9b06d/32.png) [@randy\_serv](https://forum.arduino.cc/u/randy_serv)\
**Post date:** [February 22, 2022, 3:59pm UTC](https://forum.arduino.cc/t/can-anyone-help-me-solve-the-errors/962235/9 "2022-02-22T15:59:19Z")

</div>

mega 2560 sir

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [February 22, 2022, 4:02pm UTC](https://forum.arduino.cc/t/can-anyone-help-me-solve-the-errors/962235/10 "2022-02-22T16:02:05Z")

</div>

did you check the common issues?

> **[Errors when uploading a sketch](https://support.arduino.cc/hc/en-us/articles/4403365313810-Errors-when-uploading-a-sketch)**
>
> When there is an error the IDE will print relevant information in the console. Learn how to resolve common errors.
> 
> Check this first
> These checks will resolve the most common errors:
> 
> 
> Check your s...

---

<div class="post-metadata">

**Author:** ![randy\_serv](https://avatars.discourse-cdn.com/v4/letter/r/d9b06d/32.png) [@randy\_serv](https://forum.arduino.cc/u/randy_serv)\
**Post date:** [February 22, 2022, 4:05pm UTC](https://forum.arduino.cc/t/can-anyone-help-me-solve-the-errors/962235/11 "2022-02-22T16:05:21Z")

</div>

yes sir. i already checked

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [February 22, 2022, 4:09pm UTC](https://forum.arduino.cc/t/can-anyone-help-me-solve-the-errors/962235/12 "2022-02-22T16:09:45Z")

</div>

> [@randy\_serv](#):
>
> i already checked

what did the loopback test show?

---

<div class="post-metadata">

**Author:** ![alto777](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/alto777/32/317385_2.png) [@alto777](https://forum.arduino.cc/u/alto777)\
**Post date:** [February 22, 2022, 4:13pm UTC](https://forum.arduino.cc/t/can-anyone-help-me-solve-the-errors/962235/13 "2022-02-22T16:13:22Z")

</div>

Did you

> 1. Check that your USB cable is working. Test it with a different device, or try using a different USB cable. Make sure it is a _data_ cable, a charge-only cable will not work.

Or a different USB gazinta, or with or without a hub &c.

Also not mentioned or I didn't see it is to reboot your machine.

It's probably the only reason I ever have to… I can go weeks with no trouble, other times right away but sometimes my USB ports become, one by one, locked out unavailable.

I have found no other way to force the USB subsystem to reset itself.

a7

---

<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:** [August 21, 2022, 4:14pm UTC](https://forum.arduino.cc/t/can-anyone-help-me-solve-the-errors/962235/14 "2022-08-21T16:14:21Z")

</div>

Closed on August 21, 2022, 4:14pm UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
