Hello, I am just starting out with arduino and have already run across a problem I just can't understand. I am trying to work my way through the project booklet provided with my official Arduino starterkit. I spent a lot of time attempting to get things to work, but my readings were erratic, too low and something obviously wasn't right. After some scouring the internet, I realised that I had been using the supplied BC547 transistors in place of a temperature sensor. However it seems that the temperature sensor that's supposed to be included in the kit (the TMP36) is nowhere to be seen. (Hence why I had been mistakingly using the wrong componant)
I concluded that sometimes parts are accidentally not included in kits like these, as mistakes happen, so went ahead and ordered myself a couple of TMP36s off eBay.
However, upon using the TMP36 in the circuit (which is structured exactly the same way as in the book, and with the original source code for this project), I am still getting the same problem! Only now, my results are far too high, instead of too low. And not quite as erratic but still clearly not stable.
I am wondering if my use of transistors in the circuit could have damaged something? Or if my new TMP36s are slightly different to the one I am supposed to have.
I have tried connected the TMPs middle pin to different analog inputs with no success.
As a beginner, I'm really at a complete loss as to what is going on. Please can you advise?
Results I'm getting in the serial monitor:
sensor Value: 942, Volts: 4.60, degrees C: 409.96
sensor Value: 930, Volts: 4.54, degrees C: 404.10
sensor Value: 945, Volts: 4.61, degrees C: 411.43
sensor Value: 940, Volts: 4.59, degrees C: 408.98
sensor Value: 930, Volts: 4.54, degrees C: 404.10
sensor Value: 946, Volts: 4.62, degrees C: 411.91
sensor Value: 939, Volts: 4.58, degrees C: 408.50
sensor Value: 932, Volts: 4.55, degrees C: 405.08
sensor Value: 947, Volts: 4.62, degrees C: 412.40
sensor Value: 936, Volts: 4.57, degrees C: 407.03
sensor Value: 933, Volts: 4.56, degrees C: 405.57
sensor Value: 948, Volts: 4.63, degrees C: 412.89
sensor Value: 934, Volts: 4.56, degrees C: 406.05
sensor Value: 935, Volts: 4.57, degrees C: 406.54
sensor Value: 948, Volts: 4.63, degrees C: 412.89
sensor Value: 933, Volts: 4.56, degrees C: 405.57
Love-o-Meter code:
// named constant for the pin the sensor is connected to
const int sensorPin = A0;
// room temperature in Celcius
const float baselineTemp = 20.0;
void setup() {
// open a serial connection to display values
Serial.begin(9600);
// set the LED pins as outputs
// the for() loop saves some extra coding
for (int pinNumber = 2; pinNumber < 5; pinNumber++) {
pinMode(pinNumber, OUTPUT);
digitalWrite(pinNumber, LOW);
}
}
void loop() {
// read the value on AnalogIn pin 0
// and store it in a variable
int sensorVal = analogRead(sensorPin);
// send the 10-bit sensor value out the serial port
Serial.print("sensor Value: ");
Serial.print(sensorVal);
// convert the ADC reading to voltage
float voltage = (sensorVal / 1024.0) * 5.0;
// Send the voltage level out the Serial port
Serial.print(", Volts: ");
Serial.print(voltage);
// convert the voltage to temperature in degrees C
// the sensor changes 10 mV per degree
// the datasheet says there's a 500 mV offset
// ((volatge - 500mV) times 100)
Serial.print(", degrees C: ");
float temperature = (voltage - .5) * 100;
Serial.println(temperature);
// if the current temperature is lower than the baseline
// turn off all LEDs
if (temperature < baselineTemp + 2) {
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
} // if the temperature rises 2-4 degrees, turn an LED on
else if (temperature >= baselineTemp + 2 && temperature < baselineTemp + 4) {
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
} // if the temperature rises 4-6 degrees, turn a second LED on
else if (temperature >= baselineTemp + 4 && temperature < baselineTemp + 6) {
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
} // if the temperature rises more than 6 degrees, turn all LEDs on
else if (temperature >= baselineTemp + 6) {
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
}
delay(1);
}
I have things set up like this (as per the booklet):
Please help me. Been struggling with this for days.