Building Temperature Meter using UNOR3 and LM35 sensor

Definition of Tutorial: A tutorial is a step-by-step teaching guide designed to help someone "learn how to do something", usually by explanation and examples.

Figure-1: Schematic of Temperature Meter

1. VDT = DC voltage from signal pin of LM35 when room temp is T degC

2. Find relationship between T and VDT from response points of LM35 given in Fig-1:
T = 100 * VDT

3. Function to set full scale of ADC at 1.1 V: (Full scale is the maximum input signal which, when applied to an ADC channel, causes all output bits of the ADC to become 11 1111 1111.)
analogReference(INTERNAL);

4. Create/prepare Lookup Table (LUT) showing cc-codes for the digits 0 to 9 and A to F. The C++ declaration code for this LUT is given below Fig-2:


Figure-2:

byte lupTable[] = 
{
   0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, //0	1   2	3	4  	5  	6	7
   0x7F, 0x6F, 0x77, 0x7C, 0x39, 0x5E, 0x79, 0x71	//8  9   A     B   C    D    E    F	
};

5. Acquire VDT signal from sensor and save its binary form into variable y.
int y = analogRead(A4);

6. Find relationship between T and y.
T = 100 * (1.1/1023) * y; //T = 25.3

7. Convert T from float type to int type to make it compatible with display unit which accepts fixed number (no floating point number). (The decimal point is inserted manually.)
int myT = (int) T * 10.0; //21.5 * 10.0 = 253.0; myT = 253 = d0 d1 d2

8. Extract decimal digits (d0 d1 d2 = 2 5 3) from myT and save them in an array.

byte myDigit[3];
int i = 2;

do
{
    myDigit[i] = myT % 10;    //myDigit[2] = 00000011 = 3
    myT = myT/10;      
    i--
}
while(myT != 0);

9. Collect cc-code for the digits d0 d1 d2 from LUT and save them in variables:

byte ccd0 = lupTable[myDigit[0]];   //cd0 = 0x5B for 2
byte ccd1 = lupTable[myDigit[1]];   //ccd1 = 0x6D for 5
byte ccd2 = lupTable[myDigit[2]];  //ccd2 = 0x4F  for 3

10. Send ccd0 onto DP0 position of display unit.

PORTB = ccd0;     //PORTB accpets lower 6-bit (segemnts: a to f) of ccd0
digitalWrite(6, bitRead(ccd0, 6));    //DPn-6 accepts bit-6 (g segment) of ccd0
digitalWrite(7, bitRead(ccd0, 7));    //Dpin-7 accepts bit-7 (. segment) of ccd0
//-----------------------
digitalWrite(A0), HIGH);  //2 appears only on DP0 postion 
digitalWrite(A1, LOW);
digitalWrite(A2, LOW);
//------------------------
delay(5)
//===============================

11. Send ccd1 and ccd2 onto DP1 and DP2 positions of the display unit respectively

12. Open IDE, place the above codes under the appropriate places, write any missing codes, compile, and upload into UNO R3. Check that Display Unit shows room temperature at 1 sec interval.

13. Exercise
Re-write sketch of Step-12 using SevSeg.h Library to reduce number of code lines.

  • Should really add drivers here to handle the display current.

@LarryD

Thank you for pointing out the apparent design flaw.

I did not include a separate driver on the common-cathode (cc) pin based on the following line of reasoning.

When all segments are ON, the total source current (average) for a multiplexed digit (including the decimal point) is approximately 25 mA (4.5/470)Ă—8/3 which, although above the continuous rating of 20 mA of a sink pin, may still be tolerated by the MCU under multiplexed operation.

Nevertheless, I would still prefer to avoid using transistor drivers on the cc pins to save space and cost. Instead, I plan to increase the current-limiting resistors to 560R, which will reduce the total source (sink) current to about 21 mA.

Moreover, modern 7-segment display devices are quite efficient and produce sufficiently bright and visually pleasing output even at segment current well below 10 mA.

I would be glad to receive your feedback.

  • There are always exceptions to rules.

  • Placing an N channel MOSFET is warranted to key the digits to GND (common cathode).

Could use ULN2803.

  • Assume: 8 is being displayed, one red led per segment (2v drop across a segment LED).
    Iper segment = V470R / 470R
    I = (5V - 2VLED) / 470R = 6.4mA
    6.4mA * 7segments = 44mA plus a decimal point current.

But this is a 3-digit multiplexed display unit; will not the average current be taken? The period of the refresh cycle is 15 ms. So, the average source current per digit (including dot) is: ((5-2)/470 * 8)/3 = 17 mA.

How do you place the subscript and superscript?

  • Each digit has its own cathode to GND GPIO.

  • If we were displaying 888 we essentially have all the segments on all the time.

  • As in my calculations, when we have all segments on, the GPIO pin will have 44mA flowing, i.e. when software makes that GPIO LOW.

It is a multiplxed display unit; where, the segments of a digit remain ON only for 5 ms.

Can you find something in the ATMEGA328 data sheet for the MCU that says that it's ok so long as the average current is 25mA? And that it's ok if the instantaneous current is 3 times higher so long as it is only for 5ms?

Can you find something in the data sheet that says that the max continuous current is 20mA?

470 Hello 470

<sub>470</sub> Hello <sup>470</sup>

It is my assertion considering the absolute maximum rating of 40 mA per pin.

Correct. And does your proposed circuit respect that maximum? At all times?

Humm, is it safe to take 100mA, 200mA, 300mA . . . from a GPIO for only 1us per second ?

  • Suggest you not design towards average currents.
    For best practices, I recommend you to design to a steady state ON situation.

The datasheet says: IOH = 20 mA at VOH = 4.2 V when Vcc = 5 V. The “continuous maximum rating” phrase is not there.

VOH = minimum 4.2 V guranteed; so, IOH = 20 mA (maximum) should also be guaranteed. Hence, the phrase “continuous maximum rating”.

If I consider the average source current for the multiplexed digits, then the total source current per digit is: ((5.0 - 2.0)/470 * 8)/3 = 17 mA.

But @LarryD advocates in favor of considering steady-state current and not the average current.

Instead of 2803 power buffer, can I go with C828 NPN transistor?

  • That looks reasonable.

  • I am partial to SMD MOSFETs

The forum has a formal way of publishing tutorials.

For details see:
https://forum.arduino.cc/t/how-to-submit-a-tutorial/1111344

This topic aught to be moved to a relevant category.
I only know this because I fell foul of the issue when someone suggested that I moved a post to the 'Tutorials' category, and I did it prematurely.

Rare or medium?
With soy sauce or garlic?

Tom.... :smiley: :+1: :coffee: :australia:

Correct. The steady-state current is either 0mA, which is ok, or 3x17mA == 51mA, which is not ok.

I don't think the ATMEGA328 data sheet says that it's ok to exceed the absolute maximum so long as it's only for a short time. Therefore we must assume it's not safe to exceed the absolute maximum for any length of time.

Slightly Medium Done
etc.