Monday, February 29, 2016

Arduino Circuit with Temperature Sensor TMP36 - Temp Reading Functions as LED Switch

I finished building the basic circuit for controlling a LED bulb with a switch control (the white jumper wire in the photo below).


After disassembling this switch circuit, I decided to create a circuit where an LED bulb the switch for on/off would occur when the room temperature would drop below a specific number. I've found that the TMP36 sensors are not terribly precise with air temperature readings. They can frequently be off by over 20 degrees with a very basic circuit that runs off the 5v Arduino output. I searched for an solution to increase the TMP36 sensor's accuracy and found this alternative circuit on the Adafruit site (scroll down to the "Getting Better Precision" section) which utilizes the 3.3v reference voltage as ARef. I then added a basic LED bulb to my circuit and added code that would turn the LED on if the temp sensor's reading dropped below a 210 voltage reading (approximately 66 degrees Fahrenheit).

Here is the circuit diagram


Here is the Arduino sketch's code


int TempSensorPin = A6; //analog pin 0

int YellowLED = 6; // The LED attached to pin 6 will be called GreenLED

void setup(){

Serial.begin(9600);

pinMode(YellowLED, OUTPUT); // sets GreenLED Pin as an output sending data or current out

pinMode(TempSensorPin, INPUT);

// Set pin A5 to use as a power pin for the light sensor for LilyPad only as per Tutorial - I did not use these two lines as I powered with + not A5

pinMode(A5, OUTPUT);

pinMode(A5, HIGH);

}

void loop(){

int TempSensorValue = analogRead(TempSensorPin);

Serial.print("Temp value is:"); // Print some descriptive text and then the value from the sensor

Serial.println(TempSensorValue);

if (TempSensorValue <450) { // if the SensorValue is higher or lower than a certain value

digitalWrite(YellowLED, HIGH); // turn the LED on

} // this brace closes the if statement

else { // otherwise

digitalWrite(YellowLED, LOW); // turn the LED off

} // this brace closes the ELSE statement

//delay(200); // This is too slow down the process adjust as necessary

}

No comments:

Post a Comment