'SensorPin' was not declared in this loop

Hey,

I’m a very new Arduino user and I recently got the Arduino Starter Kit.

I am on project 3. I finished the coding but an error popped up. It read:

SensorPin was not declared in this scope
sketch_jul28a.ino: In function ‘void loop()’:
sketch_jul28a:15: error: ‘sensorPin’ was not declared in this scope
sketch_jul28a:47: error: expected `)’ before ‘{’ token

This is what I wrote. The erred line is in red.
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);

I can’t tell what I did wrong. Could someone please point out my mistake? Thanks!

Well you didn't post all the code... there is, or should be, stuff above loop() where you should have declared sensorPin and given it a value.

Welcome to the forum.
There are a few guidelines to ask a good question. One of them is to show the whole sketch.
You can use "code" tags around the sketch. Look at the buttons and smileys above the text input field. The '#'-button is for the code tags.

The error message is that sensorPin is not declared. It means that sensorPin is not declared XD

You declare it somewhere in the top of the sketch:

int sensorPin = 2;

Instead of the '2', use the proper pin that you want.

JimboZA wrote the same thing at the same time

Can’t tell what is wrong. Post your entire code.
Use the # tag and paste the code between the [code] [/code]

I can't tell what I did wrong

It is simple. The SensorPin variable is not declared anywhere in your program, or at least the portion of it that you have posted.

As an aside, please use code tags when posting code as it makes it easier to read. Please read http://forum.arduino.cc/index.php?topic=97455.0 and follow the advice given there.

Here’s the whole code…

const int sernsorPin = 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);
  
}

At the beginning I thought I did declare the Sensor Pin… It is connected to A0 on the Arduino Board.

Check spelling of sensorPin at the top...

JimboZA:
Check spelling of sensorPin at the top...

Oh.... Oops. :blush:

The Moral of the Story is, always post all the code 8)

Welcome, by the way…

JimboZA:
The Moral of the Story is, always post all the code 8)

Welcome, by the way....

I've learned.

One last question... I'm american, so do you know the voltage conversion to Fahrenheit, rather than celsius?

Thanks a ton!

You have to convert it afterwards, since the TMP36 is a Celsius device.

The conversion is F = 1.8C + 32.

I think that JimboZA provided a good solution, but the data sheet provides others.