Hi
My temperature sensor is reading room temperature as 90* C, and randomly jumps to higher temps as high as 800.
do you think is there some thing wrong with my code?
if so please tell me what you think is wrong.
or tell me if you think it is my sensor please.
Could you help me out please.
hear is my code
const int sensorPin = A0;
const float baselineTemp = 105.0;
int green = 3;
int red = 5;
const int moterPin = 9;
void setup() {
pinMode(green, OUTPUT);
pinMode(red, OUTPUT);
Serial.begin(9600);
pinMode(moterPin, OUTPUT);
pinMode(sensorPin, INPUT);
for(int pinNumber=9; pinNumber<5; pinNumber++)
{
pinMode(pinNumber,OUTPUT);
digitalWrite(pinNumber,LOW);
}
}
void loop() {
int sensorVal = analogRead(sensorPin);
Serial.print("Sensor Value: ");
Serial.print(sensorVal);
float voltage = (sensorVal/1024.0) * 10.0;
Serial.print(", Volts: ");
Serial.print(voltage);
float temperature = (voltage - .5) * 100;
Serial.print(", degrees c: ");
Serial.println(temperature);
if(temperature > baselineTemp)
{
digitalWrite(moterPin, HIGH);
digitalWrite(green, HIGH);
digitalWrite(red, LOW);
}
else if(temperature < baselineTemp)
{
digitalWrite(moterPin, LOW);
digitalWrite(green, LOW);
digitalWrite(red, HIGH);
delay(500);
digitalWrite(red, LOW);
delay(500);
digitalWrite(green, HIGH);
delay(500);
digitalWrite(green, LOW);
}
delay(500);
}
pylon
April 6, 2020, 5:20pm
2
float voltage = (sensorVal/1024.0) * 10.0;
Does your Arduino board run on 10V? Really?
randomly jumps to higher temps as high as 800.
Sounds like a wiring problem. As you failed to post a wiring diagram it's up to you to search that error. Maybe a bad connection on the breadboard. Maybe an induction from the motor.
Does your Arduino board run on 10V? Really?
My Arduino board runs on 5V.
Here is a diagram
My Arduino board runs on 5V.
Consider replacing the 10.0 below with 5.0 (better, the actual, measured voltage of the "5V" supply), so that the result makes sense.
float voltage = (sensorVal/1024.0) * 10.0;
Wawa
April 7, 2020, 2:27am
5
Temp code can be improved a lot, but this could basically be a breadboard issue.
Start with connecting the TMP36 power/ground directly to the Arduino pins, not via the breadboard power rails.
Also better to power the TMP36 from the 3.3volt pin instead of the 5volt pin.
When it all works, and is stable, then you should change the code to use the more stable 1.1volt Aref.
Leo..
Wawa
April 7, 2020, 2:30am
6
Leave just the TMP36 on the breadboard, and try this sketch.
Leo..
const byte tempPin = A0; // connect TPM36 to 3.3volt A0 and (not-shared) ground
float calibration = 0.1039; // calibrate temp by changing the last digit(s) of "0.1039"
float tempC;
void setup() {
Serial.begin(9600);
analogReference(INTERNAL); // use internal 1.1volt Aref
}
void loop() {
tempC = (analogRead(tempPin) * calibration) - 50.0;
Serial.print("Temperature: ");
Serial.print(tempC, 1); // one decimal place
Serial.println(" C");
delay(1000); // use a non-blocking delay when combined with other code
}