Did I mention that I was working with a new part my Dad found for me? An awesome temperature sensor! It’s a neat little 3-pinned device that offered a few hurtles to conquer before getting it to meld to my demands. I often trust him for my information, but here, we both were a little stumped, for it fell into a grey area between both of our knowledge.

You see, the sensor takes in a 5V read in, and runs to ground on the other. The middle pin pulses out a signal in millivolts. One degree Fahrenheit is represented by a pulse of 10 millivolts. Simple enough right? Well you see, the Arduino software doesn’t exactly transfer that data literally, because you can’t receive the number ’10’ from that pin without some mathematical acrobatics.

First, I just wrote a simple program that printed whatever that data received was, to the Serial monitor. It was something like 140-150. I knew we were on the right track though. If I enveloped the temperature sensor in my fingers, the number would slowly increase, signifying a rising temperature and an increasing millivolt output. I needed to find a way to see how high that particular signal could go, but it’s not like I have lava on hand. The sensor is rated up to 300 degrees F. So how on earth could I push it to see if 300 was the max signal it would output, or if it was just the last guaranteed accurate one?

We pondered this question for a bit. Because there were still many variables I had that were unanswered. How does that 1xx number correlate to degrees? What’s the max output of the sensor itself? How can I get all this data?

I knew that somewhere along the line, the map() function was going to be used, so I figured good old trial and error was going to be my best bet. First, I thought mapping the signal to the range 0-300 would be the right choice, but I don’t know what the max signal is. Out the window.

Maybe map…wait no…

Or…

I sat there for an hour, stumped, but persistent. And then it hit me. In one moment, one measurement was going to solve this whole problem for me.

I was reading in a 5V input to analog. The sensor is acting as some sort of dynamic resistor, sending me signals that could vary from 0 – xxxx milliamps. If I could find out what unfiltered 5V looks like as this output, I could find that range. But how?

Potentiometer! I ran a pot from 5V to analog zero and cranked it all the way up and down. 0-1023. Bingo, there’s my range. Now all I had left to figure out is if the sensor would max out at 3k millivolts for 300 degrees, the guaranteed temperature. Or if it would max out at 5k millivolts, the entire power source for the component. This was easy:

map(mysensorinput, 0-1023, 0-3000);

or

map(mysensorinput, 0-1023, 0-5000);

My later assumption was true, the 0-5k range worked like a charm, and the rest was smooth sailing.

I’m going to continue working on this project, as I would like to document it in my Arduino notebook. As a 20 year old who is constantly told by their grades that they are a terrible student, it’s good to know that some times the best teacher is yourself.

Share this: Twitter

Facebook

Like this: Like Loading...