Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 8 months ago.
How to calculate temperature using LM35 temperature sensor and mbed lpc1768?
please show the code as well as a simple connection diagram. My code is as follows for calculation. Please check if its correct or need any modification because in this the LED is blinking even the condition is false.
- include "mbed.h"
- include <iostream>
AnalogIn ain(p15);
DigitalOut myled(LED1); DigitalOut mysecondled(LED2); name LED2 pin output as mysecondled DigitalOut mythirdled(LED3); etc DigitalOut lastled(LED4); etc
int main() {
float voltage_in; float degrees_c; int i;
Collect temperatures with timestamps every second for(i = 0; i < 10; i++) { voltage_in = ain * 3.3; degrees_c = (voltage_in - 0.5) * 100.0; if(degrees_c < 40) { myled=1; mysecondled=1; } else if (degrees_c > 40) { mythirdled=1; lastled=1; myled=0; mysecondled=0; } }
return 0; }