Alexa Controlled Servo

14K5828

Intro: Alexa Controlled Servo

Introduction
I have a laptop on a shelf in my office that monitors several cameras that are around the outside of my house. They alert me to deliveries and visitors. While I can use a web browser to see their images it is easier to just glance at the screen on the laptop from time-to-time to see what's up.

Unfortunately the laptop's screen saver cuts in after 30 minutes and blanks the screen. That forces me stop what I am doing and press the space bar or shift key to bring the screen back.

Having a voice activated Alexa controlled "finger" that could touch a key on the keyboard is surely not the simplest solution but it sounded like a fun project. This servo device places a movable arm just above a key on the keyboard. The statement "Alexa turn on keyboard" cycles the servo arm, pressing down on the shift key & renewing the screen - nice!

The application presented here is just one way that the servo can be used. Other applications include throwing a wall switch that turns lights on/off or moving some other device, perhaps a latch on a door or cabinet. If you come up with other applications please drop me an email and let me know (dave@davebodnar.com).

STEP 1: Video


There is a YouTube video here that gives an overview of this project

STEP 2: Hardware

  • Wemos D1 - from BangGood and Amazon.
  • micro servo - Amazon and BangGood
  • 3300 uf, 6.3 volt electrolytic capacitor - eBay or junk box - any fairly high capacity capacitor should work (see notes in article)

STEP 3: The Clamp

The "clamp" that holds it all together is shown here. The servo goes in the upper right and the Wemos goes into the holes to the left. The large tapered slot holds it to the side of the laptop. You will need to be changed the dimensions of that slot to fit your laptop. The links here are for a PDF or CorelDraw version of this clamp. The sixteen small holes for the Wemos are not electrically connected to anything - the are just there to help hold the controller in place.

STEP 4: Putting It Together

The parts that I used are listed above and shown here.

STEP 5: Connections

All of the connections are made by soldering right to the Wemos D1. The capacitor and 5 volt power connecting go to the 5v and G pins. The servo also connects to these pins for power. The servo's data line (the white wire in this photo) goes to pin D5. Those are the only connections that are needed. Power can be supplied from an external 5 volt power supply or, as in this case, by a USB cable plugged into the laptop. The 3300 uf capacitor was added when the Wemos crashed periodically, probably due to variations in the supply voltage. Since the cap was added the unit has been very stable. Other electrolytic caps of 1000 uf or more should work.

STEP 6: Attach to Laptop

Here the Wemos & servo are mounted and the acrylic clamp has been placed on the keyboard.

STEP 7: Using With Alexa

After programming with the code in this ZIP file (be sure to change the SSID and password to match your system) I told Alexa to discover devices. In a minute or so she reported that she had found a new device called keyboard. Once that is set the servo can be activated by saying "Alexa turn on keyboard" - note that there is no need to say "Alexa turn OFF keyboard" as the servo arm returns to the off position after pressing a key.

STEP 8: Software Notes

If you want to change the name that Alexa uses with this device from "keyboard" to something else you need to change the word "keyboard" to your word in a number of places. To simplify this I just changed ALL instances of "keyboard" to the new word using the search and replace function (edit / find).

The code includes a routine that blinks the on-board LED on the Wemos every second. This was added to give the controller a "heart beat" during testing. If you find it unnecessary or distracting it can be deleted.

Note that a number of libraries must be added to your Arduino IDE for this sketch to compile - They are at the top of the listing in the "#include" statements. You also have to add the Wemos to the IDE (see: https://www.instructables.com/id/Wemos-ESP8266-Get... )

STEP 9: Other Uses

The servo can be used to move other things as well. Thingiverse.com has several designs for a servo operated light switch including this one that can be 3D printed: https://www.thingiverse.com/thing:1156995/#comments

25 Comments

Hi, i am using a Nano33iot for the same kind of project. What do i have to change in this code to make it work.
Hi, i´ve built this all, even when i run the code and check it in the serial monitor it says:"Connected to WiFi". But i cannot discover the device in alexa app. Can anyone help?
i got the same problem and i found that first we have to enable wemo skill in alexa app.
but in my alexa app its not showing.you can try this if its there.
if you got any another way plz inform me
As I noted all I had to do was say "Alexa discover devices" and "keyboard" was found - not sure what may up with your implementation.
Keep at it and I am sure you will get it!
dave
This is not a question but to let you know that one of those blinking LED's with built in blink circuit and resistor for 5v works great for keeping computer alive. Put it in a box with led barely sticking out and set mouse on top of it centered with mouse's LED. The mouse curser will start moving over to side and stay there and computer will not go to screen saver or asleep.
I didn't know that would work but it makes sense - I could have set the laptop to never blank the screen, too, but wanted it to sleep when I wasn't in my office.
thanks for the info
dave
To those that can't discover their device with Alexa:
As I mentioned in reply to a comment
below, the method used here no longer works with Alexa. To discover devices with Alexa now, you need to use a Smart Home skill. I used Sinric (instructions here: https://github.com/kakopappa/sinric ) , and changed their example code to control the servo as done here. Feel free to use this code. You'll need to add in your API key, Wifi SSID and password, and device ID.

https://github.com/Felandric/WemosServoSinric
Does anyone try with Alexa echo dot 3rd generation? Alexa does not find the device
I cannot thank you enough for this code. Thumbs up all around!

How do you download all the missing libraries. I really don't know what I'm doing, here's the error message. Plz help:

Arduino: 1.8.5 (Windows 10), Board: "LOLIN(WEMOS) D1 R2 & mini, 80 MHz, Flash, 4M (1M SPIFFS), v2 Lower Memory, Disabled, None, Only Sketch, 921600"

Build options changed, rebuilding all

C:\Users\Bhanger Bhanger\AppData\Local\Temp\Rar$DIa0.713\Wemos-Servo-keyboard\Wemos-Servo-keyboard.ino:22:20: fatal error: switch.h: No such file or directory

#include "switch.h"

^

compilation terminated.

Multiple libraries were found for "Servo.h"

Used: C:\Users\Bhanger Bhanger\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.2\libraries\Servo

Not used: C:\Program Files (x86)\Arduino\libraries\Servo

exit status 1

Error compiling for board LOLIN(WEMOS) D1 R2 & mini.

This report would have more information with

"Show verbose output during compilation"

option enabled in File -> Preferences.

Thanks for your help--

I was able to take your instructable and morph it to do what I needed. I was very excited to discover this :)

That is great news - thanks for letting me know

dave

This is exactly what I want to do, but with a solenoid. It seems pretty easy. I just wish your Step 7 "After programming with the code" was expanded :). You have several .cpp files included. How do you get these on the wemo? Is it possible to just copy/paste the routines in these files directly in the .ino? In my limited experience, I've only programmed through the *.ino file.

Sorry for any confusion - to use the files first download the ZIP file and extract it to some convenient place on your PC

You should see a set of files that looks like the attached photo

When you open the

Wemos-Servo-keyboard.ino

file you should see the associated files displayed at the top as taps

hope that helps

dave

Why did you use GPIO14 for the servo? I'm starting on this exact circuit for another project and was going to try GPIO2 so it's closer to power.

No particular reason - the sketch should work on any of the other GPIO pins

dave

I have reprogrammed mine with separate On/Off and a hardware push button. However, there seems to be an issue when opening the Alexa app. If the device is open in Alexa, it constantly cycles on and off. I can't find out why in the code. Is there a way to make it work with the app correctly?

More Comments