Welcome!
...
Previous Notifications
2023 3RDQ

The Analog of Things Part 2

10min
<< previous the analog of things part 1 docid\ ceng9veofrqiihv8mgd5q introduction the lm35 has been with us for a while, and when searching you may assume that it's something only recently from arduino days no it's from way back when what makes the lm35 useful is that it's a straightforward device to use, and it comes in a variety of packages these options enable the device to be accommodated in several settings from directly on the pcb, to mounting the device to the equipment or the item whose temperature is being measured the lm35 is not the only useful option, and we will also have a look at the mcp9700 as a contrast in a follow up article specifications when considering a sensor, the sensor's specifications should also factor in temperature range resolution accuracy operating voltage these factors translate into the lm35 will measure between 0'c and 100'c, and this is suitable for most domestic applications the resolution is 10mv /'c which means that every degree between 0'c and 100'c would be equal to output v = 0 01 t'c at room temperature (23'c), the output voltage of the sensor would be 0 230 v or 230mv the device's accuracy is +/ 1'c across its temperature range the lm35 has an operational voltage of 5vdc implementation options for the implementation options, we will review which package to select connecting the lm35, and interfacing with the pic microcontroller how to ensure a stable temperature measurement the right package the lm35 is available in a number of 3 pin transistorized packages show below is the diagrams and their variations we will be using the 3 pin to 92 package as it's the easiest to work with and is fairly common to obtain device connection now that you have chosen the package type, the next step would be connecting it to the microcontroller there are two options here, namely a direct connection and a buffered one if the lm35 sensor is situated some distance from the board, there will be a voltage drop a voltage follower amplifier should assist with maintaining the right voltage output the device has three connections as shown in the image below the vout pin would be connected in one of two ways directly to the input pin through buffering circuitry stability the output voltage which is later converted to the temperature may be subject to fluctuation owing to the device generating heat as current passes through it if the sensor were used for a critical application, it may be advisable to include a method that disconnects the sensor from its power source ie, do not run the device continuously power the sensor to take a reading or multiple readings over a short time frame and then switch off allowing it to "cool down" or return to the ambient temperature software implementation shown below is an example written for the pic16f887, which we will also update for the "passing the torch" series to make the code more useful, it sends the temperature result to the serial port the example is straightforward, with minimal configuration of the a2d required, as this is all handled by the library available in the compiler unsigned char ch; unsigned int adc rd; char text; long tlong; char tempc = "000 0"; void main() { intcon = 0; // disable all interrupts ansel = 0x04; // configure an2 pin as analog input trisa = 0x04; anselh = 0; // configure other an pins as text = "lm35 example"; // assign text to string text = "lcd example"; // assign text to string adcon1 = 0x82; // configure vdd as vref, and analog channels trisa = 0xff; // designate porta as input delay ms(2000); text = "voltage "; // assign text to string uart1 init(9600); delay ms(100); while (1) { adc rd = adc read(2); // get adc value from 2nd channel tlong = (long)adc rd 5000; // covert adc reading to milivolts tlong = tlong / 1023; // 0 1023 > 0 5000mv ch = tlong / 1000; // extract volts digit tempc\[1] = ch+48; ch = (tlong / 100) % 10; // extract 0 1 volts digit tempc\[2] = ch+48; ch = (tlong / 10) % 10; // extract 0 01 volts digit tempc\[3] = ch+48; tempc\[4] = ch+48; uart1 write(tempc\[2]); uart1 write(tempc\[3]); uart1 write text(" "); uart1 write(tempc\[4]); uart1 write(13); uart1 write(10); delay ms(100); delay ms(1000); } }// ! parts list an lm35 is needed and a pic development board to specifically use the pic16f887, then you would require a radix duo or radix sepia however, any of the radix series would work with this project owing to its simplicity however, some code modifications would be required depending on the radix and ic chosen that is all for now, more to come in the next installment of the analog of things part 3 docid\ znlcsqf89iu5hrwpqp1uo