Gateway firmware in the dongle stays the same even in case you would like to send some special data. There is an API to send custom buffer from remote to the MQTT.
Even if you would like new topic, you just edit the remote and use these functions:
They are something like C to Radio to MQTT and you choose the topic and values to send.
You can also use Solid State Relay (SSR) which has wide input voltage range 3-32V so you dont need to bother with resistor, they are actually pretty cheap.
You just need to check that the minimal input voltage is under 8V and minimum output voltage is 3V or less - SSRs are usually for bigger output voltages and current, but we can also use them to simplify our circuit.
By coincidence, I managed to gain some unused Arduino starter kit and after few hours the simulation of doorbell integration works!
I used Arduino 5V and GND pins instead of 8V doorbell circuit, there was optocoupler 4N35 and resistor 1k ohm in the set so I used them. The second circuit of the optocoupler is following the button schema as suggested. Also added a small button to the first circuit to test the ring event. And then it worked as you can see in the second photo, there are push button events on the ulmus node.
Definitely beginner’s luck!
Thanks, Martin! I have learned a lot today and another integration ideas are popping up in my head
Of course, first I need to productionize this. I will drop the final pictures here when I am done.
Wow! Congratulations, that’s awesome that you have it working.
Since you have this nice setup, I would suggest a small test to see, if the AC signal which will go into the optocoupler will work on the button input - because of that debouncing.
Try to create a loop liek this to emulate 50Hz signal (this is pseudocode from my head)
This will generate 50 Hz signal. In case this would not reliably work, you’ll have to make a small change in the remote node firmware. But maybe you’ll need to do some changes anyway so for example only first doorbell press in 10 seconds window will be send to save batteries. On the other hand, you can have secret doorbell morse code which can be decoded on Raspberry Pi and trigger special features.
well, I decided to experiment directly with real conditions Below is how the semi-production environment looks like now. The first doorbell press was promising. The event was there but after that nothing at all.
I switched back to my original testing env to test whether everything is okay and there was no problem at all. So I went back to semi-prod and started more thorough testing.
The problem is with the standard short press (just click). That generates event only very rarely. But with a long press, it always generated a couple of events with the count depending on the press duration.
Any ideas how to fix this? And please keep in mind that perhaps I have some talent for experiments but my understanding of things I do is still very limited
The issue that short doorbell press may not generate event and long press generate multiple is because the code that is reading button does software debouncing.
Pushbuttons often generate spurious open/close transitions when pressed, due to mechanical and physical issues: these transitions may be read as multiple presses in a very short time fooling the program. https://www.arduino.cc/en/Tutorial/Debounce
This is also nice article with image, you dont need to read or undrestand the code becuase everyone’s debounce code is different Debouncing a switch - Protostack
The issue is that since the optocoupler is getting 50 Hz AC signal because the doorbell transformer is not rectified to DC. This gives us imaginary 25 presses of button per second (50Hz / 2) and thats why sometimes its not recognized as button press and sometimes the single long doorbell press is recognized as multiple button presses.
We have to ways to solve it:
Hardware
Software
Hardware solution
This is my preffered way because you and everyone else could use the stock firmware without any change. You would need to add two more electronic parts to your circuit - diode and capacitor.
So between the transformer and resistor-optocoupler you put this Diode an Smoothing capacitor (ignore the RL resistor in the image below)
The type of diode dont care so much. You can theoretically use also LED as a diode. The capacitor can be ceramic or electrolytic with values somewhere un uF (microfarads). Just be careful because electrolytics have polarity and the MINUS pin is marked with ‘-’ on the package.
By this “half wave rectifier” the optocoupler will be on all the time and the Core Module will see one single long press of the button. This way you would recognize how many someone pressed the doorbell.
Software solution
This would need basicaly replace the bc_button with simple few lines of code. So the pseudocode could look like
#include <application.h>
void application_init(void)
{
bc_gpio_init(BC_GPIO_BUTTON);
bc_gpio_set_mode(BC_GPIO_BUTTON, BC_GPIO_MODE_INPUT);
// The Core Module has hardware pull-down on BUTTON BOOT PIN so next call is commented
//bc_gpio_set_pull(BC_GPIO_BUTTON, BC_GPIO_PULL_DOWN);
... init of radio and other stuff .....
}
void application_task()
{
uint8_t button_state = bc_gpio_get_input(BC_GPIO_BUTTON);
if(button_state)
{
bc_radio_pub_push_button(0); // send parameter zero
bc_scheduler_plan_current_relative(5000); // sleep the task for 5 seconds - change this to your taste
} else {
// The button is not pressed
// Repeat this task again after 50 ms - higher is better for battery but you can miss the ring signal
// so 50-100 ms seems reasonable to me
bc_scheduler_plan_current_relative(50);
}
}
I would be interested if you’ll be able to fix it by that half wave rectifier. Let me know if you would like to try that way. In case you’ll decide for software solution, I’ll try to do the same setup as you and test the code if you run in some issues.
You’ve written that your understanding is limited, but I’ve tried my best to find basic articles and explain it all as simple as I could. I feel that this is the right way because I feel that you’re happy that you have it working so I thought you could learn more. It’s not that complicated if you don’t put math to it
I definitely go the hardware way First, it is exciting and fun to build something, and as long you are willing to guide me I am happy Secondly it is better to avoid maintenance of any addtional software.
I will inspect what other parts can be found in that Arduino starter kit and follow your instructions.
which capacitor to use? The electrolytic is the only one where I can read the value 100μF .
What about the resistor which I have on the circuit now, keep it as the first member?
Try the electrolytic caps first. You have to experiment. Try if it will run fine with ceramic caps later. The ceramics have its value coded in 2-3 numbers. What you need is value around 105 (10 * 10^5 F = 1uF).
But this is really trial and error. You don’t damage anything. If you choose too big capacitor value then you could miss when for example someone does two button presses on the doorbell. But you miss only the second button press within few seconds. So you have to find capacitor value that will smooth the 50Hz input signal, but not too much big so you can reliably distinguish when someone presses doorbell twice. But this is up to you if you would like to get more MQTT messages when one person is ringing twice.
(By rectifiying the AC voltage you get little bit higher DC voltage but your optocoupler resistor is 1k which is safely way above the value I’ve computed)
The half bridge rectifier needs to be placed between transformer and your current resistor-optocoupler circuit.
I got stuck today. Started as suggested with a diode and one 100μF capacitor. The behavior didn’t change much. Some events for short press are still missing and long press generates set of events. In fact, there is no problem with more events but the missing event for short press is a showstopper.
The strongest of ceramic capacitors I have is 104, I tried to connect up to 15 of them in parallel but it didn’t work at all, no event from both short or long press registered.
As I had the parallel setup ready, I started to add more 100μF capacitors. Subjectively my impression was that the lowest loss rate of short press events was with 4 100μF capacitors and then it got worse when adding more. But no serious statistics were done. Anyway, always some short press events were missing. Sometimes in the beginning, sometimes the beginning was fine and the gap came after some successful attempts. Well, but I am far from being able to define any clear patterns.
And in fact, there was not much different behavior when I bypassed the capacitors at all so there were just the diode, the resistor, and optocoupler.
I tried some other things which probably didn’t have sense, like changing the resistor, replacing diode with led, changing the order of diode and capacitor, and other various combinations expecting some miracle. But it didn’t happen.
Hi, you have a mistake on the breadboard as I can see. The diode pin with white band, 1k resistor and plus pole of capacitor has to be connected together. Not in series with a capacitor. And the minus pin of capacitor has to be connected to the ground - which should be your black wire?
Also, use only one capacitor. No need to have them paralel… try it with one and the we’ll see.
This is how it should look. I cannot see how that two wires are connected to the Core Module. But one pin of output of optocoupler should be connected to VCC and the other to the BUTTON/BOOT pin.
I’ve just created the same circuit just to make sure it works. I have 220uF 25V capcacitor and I feel it is too much because it dont react on the double press of the button. The 22uF seems on the endge so 100uF would be ideal… I try to find it meanwhile.
I’m testing this on the osciloscope so I can see how the rectified voltage is stable.
100 uF seems too much. SO 47uF would be ideal to dont miss double or triple doorbell press and at the same time filter the AC voltage enought that it dont trigger sporadic new button press.
100uF filter output. I also use 1k resistor but the optocoupler is little bit different.
yes, tested double or triple click and it generates just one event but for my purpose it is optimal. But who knows, perhaps some ideas about secret codes will come one day
sure, first I will share the picture of the final implementation. And probably I will stay just with SMS for now, have USB modem as SMS gate on the same hub as BigClown usb-dongle. I use emtecko where calls and sms are for free in the company network so the total cost monthly is around 3 CZK for the sim.
Now focusing on building the sensor network. There is not many things to add in the house but plenty in the garden and there are few challenges to be solved, I think I will create some new topics soon My intention is to store the full history of data, to build sort of personal dwh and use it as playground for machine learning. Trying to document things in my blog lubolab.com, but that’s always a challenge to find time for it. Soon should add there also something about BigClown integration
Thanks a lot, Martin, it was true pleasure to cope with this task here and my already great experience with BigCLown improved yet more, perhaps I will not be so scared of hardware now
I have to admit that from inside it looks quite DIY but my focus was just to place it inside and keep the maintenance easy as possible, so replacing batteries in both Gong and BigClown module without any special effort. Considering 5 days from the idea to production and my zero hardware experience, I hope it is not that bad