Go Down

Topic: Project 03- Love-o-Meter, seems to be a problem involving my loop. (Read 169 times) previous topic - next topic

Hey, I'm very new to arduino and I'm not sure what I'm doing wrong, but my code won't verify. Here is the code:

Code: [Select]
const int sensorPin= A0;
const float baselineTemp= 20.0;


  void setup(){
  Serial.begin(9600); //open a serial port
  for (int pinNumber =2; pinNumber <5; pinNumber++){
    pinMode(pinNumber, OUTPUT);
    digitalWrite(pinNumber, LOW);
  }
  void loop(){
    int sensorVal= analogRead(sensorPin);
    Serial.print("Sensor Value: ");
    Serial.print(sensorVal);
  }
 //convert the ADC reading to voltage
float voltage = (sensorVal/1024.0) * 5.0;
Serial.print(", Volts: ");
Serial.print(voltage);
Serial.print(", degrees C: ");
//convert the voltage to temperature in degrees
float temperature = (voltage- .5) * 100
Serial.println(temperature);

  if(temperature < baselineTemp){
  digitalWrite(2, LOW);
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);
  }
    else if (temperature >= baselineTemp+2 && temperature < baselineTemp+4){
    digitalWrite(2, HIGH);
      digitalWrite(3, LOW);
    digitalWrite(4, LOW);
    }
      else if (temperature >= baselineTemp+4 && temperature < baselineTemp+6){
      digitalWrite(2, HIGH);
      digitalWrite(3, HIGH);
      digitalWrite(4, LOW);
      }
        else if (temperature >= baselineTemp+6){
        digitalWrite(2, HIGH);
        digitalWrite(3, HIGH);
        digitalWrite(4, HIGH);
        }
    delay(1);
};


And here is the error message:

Code: [Select]
  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.
Arduino: 1.0.6 (Windows NT (unknown)), Board: "Arduino Uno"
Project_03_Love_o_meter.ino: In function 'void setup()':
Project_03_Love_o_meter:11: error: a function-definition is not allowed here before '{' token
Project_03_Love_o_meter:17: error: 'sensorVal' was not declared in this scope
Project_03_Love_o_meter:23: error: expected ',' or ';' before 'Serial'


Any help would be great, thanks!

dannable

There are several errors in your sketch.

The one you highlight is because you don't have the terminating '}' at the end of Setup(). Before void loop().

Then you have an extra one before:
Code: [Select]

 //convert the ADC reading to voltage


And then you are missing a semi colon at the end of this line:
Code: [Select]

float temperature = (voltage- .5) * 100


Why don't you just load the example provided in File -> Examples -> 10. Starter Kit ?
Beginners guide to using the Seeedstudio SIM900 GPRS/GSM Shield


Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy