This is one of those things that starts out as ridiculous but just might work. We’re putting in a door at our hackerspace, a pocket door, so obviously it has to be pneumatic. I was asked how to control this door, and I had one answer: Star Trek Electronic Door Chime Think Geek wants $30, Ebay wants $28, the cheapest is Amazon at $25 and free shipping. I ordered one right away with the intention of converting it for use as our door controller.
I knew I would have to do three things:
Let’s investigate the guts.
Unfortunately I did not take a picture before tearing into it, so here’s my recreation. Top left, board with a single LED. Below that is a board with a single membrane switch and that passes through the LED wires. To the far left are two PIR sensors. Out the bottom is the connection to the battery box. The right side has the speaker and volume switch. The top right has the front slider switch. The middle of the board has the switch to select which PIR sensor will activate the sound.
I didn’t really go into this with a plan, but step by step I made this sound board sing and dance. The first thing was to pin out the PIR sensors:
d1=orange=normally open (3.61v)
g1=green=normally closed (0v)
d2=purple=normally open (3.61v)
g2=grey=normally closed (0v)
That’s that. I found that I could replace one with a microswitch and activate the circuit, perfect! I had to tweak the timings once I got it hooked into the microcontroller but I could control them digitally, good enough!
Next was the front switch board:
That’s fortunate, there’s one common and three different things to be pulled down in succession. I decided to use the trick of defining a pin as an input to make it floating, which worked great. For inputs I used three separate pins with pullups to detect which was being pulled low.
Last was the LED and button boards:
1=led positive (4.4v, floating battery)
2=led ground (current limiting resistor inline, switched)
resistor removed and shorted over
1 – 6
2 – 3
4 – 5 button
5=4.38v (floating input)
The decode here is that the LED gets tied high, there is a SMT resistor on the main board, and the ground is switched. The button is on pin 5 and pin 4 is ground, so all I have to do is pull that low to activate it with a microcontroller. I really don’t like how that LED is wired so I removed the resistor on the board, jumpered over it, and wired the switched pin (3 on the board) to an input on the microcontroller (pulled up). I then wired the LED to ground and one of my GPIO through a 100 ohm resistor I added. The button also got wired to me as an input.
Here’s the story so far:
In this configuration I could essentially man-in-the-middle the entire board, but I had one limitation. The red alert is supposed to be a burglar alarm for a cubicle (just like the hail is supposed to be a doorbell) and thus cannot be stopped mid cycle. I decided the best way to fix this was to wire a couple of transistors so that I could drop power to the whole board and thus kill any sound mid-play. This is a very crude solution, but seeing as my music box is literally 2 epoxy blob chips, I’m going to just call this good enough as well.
Now I have even more control over the board than I did to start with, I have written code that would simulate an unmodified board (no PIR though) and augment it with the ability to interrupt the sound being played. If you really really wanted to you could take the PIR sensor in as analog and output it as PWM and maybe it would work. I didn’t bother because this device has 2 PIR sensors and a switch on the back to choose between left, right, or both to activate the sound. If you want a PIR sensor, just leave one in and connect the arduino in place of the other. You can even switch between them to preserve as much original functionality as possible.
Somewhere along the line I thought I broke my code for simulating the PIR sensor (spoiler: don’t #define the same variable twice and expect it to work). My remedy for this was to look into the TM2291 chip connected to the horrorshow of capacitors and resistors. This chip turned out to be a dedicated PIR sensor reader chip. Most of you won’t have ever dealt with this because you but modules that have something that does this onboard, but this device had 2 PIR sensors MUXed into one driver chip… I did not want to decode that. I found an example circuit and picked the pin I thought must be the output to the sound chip. After I desoldered the chip and connected in place of it everything worked (no it didn’t. but it was around this time I found my code bug). Now I could also be rid of that switch on the back of the PCB.
With the switch desoldered I had room to just about fit my FTDI header out the back. One important thing: the RAW and the Vin on the FTDI header are not as connected as you might think, which led to some head scratching from me. Here is the final layout as I have it now.
The diode is so the batteries don’t get charged from the ftdi header (but it can still power the unit). The switch at the top is mine for triggering things instead of the PIR (glued where the PIR was). You can see the NPN/PNP circuit I mentioned before to kill power to the board (and the power for that coming from the FTDI input, not any other pin on the pro mini). The LED has a new resistor, and the button boards now go to the pro mini. The arduino has a bunch of control lines running to the original board, but the volume switch was left alone. This literally shorts out a series resistor with the speaker, I didn’t think it was important to make that variable. You can see how I now have central control of all the inputs and outputs, which was the plan all along.
The code I think this will be running in production is the command based one I uploaded here. It’s overly modularized, but it works well. Another hint: 8Mhz does not divide equally to give close enough to 115200 baud for input, even though the output comes through readable. That’s a fuckin’ pain to diagnose. I used 9600 this one time, as you can see. My functions:
WOOSH does exactly that, plays that sound.
ALERT does the same as WOOSH, except it will be left in alert mode so the LED will blink
HAIL plays the hail sound
NONE sets the virtual switch to no sound, but can be used to cancel the blinking without playing a sound
KILL kills the current playing audio
ON turns the LED on
OFF turns the LED off
PASS passes through the LED state from the board, useful in alert standby mode or to see the blinking while playing the red alert sound
BLINK sets the board to red alert mode, does not trigger sound, LED blinks slowly
SWITCH returns the state of the front switch (0, 1, or 2)
The button on the front and the new button on the side asynchronously send 3 or 4 out serial, but they are debounced and only do it once per press.
That’s it, I’m done, it works. I anticipate this (maybe two) being serially linked to an ESP8266 (it wants 4.5 to 5v power, but 3.3v serial is fine) which will run the solenoids, read pressures, and talk MQTT. If I’m really hurting for pins I can make the second one respond to different commands, make it talk different numbers, and hook them in parallel with a couple diodes, but that’s silly…
the code is here.
the rest of the pictures are here.