11

(Marcin) #1

Alexa-controlled wheel of fortune


FORGE

void loop()
{
fauxmo.handle();
if (spinning){
delay(500+random(2500));
servo.write(90);
spinning=false;
}
}

The actual detection of the command to spin is
handled by a callback in the setup block. The code to
spin the wheel is also fairly straightforward. We just
start the servo spinning and set the spinning variable
to true. This way the servo will keep turning until it is
switched off.

void callback(uint8_t device_id, const char *
device_name, bool state)
{
if (state)
{
servo.write(0);
spinning = true;
}
}

ALEXA! SET UP MY CODE
We need to configure Alexa to work with our wheel
of fortune.
Make sure you have completed all the above steps,
uploaded the fortune wheel code to your ESP8266,
and that it is powered on. Using your Alexa app, go to
Smart Home in the menu, and click Add Device. The
device name you provided in your code should appear.
You should now be able to manually switch the device
on and off by clicking on it. The WeMo devices we

are emulating are typically appliance sockets or
lamps, so can turn both on and off. Our code
only needs to detect it turning on, but that does
mean you have to turn the device off first before
turning it on again. Don’t worry, we’ll hide all
this away in a routine in the next step.

CREATING A ROUTINE
The final stage is to automate the spinning in
Alexa. Go to Routines in the menu, and add a new
routine. You can get creative here. I used ‘spin the
wheel’ for voice prompt in the WHEN section. You
then have to turn on and turn off the device (fortune
in my case), and lastly you can get Alexa to say
something whilst spinning! I went with, “Where it
stops, nobody knows”.
All that is left is to test and spin. I came up with a
game with my daughter where we both spun it three
times and then used our imagination to come up with
a fortune from the three words chosen. Just hope
you don’t get ‘DOOM’ three times...

Left
Reverse of wheel,
showing servo horn
glued in place

TAKING IT FURTHER


One thing missing from our design is the classic
clicker sound of wheels of fortune. You could put a pin
in each section and have a clacker mounted on the
edge that hits each of these in turn.

There is a handy
guide to the
ESP8266 pins
at: hsmag.cc/
YAJOAW

QUICK TIP


Below
Adding the device
in Alexa (left)
and creating the
routine (right)
Free download pdf