Sunday, October 20, 2013

How To Use The LM335Z Temperature Sensor With An Arduino

Parts needed:
LM335Z temperature sensor
1K ohm resistor (brown, black, red)
Breadboard
Some wire

I had a little trouble finding code for this temperature sensor online, but ended up getting enough pieces together to finally get it working.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//Sketch created by Jacob Antoun
//10/20/13
//
//Wiring Info:
//Nothing is connected on the collector
//Analog Pin 3 is connected to the Base
//1K ohm resistor is connected to the Base, after the AnalogPin
//Ground is connected to the Emitter
//

#define tempSensor A0 //Puts the LM355Z temperature sensor on anolog pin 0

const float miniVoltsToKelvin = 0.004882812 * 100; //found this online, I don't remember the source :(

void setup() {
  Serial.begin(9600); //initialize the serial monitor
}

void loop() {
  float kelvin;
  float fahr;
  kelvin = analogRead(tempSensor) * miniVoltsToKelvin; //converts the reading from the arduino into kelvin
  fahr = 1.8 * (kelvin - 273) + 32; //converts the kelvin to fahrenheit
  Serial.print(fahr); //prints to the serial monitor
  Serial.print(" degrees");
  Serial.println();
  delay(1000);
}

If you want a copy of the code, and to see other projects I'm working on, look at my GitHub.
https://github.com/jacobantoun/LM335Z

Below are just two images that show the wiring of the temp sensor


Just showing the wiring of it on a breadboard

Notice how nothing is connected to the collector, and look at the placement of the analog pin and resistor.