Function Definition Error on My Code

Hello everyone,

I am creating a project to get more familiar with coding and Arduinos. I am pretty new to it all, so bare with me. I am about 1/4 finished with what I am trying to accomplish. I stopped to verify the code and received this error:

a function-definition is not allowed here before '{' token {

I can't figure out why I am getting the error on the void loop() { line.

//define pins for RGB LED
const int redLEDpin = 9;
const int blueLEDpin = 10;
const int greenLEDpin = 11;

//define temp sensor pin and a baseline temperature (degrees C) to start with
const int tempSensPin = A0;
const float baselineTemp = 20.0;

void setup()
{
//initiate serial monitor
Serial.begin(9600);

//declare the red, blue, and green LED pins as outputs and shut them off
for(int pinNumber = 9; pinNumber < 12; pinNumber++)
{
pinMode(pinNumber, OUTPUT);
digitalWrite(pinNumber, LOW);
{
}

void loop()
{
//declare var to read tempSenPin Value
int sensorVal = analogRead(tempSensPin);

//display tempSensPin readings on serial monitor
Serial.print("Sensor Value: ");
Serial.print(sensorVal);
Serial.print(" ");

//convert the output of tempSensPin to voltage
float voltage = (sensorVal / 1024.0) * 5.0;

//display the voltage on serial monitor
Serial.print("Voltage: ")
Serial.print(voltage);
Serial.print(" ");

//convert voltage to temperature (degrees C)
float temperatureC = (voltage - 0.5) * 100;

//display temerpatureC on serial monitor
Serial.print("Degrees Celsius: ");
Serial.print(temperatureC);
Serial.print(" ");

//convert degrees Celsius to degrees Fahrenheit
float temperatureF = (temperatureC * 9 / 5) + 32;

//display temperatureF on serial monitor
Serial.print("Degrees Fahrenheit: ");
Serial.println(temperatureF);

//add 5 second delay for easy reading on serial monitor
delay(5000);
}

If you use the IDE autoformat tool (ctrl-t or Tools, Auto Format) you can see where you have an extra { and a missing } and a missing semicolon

Thanks for the help. I saw that I had an absolutely simple error and I can't believe I was just seeing it wrong lol.

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