Saturday, 4 December 2021

Door/Window Sensor with an ESP8266

It's been a long time since my last post but I thought I would write up about my latest project - a door/window sensor using an ESP 8266.

I've bought a few door sensors in the past from Tuya and a Hive one (load of rubbish) but I came across a brilliant YouTube video from a gent called MakerMeik who used a logic toggle circuit to wake up the ESP from sleep mode when a reed switch is opened or closed (https://youtu.be/vxbuO1zWo3w).

Using the two XOR logic gates alowed both the door open and door closed to wake up the ESP by toggling the Enable pin whilst also passing the reed switch state to the ESP to publish.

Mike used the ESP to connect to the router via DHCP (or fixed IP) which took a few seconds to establish before then logging onto your MQTT server and publishing the door status.

So I downloaded Kicad and gave it a try, I had tried Kicad a few years ago and was a bit disappointed but the latest version was streets ahead of what I remembered and I soon had a PCB ready to send off for fabrication.

Bare PCB

Populated PCB

The PCBs were delivered and I assembled one which worked as expected (nice surprise) and while I was waiting for the PCBs to arrive back from PCBWay I exported the PCB design as a 3D model (STEP file) which I was able to import into Fusion360 and use as the basis for an enclosure.
Initially my idea was to use an 18650 Lithium cell as I had plenty that I'd reclaimed from old laptop batteries, which still had reasonable capacities, my idea was to use two halves that could be screwed together holding the PCB and battery, this could be screwed to a surface or stuck on with double sided adhesive tape.
 
 


The design is quite tall at 33mm but this is OK for my back door which is double glazed and the door is quite deep so the deep back places the reed switch nicely inline with the magnet on the door.
Printed enclosure

Having finished this version of the sensor I've been investigating ways to increase the battery life and reducing the overall size.

I found some smaller batteries that I could use with this design in conjunction with ESP-NOW code that uses alot less transmission time so I designed another rear half that is alot shallower for the new battery.



Smaller rear half for smaller battery

One tip I can give is to buy the plastic encapsulated reed switches instead of the normal glass ones as they are prone to breaking, even though I used surface mount pads to solder the switch rather than having to bend the wires to go through holes.


With my next version I will be trying out the PCB assembly service from JLCPCB so that I can utilise smaller SMD components and not have to solder them together myself!!

Some things I want to improve: -
  • Smaller size
  • Longer battery life and/or smaller battery
  • Add voltage divider to monitor actual battery voltage
  • Have a dual supply solution to use 1.5V AA cell with booster or single 3.6V Lipo cell without booster
  • Learn about ESP-NOW
There are plenty of clever people out there on YouTube with some great ideas around home automation and using the ESP8266 and ESP32 so time to watch some videos.

Gerbers, STL files etc. available from here https://1drv.ms/u/s!AkqVSEM4Y7kDhuZ0Lg1CdJrBs745Ug?e=ACkTkJ

The code for the device is available from MakerMeik's GIThub page, watch his video.

Version 2 coming soon .......




Sunday, 14 May 2017

Hot water control using a Raspberry Pi Zero W


Following on from the first blog about the hot water heating control here's what I put together for the mounting.
Whilst looking for a suitable enclosure I came across an surface mount electrical socket back-box and I got to thinking "how can I mount the RPi W and relay in this?" so after some head scratching I thought about 3D printing some carriers to go inside the back-box.
The picture above shows two carriers printed to support the RPi and the relay board.

Then I made the required entry holes in the back-box for the power cable (USB), the mains switching cable for the relay and the temperature sensor cable.

This contraption has been sitting on my desk for a few weeks running quite happily and I've been checking the event log to make sure it's been switching on and off when it should.

Next to interface it to the existing wiring.

Saturday, 11 March 2017

Hot water Remote Control using a Wemos D1 .... then a Raspberry Pi Zero W

For quite a while now I've been meaning to put together a project to control the Hot water heating remotely from my phone, I all ready have a 2nd generation Nest to control the heating but don't fancy spending the money for the 3rd generation just to add the water heating function.
I started with the plan to use a Wemos D1 Mini with a couple of the plug-in modules like a relay module, processor module and a button module all placed on the dual base PCB.


Button Module

Processor Module
Relay Module


Dual footprint Motherboard
For those of you not familiar with the Wemos D1 you have to be aware of which pins the different modules use because the relay module uses D1 which also happens to be used for one the I2C pins so if you wanted to use the I2C OLED display module it would clash.  I decided to re-wire my relay pin to use D6 (GPIO12) as this is the default pin that the Sonoff / arendst software uses for the relay anyway.

Once the parts were assembled and the software flashed (the button module happens to be the flash button as well)

The idea was to load some software written by a chap called arendst on Github this software allows you to control a relay via MQTT, usually used in WiFi controlled power sockets found at ITEAD but there's no reason why it can't be used on any ESP8266 to drive a relay and more importantly read a connected temperature sensor like a DHT22 or DS18B20.

I planned to control this from my Raspberry Pi 3 running Node Red, I would design a control layout using the Dashboard module, which serves up a webpage I can view on my phone/PC/tablet etc. inside my WiFi network.
Work in progress Dashboard UI in Node Red

 but could also be controlled outside my network using an MQTT app on my phone via the Cloudmqtt service using 4G data.

I also got hold of an Amazon DASH Button which I've configured using a node "node-dash-button", I've configured it so that pressing this button gives a 30 min boost to the Hot Water.

I tried several MQTT apps and found the one I liked the most was MQTT dash it let me create quite a nice interface.
Sample layout for MQTT Dash
Another one I liked was MQTT Dashboard because this has widgets that you can have on you phone desktop to switch something on or off  without opening the app first (Android only, I think).

So all was going well and starting to work when I saw that the lovely people that make the Raspberry Pis had just launched a new version of the Pi Zero, this time with WiFi and Bluetooth included and it was just under £10 .....Whoa! .... hold on a minute! under a tenner! .... I'm quite prepared to use a Pi Zero W instead of a Wemos D1 mini and shut it in the airing cupboard controlling the hot water.

The Pi Zero isn't very fast but I was certain it was plenty fast enough to control one relay and read the temperature using a DS18B20.

So I changed plans at this point a turned toward the Pi Zero W, if you want to use an ESP8266 then go over to Github and use arendst's code (I use it on 3 Sonoffs) and make it happen.

I will put together a blog entry for the Pi Zero W in a few days, I'm just sorting out the housing and wiring to put it in the airing cupboard.

As usual if there are any questions just ask them in the comments and I'll do my best to answer them.



Sunday, 15 January 2017

DIY Chrono Mark II

Well it's been a long time since I started off this project and I've made a few changes along the way and a few people have had a go at making their own Chronos based on the entries in this blog, some followed the design and some incorporated elements of their own into the design to improve it.
Chrono Mark II Assembled
There were a couple of the things I wasn't keen on with my design: -
  • The fact that it was not a round tube but a teardrop and therefore may not always line up with the rifle and look a bit odd.
  • An external charger circuit was required to charge the internal battery.
  • The switch was mounted at the other end of the tube from the electronics and was a bit of a pain to wire up and assemble.
So along came the Mark II with the intention of improving on those issues.

The main reason for the teardrop design was to fit in the electronic modules with the central tube so I needed to come up with a design where I could place the modules and battery around the perimeter of the tube whilst keeping the overall diameter as small as possible.

I also wanted to add a charging circuit inside the tube so there was only one part to worry about so you could just plug it into a phone charger to charge it.  If I could get all this inside the tube, along with a switch located at the same end as the electronics then it would be a big improvement IMO.

First test was putting the modules around the tube .... using Tinkercad I messed around with all the modules trying to fit them in.


Having got them to all fit in a round base I set about figuring out the charging the battery and powering the Nano from the 3.6V battery as the IR receivers were specified to use 5V.

After a good Googling around for some modules I finally found some modules that fit the bill, one to convert 3.6V to 5V and another to charge a single lithium cell from 5V.  These module need to be pretty small and I wanted them to be on a single PCB to make wiring up the modules easy so I designed a PCB to mount them on and had the idea to attach the PCB to the switch which would be securely screwed in to the base.
Power PCB Circuit

Design layout
Final PCB
The outcome for this design means that when switched on the 3.6V battery is connected to the DC/DC converter supplying 5V to the Nano, BT module and the IR beams, when switched off the battery changes to the output of the single cell charger module, which gets it's 5V supply from the nano USB connector therefore charging the battery.  Also all the supply connections for the modules are also on the PCB making it easier to wire up when assembling.

Some More Images


 

Things you'll need
 Item Link  Cost 
 Pololu 5V Step-Up Voltage Regulator U3V12F5 Link  £3.32
 DD08CRMA Mini 5V 1A Lithium LiPo Charger Module eBay Link  £1.97
 Mini Miniature On/On 6 Pin Slide Switch DPDT eBay Search Link  ~£0.40 ea.
 Power PCB gerber files Link  £0.00
3D Print files for carrier and tube Link £0.00







Monday, 6 June 2016

New Android app for the Chrony F1

I recently bought a damaged Chrony F1 from a chap that had accidentally shot it, it never ceases to amaze me how companies can design and sell things that by design you shoot at and not put adequate protection in front of the delicate electronics.

The front casing had been hit and had a large dent in it that cracked the LCD and dented the crystal body, after a suggestion from John on the Facebook group "SHOOTING CHRONOGRAPHS U.K." I looked at Radio spares for a replacement and bought this screen 184-7715, it worked like a charm and after a bit of panel beating and a lick of Hammerite Dark Green paint it looked as good as new.
Before and after
One other thing I did before shooting at it was to buy some 10mm Acrylic sheet from eBay to make some clear shields to protect the display and the rear sensor block.

So when I started to use it I realised that I'd have to write down the readings and calculate the power myself later ..... s*d that! surely there's an app for that, if not I'll write one.

So I created an app to record the readings after each shot with the option to speak the value if you prefer and automatically calculate the power using the pellet weight you entered.

I also learned of a secondary Android market called Aptoide, to which I added some of my apps so they can be downloaded from one place.

The link to my store is http://gadjetware.store.aptoide.com/ there are other apps there as well, if you think it's worth it buy me a beer using the beer icon :-) and I might add more features.

I found the serial communication protocol for the Chrony F1 and when I get a chance I'm going to look into adding the Chrony remote functionality to my PC software and maybe make a Bluetooth interface so your phone can talk to it.

DIY Chronograph Accuracy testing

A few people have attempted the DIY chronograph build, at least one person improved the design and made an excellent version of his own.

I had a a question asked about the accuracy of the chronograph so I setup some testing over the weekend to try and determine if it was as accurate as others out there.

I don't have access to a calibrated air rifle or similar, if something like that even exists?? so I decided to use a good quality Oscilloscope (Picoscope automotive), which connected to my laptop via USB and do a comparison with the output from the Nano (in uSeconds).

For each measurement I took a screenshot of the waveform from the Oscilloscope and the serial data from the Nano, this shows the correlation between the actual time between the first beam being broken and the second.
There is also a google sheet showing the data that was recorded during the test here you can view the data and make your own decisions, for the last few shots I added a Chrony F1 about 3m away from the rifle to see what result that gave me.

The Chrony was set up in the garage with the lights off (florescent's) because the Chrony doesn't like florescent lights, instead I had a couple of cheap battery powered LED lights on top of the diffusers.

The conclusion is that although the data for each shot was different between the oscilloscope and Nano, over the 23 shots the average from both was exactly the same 10.57 ftLbs, this compares well to the 10.48 ftLbs when I had it checked at a shop a couple of years ago.

So I'm happy to use my DIY chrono with the understanding that there's always margin for variation and if I was getting 11.9 ftLbs that would be too close for comfort but 11.5 would give me 4% 'ish headroom.

Thursday, 19 May 2016

Updated PC software for the DIY Chrono (and Combro)

Just a quick update for anyone that has tried the PC software application for my DIY Chrono before, I've re-worked it a bit and changed the layout and moved the settings to a separate screen.

Also now I've fixed the Combro option not working so it should now report the correct values, if not please let me know as I don't own a Combro ..... the whole point in making my own.

Some Screen shots ...

Main screen interface
The main screen shows all the shot details in FPS and M/S along with a min FPS, max FPS and a Delta FPS.
On the right there is a list that adds each shot's data to a row so you can see the history.
At the bottom is a chart section that, if the checkbox is checked, shows the data graphically, there is a tab for FPS and one for energy.
You can also select the option to store the shot data to a file on the PC, the path is set automatically but you can type in your own.  The data is stored as a CSV file and can be opened by excel and used to create a graph.

Settings screen
The settings screen is self explanatory, I hope, change the settings and they are stored for next time, the pellet data etc. is stored in the CSV file as well.  If you have a Combro then tick the checkbox and the software should work for you as well
Here you can set the PC to make a noise
You can set the PC to give you an audible warning every 'n' shots, this is good for knowing when you fired your last shot and you're not looking at the screen, the other check box resets the shot count after the beep.

You can download the file from here unpack the rar file and run the setup to install.

Comments and feedback always welcome and if you like buy me a pint with the donate button.

Door/Window Sensor with an ESP8266

It's been a long time since my last post but I thought I would write up about my latest project - a door/window sensor using an ESP 8266...

Popular Posts