Hey I am Dutch. I am allowed to be a cheapskate.
So what does this have to do with this tech-weblog. Well I'll tell you.
What does every family has in their house: a fridge
And what is every Dutch guy and girl afraid of: that the light in the fridge will not turn off when you close the door and keeps burning money. Bull ?? No really. I have colleges at work that admitted that they on purpose broke the light in the fridge to make sure it was out. Another college told me that he just removed the light.
Well I did not want to do that because one of our fridges is in our basement in where there is insufficient light. So I need the light in the fridge. But what if it really will not turn off when I close the door. It keeps using electricity unnecessarily and therefore keeps wasting money.
As I am a tinkerer I knew I had to come up with something. And here is my solution.
And here is the setup. If the light in the fridge would be off it would be totally dark in the fridge and that would set the LDR to its highest resistance. Something like 10M Ohm. If the light would be on it would fully expose the LDR and it's resistance would be Minimal.
I used the Axel Benz formula and that showed me that the pull-down resistor would have to be 10K in this case.
I will delve deeper into this very usefull formula in an upcoming story.
Now that I had the working setup I wanted to make a nice looking webpage that informed me wether the light in the fridge would be on or off. I used my favorite development environment: ESP-BASIC
First in the filemanager section I uploaded two pictures of lamps one on and one off. That would be the base of my monitoring.
Then I examined which values the ESP analog port would registrate in darkness and in light. I did that by writing a simple Basic Program.
timer 100,[test] wprint |<h1 style="text-align:center;">Luc Volders</br>Light Tester</br>| wprint "<br/>" textbox value wprint "<br/><br/>" button "<h2>Off</h2>", [Off] wprint "<br/>" wait [test] sensor = io(ai) value = sensor wait [Off] end
Let's look at the program:
this statement at the beginning of the program makes sure that the routine called 'test' is called every 100 miliseconds.
sensor = io(ai)
value = sensor
The routine just reads the analog port of the NodeMCU and puts that in the variable 'value'
just puts the measured value in a textbox on the screen.
The rest is just HTML code to put the text in a fancy way on your screen and generates a button that, when pressed, ends the program.
So that is easy. Lets look at the values the program produces.
In darkness I would get a value of 13 and in full light 850.
Naturally I also get inbetween values if the LDR is in the shade. This helps enormously. The LDR is not always positionable direct under the lamp. So I need to place it at any vacant location in the fridge and it has to react to any little bit of light it can detect.
And here is the setup in real life. Well it is a testing setup just to prove the concept works. A PCB and casing will follow later on. The red arrow points to the breadboard and in front of it is a powerbank with an enormous capacity.
onofnew = 1000 onof=0 timer 100, [TOP] wait [TOP] onof = io(ai) if abs(onof - onofnew) > 30 then CLS wprint "<h2>Fridge light status</h2>" wprint "<br>" if onof < 25 then image "lampoff.jpg" else image "lampon.jpg" end if onofnew = io(ai) end if wprint "<br>" wait
And there is the full program. Not much to it.
Every tenth of a second a subroutine is called that tests wether the value of the LDR has altered with whatever small amount. Next the program tests if the value of the LDR is below 25 and that indicates that it is in full darkness.
So it works.
There are however some small problems.
First the power supply is giving me some problems. The batteries seem to loose strength in the cold of the fridge.So they do not last long.
Next is the Wifi connection. The problem is not the distance from my router as I have a good connection when the door of the fridge is open. But the connection fades away when the door is closed. Well that is obvious as the fridge's walls are made from sheet metal and that works like a faraday cage letting no signals escape. However that makes it impossible to really test wether the light is out when the door is closed.
Above mentioned problems are really annoying so I had to find a work around and I did. I still have to implement it but I will give you the setup:
Drill a hole in the door of the fridge and kit some perspex on it as a looking glass. That way you can easily see if the light in the fridge turns off as you close the door. However it is not as sexy as my ESP setup.
Till next time