How to calibrate a sensor (while using blynk)

I have a (let’s calle it a) blynk-device. I’ve noticed that the T(emperature) shown by the sensor of the blynk-device is usually slightly higher than the actual ambient temperature. Hence calibration is in order.

However I’ve also noticed that the dT (=Tsensor - Tambient) varies depending on Tambient. E.g.
@30C: dT ~ 0 while
@20C: dT ~2C
So simply coding Tshown = Tsensor-2) won’t work.
I could map() the T but that would assume a form of linearity (of which I’m not certain) and I’ve also noticed that dT at a fixed Tambient can also vary (jeeej).

I think the best solution is to regularly measure Tambient and feed that to the blynk-device. The blynk device then stores both Tambient and Tsensor and over time creates a database of averaged Tsensor per Tambient.

Now in writing this all sounds nice, but does anyone have any clue how to fly this home with blynk?

Sounds complicated. How close is the sensor to a heat source? for example the device itself. Sometimes it is due to the sensor itself … which is not as perfect as one would wish … For example, the speedometer of my car marks 120km / h when the sensor of my gps dials 110 … which is the correct one? I may have to wait for a traffic ticket to arrive to find out …

How do you check the room temperature apart from the sensor? with a thermometer from a Chinese store?

With so little information, it is difficult to imagine the problem to find a viable solution and be able to tell you more concretely how to do what you want …

In our office we have two thermometers, one spring and one mercury, both side by side … and they mark temperatures with a difference sometimes of two or three degrees … which is the right one? To know it, we would have to use a more sophisticated environmental temperature sensor maybe…

2° temp difference doesn’t sound like a lot as mentioned previously the proximity with the MCU itself would generate it and it’d be very difficult to compare “apples with apples”. E.g know that you’re actually measuring the same temperature with the external sensor unless you do an ice point check or boiling perhaps. Thermocouples type K for example have accuracy (if I’m not wrong) around +/-2°

to fill in some gaps:

yes, the sensor IS influenced by the device itself, its in relative close proximity to both the V stepdown (220–>5V) and a Wemos d1, which operate ~28-30C. I’ve placed the sensor as far away as possible and added barriers AND air flow points to minimize the impact but its still there. The fact that its there doesn’t mean I should not calibrate though…

As for measuring: I’m using 2 devices to measure ambient temp:

  1. a honeywell room thermostat (figured that their stuff should be quite adequate in delivering the right temp)
  2. a (chinese) infrared sensor, which measures the T based on the IR emission of the environment.

Both 1 and 2 are eerily close in what they tell about ambient T, sometimes .5C difference.

So given this 3 point measurement of which one is obviously influenced by close proximity factors…I would like to calibrate it preferably as mentioned in the OP.

I guess it depends on how accurate the temperature reading needs to be for your project. I have a thermostat which uses readings from a BME280. I’d expect to have to set the target temperature to around 22° to achieve a comfortable result, but in fact I have to set it to 24° to achieve what my body thinks is the correct temperature.
As the temperature range I’m measuring is fairly narrow, I could simply deduct 2° from the results of my sensor and all would be good, but I haven’t bothered (yet at least). In the end it’s just a number, and unless you’re trying to achieve a certain specific temperature - such as if you’re running an incubator, or wanting to push weather readings to a service such as weather underground - then it doesn’t really matter. I once lived in a house that had a thermostat numbered 1-10. Setting it to 6 was comfortable, but you might crank it up to 7.5 if you were feeling chilly.

If getting a more accurate calibration is important then you’ll need to get hold of an accurate thermometer and check the readings.
A simple case switch statement is probably the easiest way to do it…
Temp == 22 to 24 then deduct 2 degrees
Temp == 24 to 26 then deduct 2.2 degrees
etc etc.


I think the only viable option to autocalibrate the obtained measurement is to have more than one sensor in different positions and try to get the average of the measurements … You can never be sure of the variation of the accuracy of a sensor with respect to time. … try to compensate something variable that you sometimes think is totally “random” without any other sensor connected to your system to compare its values … it is simply an odyssey …

This or use a better sensor… (i don’t know what sensor is better :smile: )

Another way of doing it would be something like to create a substitution table …

Create a learning mode where what is measured by the sensor and what measured by the
thermostat (that you send it to the application using blynk perhaps) … you can create a
table similar to this:

Sensor    Real
0         0
1         1.10
2         2
3         2.90
27       28
28       28.5
29       29   

and when the sensor get a temp, send the correct value from the table…

yes, maybe it’s the same as killing mosquitoes with cannon fire … but surely after receiving the cannonball, there is no mosquito left :smile:

The problem with a substitution table is that you also have to deal with the intermediate decimal values, so it gets very cumbersome.

A case statement can handle a range ov values, so it’s a more elegant solution.


thank you all, this gives me something to mull over.

Is only another approaching way… and as i said… is an absurd way… (kill mosquitoes with cannonball) but it allows you to have other points of view that even if you do not use them, they can help you to dispel a better solution …

1 Like

Not too sure about it, as Pete said, thermostats sometimes have only scales from 0-6 for example. Additionally I had a quick look at their website and didn’t find any information on accuracy. I used to work at Siemens they pretty much use to do the same thermostats… From a commercial perspective you don’t want your thermostat to be extremely accurate as imagine the ordinary customer looking at a thermostat changing the temperature at 0.1° resolution every second or so…

You said both thermostat and China IR are reading similar temperatures I believe this is only a coincidence as IR measures surface temp only and you have emissivity error and IR thermometers won’t offer any accuracy better than +/-2° anyway.

You can try this to correct your reading based on data acquired from your other devices maybe using something like

thnx. im not looking for too accurate sensor but I do like it to be more correct than +/-2C. Im beginning to see though that this might be overkill and that working with ‘feel’ is possible better. Anyway thanks all for your replies!

1 Like