Simple temperature gauge

Hi there,

Complete noob here so be nice please!

Im probably missing something very simple, but only just got this for xmas so not very good at it. My code:

void setup() { Serial.begin(9600); int sensorPin= 0; // put your setup code here, to run once:

}

void loop() { float temp = analogRead(sensorPin);

Serial.println(temp); delay(1000); // put your main code here, to run repeatedly:

}

The error message it keeps returning is: 'sensorPin' was not declared in this scope

Any ideas? Thanks.

Any ideas?

Yeah: 'sensorPin' was not declared in this scope. It says right there.

You only need to think from the perspective of a computer: how do you read voltage from a pin not yet specified?

'int sensorPin= 0;'

So i need to set it as an output as well?

jaddion82052: 'int sensorPin= 0;'

So i need to set it as an output as well?

Suggest you read up on the tutorials for analogRead here

Slightly enhanced the code so that the variable sensorPin is in the global scope.

int sensorPin = 0;  // global scope

void setup()
{
  Serial.begin(9600);
  Serial.println("Start temperature 0.1");
}

void loop() 
{
  float temperature = analogRead(sensorPin);

  Serial.print(millis());
  Serial.print("\t");
  Serial.println(temperature);

  delay(1000);
}

Just change the sensorValue datatype to what you require!

int sensorPin = A0;    // select the input pin for the sensor
int ledPin = 13;      // select the pin for the LED
int sensorValue = 0;  // variable to store the value coming from the sensor

void setup() {
  // declare the ledPin as an OUTPUT:
  pinMode(ledPin, OUTPUT); 
  Serial.begin(9600);
  Serial.println("Start temperature"); 
}

void loop() {
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin); 
  if (sensorValue >= somevalue)
  {
    // turn the ledPin on
    digitalWrite(ledPin, HIGH);
    Serial.println("In range");
  }
  else
  {
    // turn the ledPin off:
    digitalWrite(ledPin, LOW);
    Serial.println("Out of range");
  } 
  delay(1000);                 
}
[glow=lightgreen,2,300]void setup()
  {
  Serial.begin(9600);
  int sensorPin= 0;
  // put your setup code here, to run once:

  }[/glow]

void loop() {
  float temp = analogRead(sensorPin);

The green part is the “scope” in which sensorPin is defined. Then you try to use it outside that scope.