LMT01 driving an Arduino Uno

I had no success getting help with any earlier post on this subject, so I am starting over with new code by Kevan Darrah. He is a good programmer, so the code should work, but it doesn’t. I did a lot of reading and I understand how it should work, so let me spend few words explaining what I learned and maybe someone can take it from there. The LMT01 output is 0.6V to 1.6V pulses 10 usec wide, I verified this using a scope, the total number of theses pulses is proportional to the temperature. This repeats every 150 msec. This signal is input to pin D2, but that is a digital pin: High=5V, Low= 0V, but Arduino IDE does something sneaky when you use the special function “attachInterrupt(pin,ISR,Falling)” – It redirects the signal internally to pin A0N of the positive side of an Analog Comparator, and attaches to AN1 internally a stable reference voltage of 1.1V. Now the 0.6V to 1.6V pulses are exactly centered on the comparator so it puts out a perfect 1’s and 0’s for easy counting.
So to repeat myself only Pin2 is attached with the LMT01 to the Arduino. Why doesn’t this &!#^- damned thing work, it compiled and uploaded correctly. If I had a debugger on this software, moving one line at a time I could fix it myself. Code follows:

//Sample Code for LMT01 Temperature Sensor
//Kevin Darrah

#define pulsePin 2 //D2 on arduino D5 on esp8266 **This is the output from the LMT01

//globals for the LMT01 temp sensor
volatile unsigned int pulseCount = 0;//pulses out of the sensor
float temperatureC = 0, temperatureF = 0;//converted temperatures
float tempHIGH, tempLOW = 1000;

void pulseDetect();//interrupt function
float getTemperature();//call this to get temperature from the LMT01 - returns a float for the temperature in (C)

void setup() {
pinMode(pulsePin, INPUT);//output from LMT01 sensor circuit


void loop() {
temperatureC = getTemperature();// call getTemperature() to return temp in C
if (temperatureC != 1000) {//returns 1000 if anything went wrong
temperatureF = temperatureC * 9.000 / 5.000 + 32;
if (temperatureF > tempHIGH)
tempHIGH = temperatureF;
if (temperatureF < tempLOW)
tempLOW = temperatureF;
Serial.print("C ");
Serial.print(“F HIGH=”);
Serial.print(“F LOW=”);
Serial.print(“F DIFF=”);
Serial.print(tempHIGH - tempLOW);
Serial.print("F ");
Serial.println("pulses ");
for (int i = 0; i < random(50, 200); i++)


float getTemperature() {// ********* GET TEMPERATURE FUNCTION *** returns the temperature C
attachInterrupt(digitalPinToInterrupt(pulsePin), pulseDetect, FALLING);//using interrupt pin tp trigger on falling edge

unsigned long conversionStartTime = millis();//keeps track of timing

while (millis() - conversionStartTime < 10) { //looking for silence, in case we go to read temperature mid-measurement, ride it out till next one
// yield();//for the ESP8266 to keep other tasks happy
if (pulseCount > 0) {
pulseCount = 0;
conversionStartTime = millis();

pulseCount = 0;//reset pulse count
while (millis() - conversionStartTime < 150) {//wait for first pulse
// yield();//for the ESP8266 to keep other tasks happy
if (pulseCount > 0)
if (pulseCount == 0)
return 1000;//FAIL - never got a pulse

conversionStartTime = millis();//conversion done, so reset time
unsigned int oldPulseCount = pulseCount;//just to help keep track of timings when pulse pin goes idle
unsigned long pulseTime = millis();
while (millis() - conversionStartTime < 60) { //measure pulses
// yield();//for the ESP8266 to keep other tasks happy

if (pulseCount != oldPulseCount) {//new pulse, so update timer
oldPulseCount = pulseCount;
pulseTime = millis();
else if (millis() - pulseTime > 5) {//no pulses for a while, must be done.
//^^^ Stays stuck here counting pulese for 60ms

if (pulseCount < 5) { //this is just noise, false trigger… I mean only 5 pulses, that can’t be right
return 1000;//FAIL

detachInterrupt(digitalPinToInterrupt(pulsePin));//done with the interrupt
temperatureC = 256.000 * pulseCount / 4096.000 - 50;//conversion
//see 7.3.2 Output Transfer Function in Datasheet

return temperatureC;//throw the temp back

//change this function to look like this if using the ESP8266
//void ICACHE_RAM_ATTR pulseDetect()

void pulseDetect() {// ********* PULSE COUNTER INTERRUPT FUNCTION

I did a lot of reading

But you didn’t read the sticky post at the top of the topic list. There you would have found information about how to post your problem so you’ll get help. I know that immediately by looking at your post because you didn’t use code tags for your code (that’s the </> button in the editor). Please edit your post and add code tags!
You would also have learned that we need links to the hardware you used.
If you didn’t use an Arduino Shield (where the connections are defined) we also need a wiring diagram of how you connected all the external hardware to the Arduino.