Can Someone help me with these errors

Hello, I am new to the Arduino. I have a sketch that I am trying to load on my Arduino for a fan controller on my vehicle. This is not my work on this sketch so I’m just coping what I was told to do to get this to work. I clicked on verify and compile and get an error message of this:
exit status 1
a function-definition is not allowed here before ‘{’ token.
I have no idea what to do from here, can someone advise or check this sketch?
Thanks
Keith

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // This a test program, no warranties are implied or given. fanControllerR2V3base
  // Use, copy any modify this test program any way you want, at your own risk.
  // Test, test, test and then test some more..
  // It reads a temperature sensor and controls a Mazda PWM fan power module.
  // ...Carl...

  /*----------------------- User adjustable variables and preferences section ---------------------------------*/
  float tempForFanStartup = 175.0; // target low temp. below this temperature, the fan will be off
  float tempForFanOnFull = 210.0; // target High temp. above this temperature, the fan will be on at full power
  // adjust these two to get the desired range. for example for a transmission, maybe 140 to 160

  float R0 = 10000; // The base resistance of the NTC sensor used. 10K with a 3435 Beta.
  float Beta = 3435; // The Beta of the sensor used. Very commonly available

  float voltsForFanStartup = 1.2; // Roughly the signal voltage that triggers the mazda module's slowest speed.
  // A higher voltage here will effectively increase the fans lowest speed target.
  /*----------------------- end of User adjustable variables and preferences -----------------------------------*/

  const int fanPwmOutPin = 6; // Arduino forces this pin to 0 or 5 volts.
  const int tempSensorPin = A0; // Pin to read analog voltage from the temp sensor.
  int pwmDuty; // The calculated PWM duty is stored here
  float pwmMinStartupDuty; // the starting duty is stored here (mazda module starts fans at about 24 % duty)
  float currTemperature; // the temperature in F is stored here


  void setup() { /* ++++++++++++++++++ Setup is run once when the arduino boots ++++++++++++++++++++++++++*/
    Serial.begin(115200); // set up serial port for 115200 baud (optional)

    analogReference (EXTERNAL) ; // note, this is using the 3.3 volt supply as the analog reference.
    analogRead (tempSensorPin) ; // a couple of reads to give the A/D time to adjust
    analogRead (tempSensorPin) ; // a couple of reads to give the A/D time to adjust
    analogWrite(fanPwmOutPin, 0); // turn the fan off at start

    pwmMinStartupDuty = (voltsForFanStartup / 5.0) * 255.0; // convert the Mazda starting voltage to a PWM duty
  } // end setup


  void loop() { /* ++++++++++++++++++ Main Loop, continuously loops forever ++++++++++++++++++++++++++++*/

    readAndTranslateTempSensor();

    calculate_and_send_PWM();

    //print_to_serial_port(); // un-comment this line for testing and calibration to the laptop.

  } // end main loop


  void calculate_and_send_PWM(); { // ++++++++ subroutine to calculate and set PWM duty cycle ++++++++++++++*/

    if (currTemperature < tempForFanStartup) { // If the temperature is below the lowest setpoint, turn fan off
      analogWrite(fanPwmOutPin, 0); // PWM duty = 0 percent
      pwmDuty = 0;
      return;
    }

    if (currTemperature > tempForFanOnFull) { // If the temperature is above the highest setpoint, turn fan on full
      analogWrite(fanPwmOutPin, 255); // PWM duty = 100 percent
      pwmDuty = 255;
      return;
    }

    float tempRange = tempForFanOnFull - tempForFanStartup ; // start calculating duty cycle
    float pwmRange = 255.0 - pwmMinStartupDuty ;
    float pwmDutyPct = (currTemperature - tempForFanStartup) / tempRange ;

    pwmDuty = (int) (pwmMinStartupDuty + (pwmDutyPct * pwmRange) + .5); // actual PWM duty is calculated here

    if (pwmDuty > 255) { // make sure duty ended up between 255 and 0
      pwmDuty = 255;
    }
    if (pwmDuty < 0) {
      pwmDuty = 0;
    }

    analogWrite(fanPwmOutPin, pwmDuty); // write PWM duty to PWM output pin

  } // end calculate_and_send_PWM


  void readAndTranslateTempSensor() { /* ++++++ subroutine to read and translate temp sensor to temp F +++++++++++++*/

    int tmp = analogRead(tempSensorPin);
    float r = ((1023.0 * R0) / (float)tmp) - R0;
    currTemperature = Beta / log(r / 0.09919) - 273.15; // for a 10K thermister with a beta of 3435
    currTemperature = (9.0 / 5.0) * currTemperature + 32; // convert to Fahrenheit
    if (currTemperature > tempForFanOnFull) { // If the temperature is above the highest setpoint, turn fan on full
      analogWrite(fanPwmOutPin, 255); // PWM duty = 100 percent
      pwmDuty = 255;
      return;
    }

    float tempRange = tempForFanOnFull - tempForFanStartup ; // start calculating duty cycle
    float pwmRange = 255.0 - pwmMinStartupDuty ;
    float pwmDutyPct = (currTemperature - tempForFanStartup) / tempRange ;

    pwmDuty = (int) (pwmMinStartupDuty + (pwmDutyPct * pwmRange) + .5); // actual PWM duty is calculated here

    if (pwmDuty > 255) { // make sure duty ended up between 255 and 0
      pwmDuty = 255;
    }
    if (pwmDuty < 0) {
      pwmDuty = 0;
    }

    analogWrite(fanPwmOutPin, pwmDuty); // write PWM duty to PWM output pin
    void readAndTranslateTempSensor() { /* ++++++ subroutine to read and translate temp sensor to temp F +++++++++++++*/

      int tmp = analogRead(tempSensorPin);
      float r = ((1023.0 * R0) / (float)tmp) - R0;
      currTemperature = Beta / log(r / 0.09919) - 273.15; // for a 10K thermister with a beta of 3435
      currTemperature = (9.0 / 5.0) * currTemperature + 32; // convert to Fahrenheit

    } // end readAndTranslateTempSensor


    void print_to_serial_port() { /* ++++++++++ optional prints values to laptop usb port for debugging and calibration ++*/
      Serial.print(F("currTemperature F: ")); Serial.print(currTemperature);
      Serial.print(F(" pwmDuty: ")); Serial.println(pwmDuty);
    }

void calculate_and_send_PWM(); {Compare to loop and setup.

Or, in your case, setups. Oops.

Thanks for your reply but I have no ideal how to do what you suggested

Here, let me make it simplevoid loop() {
andvoid calculate_and_send_PWM(); {

See it now?

Your second setup should not be inside loop.

“Your second setup should not be inside loop.”
And the 2nd loop()

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Ok thanks, I'll try it

Well I was able to fix a few more error with y'all s help, now I have 1 error left. He is what it says:

'readAndTranslateTempSensor' was not declared in this scope

So this is not my sketch I'm just using what was given to me so I don't know what i'm doing!
Thanks for your help!
Keith

How about showing us what the code looks like after you've corrected it?

And the whole, exact error message(s)

OK, here’s what I have now
This is the error now:‘readAndTranslateTempSensor’ was not declared in this scope

void loop() {
  // This a test program, no warranties are implied or given. fanControllerR2V3base
  // Use, copy any modify this test program any way you want, at your own risk.
  // Test, test, test and then test some more..
  // It reads a temperature sensor and controls a Mazda PWM fan power module.
  // ...Carl...

  /*----------------------- User adjustable variables and preferences section ---------------------------------*/
  float tempForFanStartup = 175.0; // target low temp. below this temperature, the fan will be off
  float tempForFanOnFull = 210.0; // target High temp. above this temperature, the fan will be on at full power
  // adjust these two to get the desired range. for example for a transmission, maybe 140 to 160

  float R0 = 10000; // The base resistance of the NTC sensor used. 10K with a 3435 Beta.
  float Beta = 3435; // The Beta of the sensor used. Very commonly available

  float voltsForFanStartup = 1.2; // Roughly the signal voltage that triggers the mazda module's slowest speed.
  // A higher voltage here will effectively increase the fans lowest speed target.
  /*----------------------- end of User adjustable variables and preferences -----------------------------------*/

  const int fanPwmOutPin = 6; // Arduino forces this pin to 0 or 5 volts.
  const int tempSensorPin = A0; // Pin to read analog voltage from the temp sensor.
  int pwmDuty; // The calculated PWM duty is stored here
  float pwmMinStartupDuty; // the starting duty is stored here (mazda module starts fans at about 24 % duty)
  float currTemperature; // the temperature in F is stored here


  void setup(); { /* ++++++++++++++++++ Setup is run once when the arduino boots ++++++++++++++++++++++++++*/
    Serial.begin(115200); // set up serial port for 115200 baud (optional)

    analogReference (EXTERNAL) ; // note, this is using the 3.3 volt supply as the analog reference.
    analogRead (tempSensorPin) ; // a couple of reads to give the A/D time to adjust
    analogRead (tempSensorPin) ; // a couple of reads to give the A/D time to adjust
    analogWrite(fanPwmOutPin, 0); // turn the fan off at start

    pwmMinStartupDuty = (voltsForFanStartup / 5.0) * 255.0; // convert the Mazda starting voltage to a PWM duty
  } // end setup


  void loop(); { /* ++++++++++++++++++ Main Loop, continuously loops forever ++++++++++++++++++++++++++++*/

    readAndTranslateTempSensor();

    calculate_and_send_PWM();

    //print_to_serial_port(); // un-comment this line for testing and calibration to the laptop.

  } // end main loop


  void calculate_and_send_PWM(); { // ++++++++ subroutine to calculate and set PWM duty cycle ++++++++++++++*/

    if (currTemperature < tempForFanStartup) { // If the temperature is below the lowest setpoint, turn fan off
      analogWrite(fanPwmOutPin, 0); // PWM duty = 0 percent
      pwmDuty = 0;
      return;
    }

    if (currTemperature > tempForFanOnFull) { // If the temperature is above the highest setpoint, turn fan on full
      analogWrite(fanPwmOutPin, 255); // PWM duty = 100 percent
      pwmDuty = 255;
      return;
    }

    float tempRange = tempForFanOnFull - tempForFanStartup ; // start calculating duty cycle
    float pwmRange = 255.0 - pwmMinStartupDuty ;
    float pwmDutyPct = (currTemperature - tempForFanStartup) / tempRange ;

    pwmDuty = (int) (pwmMinStartupDuty + (pwmDutyPct * pwmRange) + .5); // actual PWM duty is calculated here

    if (pwmDuty > 255) { // make sure duty ended up between 255 and 0
      pwmDuty = 255;
    }
    if (pwmDuty < 0) {
      pwmDuty = 0;
    }

    analogWrite(fanPwmOutPin, pwmDuty); // write PWM duty to PWM output pin

  } // end calculate_and_send_PWM


  void readAndTranslateTempSensor(); { /* ++++++ subroutine to read and translate temp sensor to temp F +++++++++++++*/

    int tmp = analogRead(tempSensorPin);
    float r = ((1023.0 * R0) / (float)tmp) - R0;
    currTemperature = Beta / log(r / 0.09919) - 273.15; // for a 10K thermister with a beta of 3435
    currTemperature = (9.0 / 5.0) * currTemperature + 32; // convert to Fahrenheit
    if (currTemperature > tempForFanOnFull) { // If the temperature is above the highest setpoint, turn fan on full
      analogWrite(fanPwmOutPin, 255); // PWM duty = 100 percent
      pwmDuty = 255;
      return;
    }

    float tempRange = tempForFanOnFull - tempForFanStartup ; // start calculating duty cycle
    float pwmRange = 255.0 - pwmMinStartupDuty ;
    float pwmDutyPct = (currTemperature - tempForFanStartup) / tempRange ;

    pwmDuty = (int) (pwmMinStartupDuty + (pwmDutyPct * pwmRange) + .5); // actual PWM duty is calculated here

    if (pwmDuty > 255) { // make sure duty ended up between 255 and 0
      pwmDuty = 255;
    }
    if (pwmDuty < 0) {
      pwmDuty = 0;
    }

    analogWrite(fanPwmOutPin, pwmDuty); // write PWM duty to PWM output pin
    void readAndTranslateTempSensor(); { /* ++++++ subroutine to read and translate temp sensor to temp F +++++++++++++*/

      int tmp = analogRead(tempSensorPin);
      float r = ((1023.0 * R0) / (float)tmp) - R0;
      currTemperature = Beta / log(r / 0.09919) - 273.15; // for a 10K thermister with a beta of 3435
      currTemperature = (9.0 / 5.0) * currTemperature + 32; // convert to Fahrenheit

    } // end readAndTranslateTempSensor


    void print_to_serial_port(); { /* ++++++++++ optional prints values to laptop usb port for debugging and calibration ++*/
      Serial.print(F("currTemperature F: ")); Serial.print(currTemperature);
      Serial.print(F(" pwmDuty: ")); Serial.println(pwmDuty);
    }

When you encounter an error you’ll see a button on the right side of the orange bar “Copy error messages” (or the icon that looks like two pieces of paper in the Arduino Web Editor). Click that button. Paste the error in a message here USING CODE TAGS (</> button on the forum toolbar). If the text exceeds the forum’s 9000 character limit, save it to a text file and post it as an attachment. If you click the “Reply” button here, you will see an “Attachments and other settings” link.

That will give us the complete error output, rather than a much less useful summary of the error.

Ok here it is!

Arduino: 1.8.8 (Windows 10), Board: "Arduino Nano, ATmega328P"

C:\Users\Triton\Documents\Arduino\PWM\PWM.ino: In function 'void loop()':

PWM:41:32: error: 'readAndTranslateTempSensor' was not declared in this scope

readAndTranslateTempSensor();

^

PWM:43:28: error: 'calculate_and_send_PWM' was not declared in this scope

calculate_and_send_PWM();

^

PWM:121:5: error: expected '}' at end of input

}

^

PWM:121:5: error: expected '}' at end of input

exit status 1
'readAndTranslateTempSensor' was not declared in this scope

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

A function should look like this

void myFunction() {
  //code here
}

and not like this

void myFunction(); {
  //code here
}

When calling functions you use

myFunction();

And as someone else mentioned, you can only have one loop() function;

I changed the function and got the same error also how do I fix the Arduino: 1.8.8 (Windows 10), Board: "Arduino Nano, ATmega328P"

C:\Users\Triton\Documents\Arduino\PWM\PWM.ino: In function 'void loop()':

PWM:41:32: error: 'readAndTranslateTempSensor' was not declared in this scope

readAndTranslateTempSensor() {

^

PWM:121:5: error: expected '}' at end of input

}

^

PWM:121:5: error: expected '}' at end of input

PWM:121:5: error: expected '}' at end of input

exit status 1
'readAndTranslateTempSensor' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
only have one loop() function;

We can't see which function you changed unless you post your updated code.

Metallor, I changed the function to this like you suggested in post #11

readAndTranslateTempSensor() {

Here is the new error code

Arduino: 1.8.8 (Windows 10), Board: "Arduino Nano, ATmega328P"

C:\Users\Triton\Documents\Arduino\PWM\PWM.ino: In function 'void loop()':

PWM:41:32: error: 'readAndTranslateTempSensor' was not declared in this scope

readAndTranslateTempSensor() {

^

PWM:121:5: error: expected '}' at end of input

}

^

PWM:121:5: error: expected '}' at end of input

PWM:121:5: error: expected '}' at end of input

exit status 1
'readAndTranslateTempSensor' was not declared in this scope

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

You've changed something.

So, POST ALL THE CODE.

Metallor, I re-read your post and I got it working! Thanks for your help
Keith

Glad to hear it. Good luck.