Go Down

Topic: Temperature sensor problem (Read 532 times) previous topic - next topic

Nethawk41

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);
  }
 }

Coding Badly

Code: [Select]
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);
 }
}

Nethawk41

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

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