Arduino, LED-s, LM35 and DS18B20 or temperature sensors. 2


Checked out my local electronics store http://www.oomipood.ee yesterday and got some stuff.

First, a breadboard and some wires. Also got me a soldering iron. Those are just for testing. At least I do not have to twist wires together now.

Then I thought, LED-s are cool for something, right? There is a nice site http://www.ladyada.net/learn/arduino/lesson3.html. So I did get 10 1/4W 1K ohm resistors, and some leds, specifically 2 red, 2 blue and 2 green. 3mm and somewhere near 2000-4000 mcd.
As LEDs, when turned off, look the same, at least to me, I had the pleasure of figuring out which one is which.
As Arduino Duemilanove has digital pin 13 already connected to a led and also a resistor, it was simply a connection test – LED-s longer leg to pin 13 and shorter to GND.

Then is was time for LM35DZ temperature sensor. This is a nice analog device, which should be pretty accurate and covers temperature range of 0-100C. Good for indoors and underfloor heating temperature.
Good tutorial for it can be found in http://pscmpf.blogspot.com/2008/12/arduino-lm35-sensor.html.
Basically You just connect ground, power and analog from arduino. This is the reason why I did get that sensor anyway.

My code for two blinking LEDs on digital ports 13 and 12 and LM35 on analog port 0 looks like this:

int ledPin1 = 13; // LED connected to digital pin 13
int ledPin2 = 12;
float tempC;
int analog_tempPin1 = 0;

// The setup() method runs once, when the sketch starts

void setup() {
    // initialize the digital pin as an output:
    pinMode(ledPin1, OUTPUT);
    pinMode(ledPin2, OUTPUT);
    Serial.begin(9600);
}

// the loop() method runs over and over again,
// as long as the Arduino has power

void loop()
{
    tempC = analogRead(analog_tempPin1); //read the value from the sensor
    tempC = (5.0 * tempC * 100.0)/1024.0; //convert the analog data to temperature
    Serial.print("analog ");
    Serial.print(analog_tempPin1);
    Serial.print(" ");
    Serial.println(tempC); //send the data to the computer

    digitalWrite(ledPin1, HIGH); // set the LED on
    digitalWrite(ledPin2, LOW); // set the LED off
    delay(1000); // wait for a second
    digitalWrite(ledPin1, LOW); // set the LED off
    digitalWrite(ledPin2, HIGH); // set the LED on
    delay(1000); // wait for a second
}

 

Putting Your finger on that LM35 and seeing temperature rise is a good indication, that at least something works.

Unfortunately, using digital temperature sensor, DS18B20 proved to be more of a challenge. I did look at http://stuff.nekhbet.ro/2009/08/23/how-to-use-the-ds18s20-and-ds18b20-temperature-sensors-with-arduino.html
and some other examples, but unfortunately forgot to purchase 4.7Kohm resistors. Back to shop then.

Getting DS18B20 to work with required 4.7Kohm resistor is described in arduino-and-ds18b20-1-wire-digital-thermometer.

Description how to read LM35 more accurately can be found in Accurate LM35 readings.

 

Leave a comment

Your email address will not be published. Required fields are marked *