A doorbell is great for letting you know when someone is at the door.
<br>
But what do you do, if your music is turned 100% up. Or you sit with headphones… You won't know someone rang your doorbell. And you'll have to wait another day for that package you have been waiting for so long on…
If you have a wired doorbell, and it doesn't have a voltage out like mine on button press. Get a “Current Sensor Module” on ebay. This will then give you a voltage out! But beware that it also give you voltage while idling (so change the script to where the threshold fits). Just beware that current sensors isn't the most stable solution. As magnets tends to affect them ;)
If you have a wireless doorbell, poke around with a multimeter and see where there is power while button is pressed (LED, Speaker??). If you don't really know what you're doing, you should be ready to by a new unit or get a second receiver that you can play on.
Since I want an instant notification, I choose to power this instead of letting it be powered by the batteries (takes 2-3 seconds to connect to wifi).
The ADC port on the ESP8266 can maximum handle 0.978V, so you need a simple resistive voltage divider.
The voltage divider I decided to make, will turn 7.2V (“Vin”) down to 0.978V (“Vout”).
This gives me 0.550Vout when Vin is 4V.
<br>For resistance I used 1k as R1 and 157 as R2 (The 157 was made by connecting 100+47+10 in series). And the GND should be the same on all 3 things.
I was lazy, so I just used NodeMCU. I wanted to use MicroPython, but that seems to run the chips very hot. I prefer that you can't even feel they are on.
tmr.alarm(2,50, 1, function()
currentADC = adc.read(0)
if currentADC > 20 then
-- Button is currently pressed!
print("C-ADC: "..currentADC.. " P-ADC: "..previousADC)
if previousADC < 21 then
previousADC = currentADC -- Fix for long HTTP requests...
-- slicknet:send("STROBE 300,5000")
-- slicknet:send("DOORBELL " .. node.chipid())
conn=net.createConnection(net.TCP, false)
conn:on("receive", function(conn, pl) print(pl) end)
conn:connect(8888,"ws.mathias.local")
conn:send("GET /notify?type=button&id=doerklokken&value="..currentADC.."&nma HTTP/1.1\r\nHost: ws.mathias.local\r\nConnection: keep-alive\r\nAccept: */*\r\n\r\n")
end
end
previousADC = currentADC
end)
-- Don't forget to add a "keep alive" script too!! Sometimes ESP's wifi gets stuck pretty easily.