8 years, 1 month 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.

  1. include "mbed.h"
  2. 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; }

1 Answer

7 years, 2 months ago.

if you write "ain.read()". probably could help you