Pages: [1]   Go Down
Author Topic: Temperature sensor problem  (Read 447 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 14
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Okay just to give an idea whats on the table- I'm new I couldn't make a code without examples so I've come to ask.

The code I present here I hoped to print a reading from the temperature sensor when I press the push pin.  However it doesn't work; honestly I'm surprised it doesn't have a error when I verify it. Any help would be wonderful...



int sensorPin = 0;                                  
const int buttonPin = 2;
int buttonState = 0;


void setup()
{
                          
  pinMode(buttonPin, INPUT);
  Serial.begin(9600);

}

void loop()
{
  if (buttonState == HIGH) {
    
   int reading = analogRead(sensorPin);
 float voltage = reading * 5.0 / 1024;
                    
   Serial.print(voltage); Serial.println(" volts");
 float temperatureC = (voltage - 0.5) * 10 ;

 Serial.print(temperatureC); Serial.println(" degress C");
 float temperatureF = (temperatureC * 9 / 5) + 32;
 
 Serial.print(temperatureF); Serial.println(" degress F");
 
 delay(1000);
   }
  }
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 200
Posts: 12782
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
int sensorPin = 0;                                  
const int buttonPin = 2;
int buttonState = 0;


void setup()
{
                        
 pinMode(buttonPin, INPUT);
 Serial.begin(9600);

}

void loop()
{
  [glow]buttonState = digitalRead( buttonPin );[/glow]

 if (buttonState == HIGH) {
  
  int reading = analogRead(sensorPin);
float voltage = reading * 5.0 / 1024;
                    
  Serial.print(voltage); Serial.println(" volts");
float temperatureC = (voltage - 0.5) * 10 ;

Serial.print(temperatureC); Serial.println(" degress C");
float temperatureF = (temperatureC * 9 / 5) + 32;

Serial.print(temperatureF); Serial.println(" degress F");

delay(1000);
  }
}
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 14
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you, and... amazing.  It's going to be interesting learning this language.
Logged

Pages: [1]   Go Up
Jump to: