analog temp. sensor

Hi every one really , i need your help i'v a project to find the level of the temp. using analog temp. sensor KY-013 and temp sensor 18B20 connected to A0 and 5 LED connected to pins 2,3,4,5,6 the range of the temp. wanted to be measured is from 25 to 125 when the temp. is 25 all the LED is off but if the temp. is 125 all the LED will be on so how can i program the arduino mega 2560 for this project help me please The range of the sensor ( both type) is -50 to 125 and the sensitive is 0.5 C what is the program?

Well, first you need to find the datasheet for your sensor, and see:

  • How to connect it and power it
  • What its sensitivity is, ie what voltage = what temp

If it's say an LM35, then google "LM35 Arduino" and you'll find a zillion hits.

edit.... that made a lot more sense before the OP edited the opening post.

Yes to all Jimboza posted!

Different sensors connect in different ways and give different information.

Possibly you have one that changes resistance with temperature. Then you give it power through a resistor to an analog pin and from that analog pin through a bigger resistor to ground. That last link must be there or the pin will read full 1023 fairly soon.

Others are made to connect to a bus like 1-wire bus or I2C bus and return data as serial messages.

You probably have the first kind.

There are plenty of example programs using the DS18B20 (integrated digital temperature) or the KY-013 (analog sensor module) but none already written for your specific project. It’s not hard to modify one of the exisisting ones though.

If you know how to turn on an LED you should be able to turn on multiple LEDs, it’s just a matter of which pins you drive HIGH. Then you can modify the sketch to turn on certain LEDs based on an value typed on the serial (for example).

Once you made that sketch you can create a sketch which reads the temperature from a DS18B20 or the KY-013 and just prints it on the serial console.

At this point all you have to do is mix the two sketches adapting the temperature so it can be the input for the LEDs: this part can be achieved just by using the map function:

unsigned int temp; // suppose this variable holds the temperature in C
unsigned int ledPins[5]; suppose this array holds the pins associated to each LED in order from bottom LED to top

// TURN OFF ALL THE LEDS
for (int i = 0; i < 5; i++) {
  digitalWrite(ledPins[i], LOW);
}
// DETERMINE HOW MANY LEDS TO TURN ON
int ledsToTurnOn = map(temp, 25, 125, 0, 5); 

// TURN ON THE RIGHT AMOUNT OF LEDS
for (int i = 0; i < ledsToTurnOn; i++) {
  digitalWrite(ledPins[i], HIGH);
}

So now i look like a jackass since you edited stuff into the opening post and my reply #1 makes bugger all sense now.

JimboZA:
So now i look like a jackass since you edited stuff into the opening post and my reply #1 makes bugger all sense now.

For a brief moment I thought you were talking to me :~

iraqikamal: Hi every one really , i need your help i'v a project to find the level of the temp. using analog temp. sensor KY-013 and temp sensor 18B20

Congratulations! You got ONE OF EACH KIND! Only 1 of those needs the analog sensor to work. I bet you can guess which!

Here's a tutorial on using the 18B20 that you could easily have found on Google with words 18B20 Arduino, http://www.hacktronics.com/Tutorials/arduino-1-wire-tutorial.html

I'll leave it up to you about how to find examples on that KY-013. It should be like wiring up a pot.