Alexa Controlled Solenoid Using WEMO D1 Mini
by gluckc in Circuits > Electronics
9338 Views, 11 Favorites, 0 Comments
Alexa Controlled Solenoid Using WEMO D1 Mini
It really is amazing. It's not that hard to have an alexa echo control a micro-processor. The world is your oyster. This instructable takes you through the steps to control a solenoid. You can use this same process to control whatever you want. In my case, I used the solenoid to push an elevator button. I made two of these, one for the upstairs elevator button, and one for the downstairs elevator button.
Get Your Parts
Ingredients:
WEMO D1 mini -- Be careful not to get the WEMO D1 mini LITE. I accidentally did this thinking I was saving money, but it didn't work correctly.
L293D -- A relay is typically used, but I had a bunch of these laying around, and they worked.
Female Pin Headers -- optional
wires
9V Battery
Mix It Together
I soldered this together on the perfboard. This particular board is nice because it is laid out like a breadboard with rails and sets of holes that are connected.
First, I soldered female headers onto the perfboard for the WEMO to plug into. Originally, I also soldered female headers for the L293D to plug into. However, I discovered, that the L293D does not plug into the headers with a good connection, so I soldered it directly onto the board.
Then I soldered wires to to the board to make connections:
1. Red wire from WEMO 5V to L293D Enable pin
2. Black wire from WEMO ground to L293D ground pin (5)
3. Yellow wire from WEMO D1 pin to L293D input2 pin (7)
4. battery cap wires - black to WEMO ground, red to L293D Vs pin (8)
5. solenoid wires -- black to WEMO ground, any color to L293D output2 pin (6) -- NOTE: I used wire with a 2-pin female connection at the end. I can plug the solenoid into this. I soldered male pins to the end of each solenoid wire.
There was no reason that I connected to Input/Output 2, I could have done Input/Output 1. In fact, I could have controlled 4 solenoids instead of just the one, but one was all I needed for this project.
Code
You can use the Arduino IDE to program the WEMO.
There are some steps to get the WEMO working with the arduino IDE, and you can follow them in this excellent instructable...https://www.instructables.com/id/Wemos-ESP8266-Get...
Next, you have to get the WEMO working with the Echo...
The reason for the WEMO is that it is WIFI enabled - and, you can use some easily available code to make it behave like a wemo belkin switch. This is an easy way to interface it with the amazon echo.
First, go to:
https://github.com/kakopappa/arduino-esp8266-alexa... and download the belkin simulation code. Put this code where all your other arduino projects are located. Then bring up the wemos.ino file in the arduino ide. The only file that needs to be modified is the wemos.ino file. Basically, all you need to do in this file is:
1. Set your SSID and password to your wifi
2. Define your switch; (Switch *kitchen = NULL;)
3. Initialize your switch; (kitchen = new Switch("kitchen lights", 81, kitchenLightsOn, kitchenLightsOff); upnpBroadcastResponder.addDevice(*kitchen); )
4. Add to Loop section; (kitchen->serverLoop(); )
5. Make your callback for both On and Off and put whatever you want in the callback: bool kitchenLightsOn() { Serial.println("Switch 2 turn on ..."); isKitchenLightstsOn = true; return isKitchenLightstsOn; }
You'll see all this in the sample wemos.ino code. Just replace the Switch-es in that file with whatever you want to make a switch. In my case, I renamed everything "BasementButton". My basementButtonOn() callback changes pin D1 to HIGH. See the code I included as an example.
Downloads
Application
In my case, I wanted the solenoid to push an elevator button. To do this, I needed some kind of bracket to hold the solenoid over the elevator button. So, this is my first foray into the 3D printer world. I went to tinkercad.com and made an account. You can use their tool to build 3D designs in the cloud and then export your design to a *.stl file which can be printed out. I found tinkercad to be very intuitive to use. You drag shapes into the drawing area to build the design you want. When you first set up your account, it has a very good tutorial to get you started. It just gets a little trickier when you need to make sure it has the correct dimensions.
I was able to print the bracket out through the kindness of a friend who has a 3D printer. But there are various companies that can do it for you, too. Some libraries will even do it.
Downloads
Put It Together and Done
I mounted the bracket/solenoid over the elevator button and put the WEMO in a plastic box on top of the button. After uploading the code to the WEMO, you have to get Alexa to discover it. Just say "Alexa find devices". Once she finds it you can say "Alexa turn on DEVICENAME" or "Alexa turn off DEVICENAME". This activates the callback into the code and turns on the solenoid. In my case, I have a "elevator up" device and a "basement button" device. It's a little wordy, but it works. Also, it doesn't entirely make sense to "turn on" and "turn off", but I'm not sure that it can be changed.