Reading voltage from Pin 2
Posted: Sun Apr 12, 2015 10:14 am
I am attempting to connect pin 2 to a temp sensor and read voltage. I have a tmp36. I have confirmed that it is working using an Auduino UNO:
https://learn.adafruit.com/tmp36-temper ... emp-sensor
I have confirmed that I am correctly identifying pin 2 as I was able to use it in output mode to blink an LED. However, no sketch I have tried can get anything from analogRead other than '0'. I have even tried connecting pin 2 back to 3.3v.
Any suggestions?
Sketch:
https://learn.adafruit.com/tmp36-temper ... emp-sensor
I have confirmed that I am correctly identifying pin 2 as I was able to use it in output mode to blink an LED. However, no sketch I have tried can get anything from analogRead other than '0'. I have even tried connecting pin 2 back to 3.3v.
Any suggestions?
Sketch:
Code: Select all
int sensorPin = 2;
int i = 0;
void setup() {
pinMode(sensorPin, INPUT);
Serial.begin(115200);
}
void loop() {
int reading = analogRead(sensorPin);
Serial.print(reading);
Serial.println(" reading");
float voltage = reading * 3.3;
voltage /= 1024.0;
Serial.print(voltage);
Serial.println(" volts");
float temperatureC = (voltage - 0.5) * 100 ; //converting from 10 mv per degree wit 500 mV offset
//to degrees ((voltage - 500mV) times 100)
Serial.print(temperatureC); Serial.println(" degrees C");
// now convert to Fahrenheit
float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
Serial.print(temperatureF); Serial.println(" degrees F");
Serial.println(i);
Serial.println("");
Serial.println("");
i+=1;
delay(1000);
}