By Daniel Du
In last post I get my first Arduino experience and tried 123D circuits, I will keep moving to try some sensors. I will start from LM35 temperature sensor, which can be used to monitor current temperature. LM35 sensor is included in Arduino Starter Kit.
Let’s connect the hardware first, put the LM35 sensor on breadboard, and connect it with Arduino as below.
(You may notice the CC3000 WIFI shield extension on top of Arduino, I will use it to connect to internet later, let’s ignore it first in this post)
The left leg of LM35 is power, we connect it to the 5v pin on Arduino with a red wire, the right leg is ground end, we connect it to GND pin on Arduino with a black wire, the middle leg is value out, let’s connect it to A0 on Arduino with a blue wire.( if it does not work for you, you probably reverse the left and right side of legs of sensor)
Now, let’s write some code in Arduino IDE,
float temp = 0; // the setup routine runs once when you press reset: void setup() {
Serial.begin(115200);
Serial.println(F("reading temperature begin. \n"));
} // the loop routine runs over and over again forever: void loop() { static unsigned long sensortStamp = 0; if(millis() - sensortStamp > 100){ sensortStamp = millis(); // read the LM35 sensor value and convert to the degrees every 100ms. int reading = analogRead(0); //note that we connect the value end of LM35 to A0 pin temp = reading *0.0048828125*100; Serial.print(F("Real Time Temp: ")); Serial.println(temp); } }
Now go ahead to upload the code to Arduino and open serial monitor from “Tool” menu of Arduino IDE. This code snippet read current temperature value and display it to serial port every 100 milliseconds. If everything goes OK, you will see the temperature is output. If you heat up the sensor with a hair dryer, you will see the temperature is raising too.
Have fun!
Comments
You can follow this conversation by subscribing to the comment feed for this post.