If your ADC is 10 bit then you get 1023 for 5V
LM35 max o/p is 1.5V for 150 deg C.
If you are measuring 25 to 40 deg C then
1023 = 5V
306.9 = 1.5V (150 deg C)
25 deg C = 0.25 V = 51.15 raw adc value
40 deg C = 0.4 V = 81.84 raw adc value
o/p of LM35 will be 0.25V to 0.4V for 25 to 40 deg C
adc value will be 51.15 to 81.84
you are dividing this value by 2, so you get
temp / 2 =
51.15/2 = 25.575 = 25 as int is used
81.84/2 = 40.92 = 40 as int is used
temp will be 25 to 40
So, these two conditions never work
Code C - [expand] |
1
2
| if((temp >= 5) && (temp < 15))
if((temp >= 15) && (temp < 20)) |
but this will work as temp will be > 20 and < 70
Code C - [expand] |
1
| if((temp >= 20) && (temp < 70)) |