The National Academy of Engineering lists personalized learning as one of its "Grand Engineering Challenges." Additionally, there is a lack of effective and engaging tools to educate adults and children on energy sources and usage.
It's not clear that it takes a large amount of effort to generate the electricity required to run our devices, so few people consider the choices they make when going about their daily lives or passing regulatory laws that govern millions. For instance, are people aware that a AA battery requires much more energy to be created than it actually consumes? Or how much power can be generated from a small solar panel?
How might we take that knowledge, turn it into an actionable practice to help ourselves and the planet, and practice it in a tangible and effective way?
The goal of the House Pet is to create a solar-powered house that teaches about energy usage through a playful, multi-sensory experience. It’s a “Tamagotchi," but with a physical body, intuitive voice interface, and important lessons to teach.
The House Pet contains a solar panel roof, onboard battery monitoring system, tank treads to drive around, an extensible Lego body, voice-controlled interface and screen (via an Alexa Show), and a variety of other sensors. A pet is the the perfect, intuitive way to teach lessons about energy and solar power. Everyone is used to interacting with their own pets with their voices, making the voice interaction automatically intuitive.
House Pet owners will need to tend to their pets. Taking the pet outside when it needs to charge and checking in on it regularly to ensure that it is healthy. House Pet should be a fun way for everyone to conceptualize how much work it actually is to maintain energy for all of our devices and activities in our daily lives.
Here is an overview of the major parts of House Pet. I'll got into each part in more detail later.
The roof is a 10 Watt Solar Panel. This allows the House Pet to charge the batteries using the sun!
Custom Battery Pack with Telemetry Interface
I designed and built this custom battery system for the House Pet.
These treads allow House Pet to drive around!
Light Sensor on the Roof
The House Pet can detect how bright the sun is via the light sensor.
Touch Sensor Chimney
The House Pet will respond with affection when you pat the chimney :)
The House Pet will follow an infrared emitter as if it were a wireless leash.
Infrared Emitter “Leash”
Integrated Screen and Voice Control
The House Pet contains an Echo Show which adds Alexa Voice Control and a fun display.
Cloud Dashboard of Power Information via the Arduino IoT Cloud
House Pet can tell you how much power the solar panel is generating:
Using the Lego EV3 Remote as a wireless "leash", House Pet will follow you around. Just ask House Pet to "follow me".
House Pet can drive around in any direction via voice command:
House Pet can tell you what voltage the battery is at:
House Pet can inform you about the current power consumption:
House Pet has a screen thanks to the Echo Show embedded into its face. This is used to display information about House Pet's current status:
Even real pets love House Pet!
I wanted House Pet to have the following interactions:
- Follow me! using the IR beacon as a virtual leash
- Patting the House Pet on the head and having it acknowledge
- Ask the pet what its battery state of charge is
- Ask what the charge power is
- Ask how much power the pet is drawing
- Ask how much light is hitting your solar panels
I wanted House Pet to be really cute and fun. Like all great Lego creations, it started with a big pile of bricks.
Here is one of my concept drawings and form-factor prototypes:
I spent a long time making different form-factor prototypes. I wanted to be sure the sizing and looks was correct.
Here is a link to the complete Bill of Materials for House Pet. I've also added all of the major components to the parts list of this Hackster article.
Luckily I had a lot of these components before starting the project, so I saved quite a bit of cost for myself.
All of the Lego bricks used come from the kits linked above. It's certainly possible to substitute or change things depending on the bricks you have available.
What follows is a detailed description of how I built the House Pet.
I've attached a PDF that includes complete build instructions for the Lego portion of House Pet. Additionally, all of the code and documents can be found on Github, including the PDF instructions.
I modeled the solar panels as Lego sheets to make the rendering look nice, so just ignore that last step :).
There are a few extra steps outside of the PDF that I couldn't model in the Lego Studio software.
Echo Show Mounting
The Echo Show 5 sits easily on the little pedestal as show below:
Lego EV3 cables need to be routed to the two motors and the three sensors according to the block diagram:
I've attached some photos below of how I routed the cables. Also remember to install the WiFi adapter before closing everything up! You can see it inserted in the EV3 in the picture below.
The trickiest part is routing the cables to the motors, which are underneath the floor of the house; This is why the small gap is left in the house floor.
Attaching the Solar Panel
To secure the solar panel to House Pet, I used four small velcro squares.
This velcro allows the roof to be easily removable to place the electronics inside.
All source code can be found in the House Pet Github Repository.
The power system has a few major components:
- The solar panel
- The battery pack
- The battery telemetry interface via an Arduino MKR 1010
I'll go into the construction of each one in detail below.
It has a very easy USB output, doesn't require any additional control circuitry, and generally outputs most of the rated power. It's also really rugged in construction and folds nicely to form the roof of House Pet.
I trialed a great deal of solar panels (I returned the bad ones) to find one that would actually output anything close to the rated power output. If you ever mess around with solar panels, you'll find there is a great deal of marketing and misinformation in the industry.
Here are some pictures of my solar panel trials I did before settling on the Voltaic set.
I needed a battery pack with a telemetry interface that would show me the current state of charge, the power input, and the power output. I couldn't find any such battery pack off the shelf (if anyone knows of one I would greatly appreciate it). Additionally, I was on a bit of a time crunch for this project, so I didn't have time to do a fully custom battery pack with my own printed circuit boards and things.
So I tore apart an off-the-shelf USB battery bank and added some sense points to measure what I wanted.
Warning: Batteries are really tricky and they need to be handled very carefully. If you aren't extremely comfortable with a soldering iron and the basics of battery safety, I would not recommend replicating this battery pack modification.
Then I soldered sense points onto the main circuit board to sense the following data points.
Here's the finished soldering:
Finally I attached the Arduino described below to send this information to the Cloud and drive some fun Neo Pixel lights.
Battery Telemetry Interface
The battery pack above is combined with an Arduino MKR 1010 WiFi and an Adafruit ADC module. I also added a nice Adafruit NeoPixel Stick to change colors depending on if the power input / output ratio is positive or negative.
I've attached a Fritzing file that shows the connections for the Arduino Battery Monitor.
The resistor shown is a 470 Ohm current limiting resistor for the Neo Pixel data line.
In the future, I hope to collapse all this down into a single, integrated battery module that is much smaller, more rugged and has additional safety features.
For now it lives on the breadboard as show.
I soldered wires directly onto the Neo Pixel:
The battery / power system uses the Arduino IOT cloud to host a nice cloud dashboard of the relevant power information.
We will use the Arduino IoT API, which unfortunately requires a paid account, so make sure to sign up for the Maker account on this link.
Now that that's done, you can add your MKR WiFi 1010 board here.
Once you have added your board, take note of your board's "ID". We'll need to add that into our House Pet code later to poll the values.
We also need to note your API key for later. This can be found at the bottom of this page.
Now that you have your board associated with the Cloud, you'll need to add the following properties:
The property ID‘s for each of the four properties need to be updated in the House Pet python script.
Now, we just need to flash the Arduino MKR 1010 with the code provided on Github. The code can be found here.
I used the normal Arduino IDE to flash my code. The download and excellent tutorials can be found here if you aren't familiar with Arduino.
You'll need to install a few libraries including the ADS1115 library for the ADC, the Adafruit Neopixel library, and the EWMA library for the filter.
Testing the Electronics
Once you have all the electronics hooked up, it's best to test everything outside the House Pet, since there isn't much space inside.
Once you plug in the Arduino to the battery pack as shown in the block diagram, you should see it power on and be able to view the battery information in the Cloud Suite.
CreateAlexa Developer Account
In order for Alexa to understand what you are saying, you'll need to create an Amazon Developer account.
Stop once you have your Alexa ID and Gadget secret. Save this; you'll need it later in this tutorial.
Set up your Alexa Skill
You'll now need to create an Alexa skill to teach House pet how to listen and speak.
Go to the Alexa developer section and click "Create a skill".
Enter House Pet as the Skill Name, which is how you'll tell Alexa to open the House Pet.
Select "Custom" for the skill model:
and Alexa-Hosted (Node.js) at the bottom of the page:
Now click the Create button in the top right.
Now you'll see the Dashboard for your Alexa skill. Click on the JSON Editor option on the lefthand side of the screen:
This JSON file is what teaches Alexa how to listen to you :)
After uploading the JSON file, hit the Save Model and Build Model buttons in that order at the top of the screen:
Now select the Code button at the top of the screen:
This is the Node.js code that teaches Alexa how to interface with our Lego Intelligent brick.
Create a file called "common.js" by clicking the Create File button.
Now copy the contents of all four files from Github into the files in the Alexa Developer Consoler.
When you are done, click Save, and then Deploy in the top right.
Now your skill is live on Echo devices connected to your Amazon account. This means you can use House Pet with a real Echo device!!
Lego EV3 Intelligent Brick
You can stop once you see the EV3 connected in Visual Studio code and skip downloading the Alexa missions. We won't need those :)
Install Python Dependancies
Now that we have a connection to our Lego Brick, we need to install some Python dependancies. Open an ssh terminal to the Lego Brick by right-clicking on the EV3 brick in Visual Studio.
The password is "maker".
Run the following commands:
sudo apt update
sudo apt install python3-pip
sudo pip3 install arduino-iot-client
sudo pip3 install requests-oauthlib
This can take a while because House Pet's processor is pretty slow.
Configure the House Pet Code
You'll need to configure a few things:
You should have noted those in the earlier Amazon step of this tutorial.
amazonId = #FIXME
alexaGadgetSecret = #FIXME
Custom.Mindstorms.Gadget = 1.0
This tells the Lego Brick how to connect to your Alexa device.
Arduino API Information
We need to add some information to the Python script so that the House Pet knows how to connect to the Arduino API.
Enable Bluetooth on the Intelligent Brick
The Lego Intelligent Brick connects to Alexa via a Bluetooth connection with the Echo Show. You'll need to enable Bluetooth on the Lego brick.
Stop once you see the Bluetooth icon appear in the top right corner of the Lego screen.
Download Code to Lego
Visual Studio Code is the easiest way to get the House Pet script onto the device. Download it here.
Installing the EV3Dev plugin will allow you to easily send your code to the EV3 inside of House Pet via the Wifi dongle. Ensure that your EV3 brick is connected to your wifi network and open the folder of code you checked out from Github earlier.
Click on the Send workspace to device button in Visual Studio Code to download the code to the Lego Intelligent Brick.
Activate House Pet!
Open an SSH connection to the Lego brick and start the House Pet script:
sudo python3 house-pet.py
The first time that you run the House Pet application, you'll need to connect it to your Alexa device.
Once the script starts up, you'll the following message in your SSH console:
House Pet is Ready!
Once the python script is running and a connection message appears in the console, House Pet is ready for use!
I wanted to highlight a few of the interesting code snippets in House Pet.
Current Measurement Scaling
The load and charge current pins read an analog voltage via the ADC module. Using measurements taken with different current values, I was able to derive the scaling show below to get an actual current measurement. Luckily, the R squared value is nearly exactly one, meaning a linear scaling is perfect and makes for some easy math.
float load_amps = ((only_load_mv /1000) * 43.30) - 1.71;
float charge_amps = ((charge_volts/1000) * 35.12) - 0.13;
I found some interesting things about the measurements on the two pins.
Voltage Reading Moving Average
Any analog voltage reading is going to be fairly noisy, making filtering a critical part of any good signal acquisition system. I used the extremely nice EWMA Library for Arduino.
chargeCurrent = chargeCurrentFilter.filter(charge_amps);
loadCurrent = loadCurrentFilter.filter(load_amps);
batteryvoltage = battVoltageFilter.filter(batt_volts/1000);
Display Voltage On Screen
It was surprisingly easy to use the Echo Show's screen. Below is the code snippet that is run when you ask House Pet what the battery voltage is.
The Lego light sensor makes detecting the light intensity very easy. This way Alexa only has to look up a percentage value.
Light Sensor Usage
I used the light sensor for two purposes, to detect the light intensity and also to display a red light if the battery voltage is low. To do this, I had to toggle the mode of the light sensor between the Ambient detection mode and the output color.
Polling Arduino IoT Cloud
House Pet receives the battery data (telemetry) from the Arduino IDE. The code to do this is shown below and found at this permalink:
api_response = api_instance.properties_v2_show(id, load_current_pid)
print('Load Current: ', round(api_response.last_value, 2))
load_current = round(api_response.last_value, 1)
except ApiException as e:
print("Exception when calling PropertiesV2Api->propertiesV2List: %s\n" % e)
During my work on House Pet, I found the start up time of the Python script on the EV3 to be really quite slow. I started writing a very basic simulator to simulate the EV3 Dev and Alexa interfaces to improve my debugging speed. Although I haven't yet finished it, the start of that simulator can be found in this Github repository.
I just did some basic mocking of the interfaces. You can see here that I invoke the main event loop of the Gadget and started a method to send Alexa events.
from housepet_gadget import MindstormsGadget
def __init__(self, jsn):
self.payload = jsn
if __name__ == '__main__':
gadget = MindstormsGadget()
I just move my gadget file into the directory here and I will eventually be able to run it in place and significantly speed up my debugging time. I hope to somehow connect it to the Alexa simulator as well.
This is just the beginning for House Pet. There is an incredible amount of functionality I would still like to add in software.
- I would really like to add a lot of educational facts about renewable energy. The voice interface is perfect for a personalized learning experience.
- I would like to simplify the power system to make it smaller, more efficient, and safer. This can be done with a custom printed circuit board easily.
- The ambient light sensor could be used to make House Pet find a sunny spot by itself. This seems like a fun algorithm to implement.
- I'm only scratched the surface with what can be done with the House Pet screen.
- House Pet desperately needs a state of charge estimator. This way House Pet can tell you what percentage the battery is, instead of a voltage level.
- Alexa Skills can easily store stateful information using S3. This would allow House Pet to have memory and remember important things like what your name is, etc.
I hope you enjoyed my write up of the House Pet project! I'm really passionate about renewable energy, robotics, education, and fun! I plan on continuing this project over time because I think it's really fun and valuable. There's so much more work to do!
Get in touch if this sort of thing interests you!