expected initializer before int and "}" should be below input

/*
  Arduino Temperature Controller

  YouTube video: https://www.youtube.com/watch?v=nPQIjApehwk

  Made by Daedalus
*/
#include <Wire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal_I2C.h>
#define RELAY1  4  // Relay heating
#define RELAY2  6  // Relay cooling


int red = 8; // red LED heating
int blue = 2; // blue LED cooling


#define BACKLIGHT_PIN 13
#define ONE_WIRE_BUS 7

LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

{

  void setup()

  
    int Serial;
   Serial.begin(9600);
   sensors.begin();
   lcd.begin(20, 4);
   lcd.backlight();


 pinMode(red, OUTPUT);
 pinMode(blue, OUTPUT);
 pinMode(RELAY1, OUTPUT);
 pinMode(RELAY2, OUTPUT);

}

{
  void loop()

   
    lcd.setCursor(0, 0);
    lcd.print("    TEMP CONTROL");

}
  
  {
    sensors.requestTemperatures();
    float temperature = sensors.getTempCByIndex(0);
    lcd.setCursor(0, 2);
    lcd.print("      ");
    lcd.print(sensors.getTempCByIndex(0));
    lcd.print("\337C");
  }


  if (temperature < 25) ////// Had a bogus ';' here
  {
    digitalWrite(red, HIGH);
    digitalWrite(blue, LOW);


    lcd.setCursor(0, 3);
    lcd.print("      Heating");

  }
  digitalWrite(RELAY1, 0);
  digitalWrite(RELAY2, 1);

  else if (temperature > 25) ////// Had a bogus ';' here
  {
    digitalWrite(RELAY1, 1);
    digitalWrite(RELAY2, 0);
    digitalWrite(red, LOW);
    digitalWrite(blue, HIGH);


    lcd.setCursor(0, 4);
    lcd.print("      Cooling ");
    lcd.setCursor(0, 3);
  }

While I was trying to run the code for the thermal temperature sensor using the Arduino, I am receiving the error to initialize the Serial and along with that, it is also showing the error that the '}' should be before input. It was also showing the error that the "{ " should not be assigned after a function and I put it before the void loop. Can you guys provide me some suggestions to remove the error and help me !!!

DallasTemperature sensors(&oneWire);

{

Oops

int Serial;
   Serial.begin(9600);

Oops again

Hi,

There should be quite some errors in here, what I pinpointed are:
You systematically open a curly brace '{' before the functions name - parameter. You do this:
{

  • type function_name (arguments)*
  • ....*

you should do:
type function_name (arguments)
{

  • ....*

I suggest you stop trying to make this work and read somewhere how functions are syntaxed and the C++ coding basics. Sorry if I am dropping your morale, this is the fastest way to go on, learn more on the C++ basics. I see errors in more than 5 places.
I want to give you morale and persuade you that you CAN learn the basic syntaxing. I mean it!! Its not that hard
I am attaching two of my book's pages on this subject
If you like it it is here,
Practical Electronics and Arduino in 8 Hours
if not, there are many other great sources, maybe even greater!
You can do it :slight_smile: it is not hard, not too easy !
Jim

You have misplaced braces and errors in the way you have variables defined. I can't even tell how your code is supposed to flow. You need to study up on fundamental C/C++ before proceeding.

Also, you don't appear to have an action for if the temperature is 25 degrees.

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