This is a great little project, its been a few years in the making, because i had a bunch of other projects which have kind of turned into this project, and this is one kind of microcontroller switch to be able to turn a switch um trigger a relay Turn something on by paying with bitcoin, and then you can also change the amount of time that thing has been turned on for say. If youre, you know turning on the motor on the sweep machine, you want the switch to come out and then, if youre, using for an arcade, you only want it for a fraction of a second, very cheap, very easy im going to show you how i wired Up these three separate devices, because its very simple um, firstly, youll need a esp32 board. My little collection of esp32 boards is just scratching the surface. All of these have the exact same microcontroller in the sp 32 weve got a simple development board here, theyre about three quid each thats, the note 32s heres, another one, and then we have something kind of in between which is the t displayed by lilligo comes with A little screen old, lipo battery jst connector, but the important point is these: are all the sp32 based boards and we can use all of them with bitcoin switch and theres plenty more out there for whatever need. You might need the microcontroller to have for turning our thing on from our esp32 microcontroller.

I recommend one of these little five volt relays for most applications. You can get different size ones, so you can get like a 240 volt relay as well, so youll be able to turn on um mains electric if you want, but obviously thats a little bit riskier and you can get 24 volt ones as well for for different Power requirements, but the basic setups, the same and all of these mechanical relays, you buy theyre very cheap. This is on amazon, so if you buy them from aliexpress or something you can get them for like a dollar each. You have these like three terminals here and then, when the relay is powered on theres, a bridge connection made between uh the one on the left, the one on the right. I think in this case. So if, as long as you plug something in to these two terminals, um in line with it, then when the relay turns on it will switch that thing on and then on the back youve got these three gpio pins. One is a signal. Pin you just about see the s theyre poking through for the signal pin, so i think thats, the one on the left or sorry the one on the right and then i think the one in the middle is probably the positive pin and then the one on The end is a negative pin, but thats all clearly marked out on the actual relay itself um, so we just plug.

I tend to use the the 3.3 volt gpio pin out from the 32s to um the power pin, even though this is technically a five volt relay, but you can also plug it into the five volt of the esp32 um. And then you just click plug in the ground wire from the sp32 to the positive to the negative here and then um plug in the signal pin, whichever signal pin you or youre using or youve selected in your portal. So for the suite machine, i cut away the base of the machine that gave me a nice cavity to put my micro controller in i had to remove some of the plastic from the housing of the batteries. I was then able to make use of the switch which actually came with the suite machine and cut the negative wire of my thousand milliamp hour lipo battery and put that switch in line with it. So it can turn the esp32 and the suite machine on and off the esp32. This t display model comes with a jst 1.25 millimeter connector, which means i can put my battery in. I also have a power and a negative positive wire going through the suite machine to power my motor and then i have three wires which are to power the relay. So we have a signal, pin wire um, we have a ground wire and then a power wire, and then the signal pin is connected to pin 27.

I was also able to make a little notch in the suite machine which meant that the usb c wire could just slot in and we could power it from usbc. So i removed the housing which protects the electronics from the suites in the suite machine and its quite tight in here, because i pulled the wires through to the microcontroller. We have a motor on one side, a little 5 volt motor 3.3 volt, i think, is, and on the other side i actually took away the board which the suite machine came with and just replaced it with our relay. It has the three jump cables going into the three pins in the relay and then on the other side. I have screwed in the positive wire for the motor um and thats uh, so the switch the relay switch needs to be on in order for that positive wire to be bridged and then for the motor to turn on spit out the suites and then on the Back weve got our three pins, weve got our signal, pin and then weve got our power and our negative pin on the relay itself. So for the claw game – and this is incredibly cheap – this core game – i think it was like seven quid or something from amazon. I removed the uh two couple of screws on the back on the bottom of the housing. Now this claw game can be battery operated with regular, normal uh batteries, but then it could also be plugged in with a wire or you could even plug a little hybrid battery into it opened up.

And then it comes with quite an accessible little board, which you can plug our electronics into theres, two diodes, which are actually the switch on the front of the machine. So we can tap into these two diodes and then, if we make a bridger connection, it will register as a click on the switch which then turns on the claw game. So the relay is connected to the esp32 and then the sp 32 is actually connected to this power line here, and i was able to get a nice five volt power source off this back power light, which also means you can plug the machine in with its Power, cable or you can use the batteries to power. It um again having three wires going to the relay the signal, the positive, the negative and then here we have our capacitance pin, which is plugged into gpio pin four, and that means when the esp32 turns on. If i touch that capacitance pin, it will trigger the access port. This pandora box, rk machine was really simple. To set up. Ive got the m5 stack on top of the machine and then theres just a little hole drilled for the three wires to be threaded through the signal wire, the ground wire and the positive wire and theyre going to connect to that little five volt relay inside the Machine we open it up and we can see those three wires connecting straight to that relay, which is then replaced the the coin button which is included on these machines, which you press to get a credit.

So, instead of being able to press that button, you have to pay a lightning invoice and it acts as a button and then just gives you a credit. I was also able to power it from the back of the pandora box, so its basically just a case of getting three little jumper cables, which are these things and then plugging them into your esp32 board and then plugging them into the little relay the three pins. On the back of the little relay then flashing it with the software and then once its flashed, you need to flash it once because we have a really nice access portal, which we can actually use, which you can see here in this gif. We can actually use to upload our credentials onto the onto the esp32. We have instructions for installing the arduino ide and then also um opening up the project then download this repo. So, however, you want to do that if you know git clone it. If you dont know how to clone something clone a repo, you can literally just click on this thing and then download, zip and then once its done downloaded. If you open it up inside here, there will be a folder called libraries there isnt currently because havent uploaded them, but there will be a folder called libraries, take those libraries and then stick it in your arduino install libraries folder. So when you install the arduino ide youll notice that in your home directory you get a little folder called arduino click on that and theres a folder called libraries put the libraries from this repo into there theyre all the libraries you need.

You can install them separately. If you want to, i just tend to package them with the project, because often these live boots will make some change and itll break one of my projects and its always quite annoying so now just package all the libraries in with the project um, which is fine, Because its all three open source, which we like so then open up, the bitcoin switch to ino file um, which is this one here, um and then once youve. So when you open that up, youll see like this code in your arduino ide, its all in one file um and its, how many lines have we got almost 700 lines of code to the top? Here we can see theres, actually, three variables, you can change. You dont have to change um, so if youre using the m5 stack, you need to set this to true and then it will make use of the screen on the m5 stack. If you want to format and just wipe all the memory from the esp32, then you can set that to true as well. Sometimes you need to do that if youve, like um, say if theres an update and then youll flash it and itll still keep the old data from which you put in. Maybe you want to update it so thats thats, quite a useful thing to have. You probably dont need to use it, but its there anyway, if youre not using an m5 stack.

The other esp32 boards dont have a button, but what they do have is these little gpios um, so a lot of them can sense capacitance. So you can set a pin, so on here is pin four, and actually that would work with this particular board, the lilly girl, and then we can put a um whereas pin for actually no it wouldnt work with the lilly guy. I think you need to use. Pin 27 or 25 on the little but anyway on one of the other boards. If its pin four, you can put in a little jumper cable like this and then when it turns on. If you press the end of this, then the gpio cans can measure that dropping capacitance and then we can use it as a switch so that triggers the access portal so im not using a m5 stack so im just going to set that to false um im. Going to be using gpio4, so thats correct, im going to make sure the right board is selected. Yes, it is im using the node 32s um, so thats selected and the port as well. The right port is selected and then once youve done, those things. Click on the all upload button, itll upload um. Quite often when you get the little dotty lines popping up as the project projects, uploading youll need to press the little reset pin on the esp32 in order for the project to be uploaded. If its one of these little development boards, if its an m5 stack or a lilly, go actually, it should just upload on its own press, the a button or press the little uh gpio, which you set so triggers trigger the access point and then insert your credentials.

You can get the credentials you need from your lm bits. Install so just make a new wallet. Every wallet has its own api keys. So we need the invoice api key which you can get from api info. You can also use the admin api key, but obviously thats not advised so make a note of that, and then youll also need because were going to use the static qr code. Youll need to go to extensions and then url pay and then create an l in your pay link, connect it to the wallet, add in the item, description and the amount of sats which the selling your pay is going to be for so 15 sats create the Pay link copy the allen, url and then save that for use with the access pool, go to your wi fi and trigger the access point sign into the device. Youll need to put a password, obviously ive already done that, so it remembers my um logging in then click on access, point, config and uh select your element, url pay and then put that in the l in your old pay field. This device always has already has some info is saved on it from the last time i flashed it and then the invoice key the device will need that to have permission to check the balance of the wallet where the payments are going into the pin to turn On, in this case, its pin 18 and then how long to turn the pin on for because this is a claw game um, we only need to turn on for half a second just to simulate the button being pressed and the amount of check for so were Going to check that wallet for to give a credit, so someone can use the claw game and then you need to connect the device to your wi fi, select your wi fi and then put in your passphrase, and then the device can connect to your wi fi.

If you are using that static, ln url pay, so you can have a static, qr code print it out and stick on the device and thats it good luck. This can be an extremely cheap project. You can get esp32s. While i mean the most basic version. You can get is like a couple of dollars or even a dollar um, but the little development boards are maybe three four dollars and then one of these little relays is like a dollar fifty fifty cents, something like that. So, for like less than five dollars, you can create a module which you can then retrofit. Anything which has a button turns the motor on turns the switch on anything which does that you can retrofit to accept lightning payments, um and then start experimenting with this amazing payments technology which weve got in the real material world. Its very satisfying good luck, hope you have fun and if you create anything or make anything, please tag me on twitter. If you, if you put on twitter or something and then i can, you know, collect some nice examples of this project being used in the world.

https://www.youtube.com/watch?v=FeoIwTjv3YM