Since my last post about IoT, I have been looking for other ways to use the ESP8266 WiFi module with Arduino. When I visited Berlin last year I encountered abundances of two products in particular inside every souvenir shop I went inside of. This limited my attempts at purchasing a unique gift for my partner. So, between “Ampelmann” badges or reflective tags and dancing solar bears, the bear definitely won.
The novelty quickly wore off upon my return however, as the bear seemed to act as a makeshift alarm making loud plastic ticking noises at the inkling of any light whatsoever. This did mean it was moved somewhere out of the light and was forgotten about until I thought: “I bet I could control that through the internet”, apparently what I now think about most things.
How It Worked
I started by removing the bottom panel from the bear, this revealed the inner workings of what made such an “exciting” souvenir. The circuitry used a capacitor, a solar panel and some really thin copper wire arranged in a wheel-like shape. The current from the panel would go straight into the capacitor storing some charge (I guess to give it a sort of start-up/shut-down spool of charge) which then goes into the copper wire generating a magnetic field. The bottom of the bear on the inside has a magnet on it which is then pushed away from the aforementioned field giving you the “dance”.
How I Made It Work
Altering the Circuit
To control the bear, the first thing I had to do was change out the solar panel. This was soldered to the positive and negative terminals of the capacitor however so I had to break out my soldering iron. I desoldered the panel and then soldered two respectively colored M-M jumper wires in its place. Once the solder had set I put the circuit back, but of course it isn’t as flush as before because now there are two wires jutting out the base of the unit.
Secondly, I wired the positive wire (Red) to the output pin 5 (PWM), the negative one (Black) to ground in conjunction with a resistor so as to not destroy the capacitor inside the bear (I was not sure how much it could take). I wrote some code in the Arduino IDE to test everything by setting pin 5 as digital output and setting it HIGH and LOW. There is a slight delay on startup and shutdown of the bears dancing due to the capacitor storing the charge, but other than that it worked!
To get the bear to dance and stop dancing via HTTP GET requests I also wired up the ESP8266 module and wrote some code to allow it to interpret two requests. GET /B1 to start the bear dancing and GET /B0 to stop it. It works by using the HIGH/LOW voltage levels to the pin as talked about above. Next I cloned my IoT app and API repositories talked about in my other post. Two new endpoints were added to the API as a proxy that called the ESP8266 called BearOn() and BearOff(). I modified the mobile app and added a “bear” page that makes API calls to the aforementioned proxy endpoints via button presses (above).
The result works well, but there are ways it could be improved. For example, I could utilize the native accelerometer API with Ionic to make the bear dance when the phone is shaken. Maybe even create an Alexa skill to make it dance, or wire in a sound sensor to make the bear dance when it “hears” sounds.