Input devices

Group assignment

In this week's assignemt we just had to add an input device to the microcontroller board we design and measure something. A good thing is that the PCB I designes a few week ago also works for this assignment.

LM 35

The LM35 is a Centigrade temperature sensor, it gives an output voltaje that is linearly proportional to the Centigrade temperature and it does not require any calibration.

Pins

The LM35 only has three pins. It is power by a microcontroller, in this case, the attiny 45.

VIN: Positive power supply pin.

VOUT: Temperature sensor analog output.

GND: Device groung pin.

Conversion factor

The LM35 converts the temperature into an analog voltaje output, it outputs 10mV per degree Celsius. This means that for every degree Celsius, the output of the LM35 change by 10mV. The sensor requires a voltaje reference for accurate readings thats why I need to adjust the conversion factor according to the voltaje which I am powering it, so if I am using a 5v voltaje, the millivolts per step is 5000/1024 (1024 is the maximum value of the enalog read).

This means that each step of the analog to digital converter represents arround 4.88mV. Therefore, to convert the analog reading in °C I had to multiply the ADC reading by this factor.


		temperature = analogRead(3)*0.00488*100;
									

Coding

In the following code, the temperature is read from the LM35 sensor and depending if the value is above or below 20°C the LED will turn on or off.


int temperature;	//Declares de variable temperature

void setup() {
  pinMode(1, OUTPUT); //Set pin 1 as output LED
}
		
void loop() {
  temperature = analogRead(3)*0.00488*100; //Reads the analog imput from pin 3 and stores it in the "temperature" variable.
					
  delay(1000); // wait a second between readings
					
  if (temperature < 20) { //If the temperature is below 20°C the LED will turn on
	digitalWrite(1, HIGH);
  } 
  else {
	digitalWrite(1, LOW); //If the temperature is above from 20°C the LED will turn off
  }
}
				

Result

As a conclution I found out that when you use a sensor to obtain data, you depend a lot on your surroundings.