Integrating physical devices with IOTA — Peer-to-peer energy trading with IOTA Part 2
The 19th part in a series of beginner tutorials on integrating physical devices with the IOTA protocol
Introduction
This is the 19th part in a series of beginner tutorials where we explore integrating physical devices with the IOTA protocol. This is the second part in a two part tutorial where we look at using the IOTA token as the settlement currency in a peer-to-peer energy trading solution. In the first part we focused on monitoring real time power consumption and making payments accordingly. In this second part we will look at dealing with variable energy prices, a common problem that must be addressed when dealing with renewable energy sources such as solar, wind, hydro etc.
Note!
If you haven’t already, you should check out the first part of this tutorial before continuing as it forms the basis for the project we are building in this tutorial.
The Use Case
After having there new IOTA based peer-to-peer energy trading solution up and running for some time, our two neighbors again meet to discuss an unexpected problem with there new system. The neighbor explains that due to bad weather the last couple of months his solar power system have not been producing the amount of energy he was hoping for, and that the original energy price (0.2 IOTA per mW/seconds) they both agreed upon is starting to look as a bad deal for him. They could of course simply adjust the price so that the neighbor gets a higher price for his electricity; but what if the weather improves and his solar panels start generating more electricity? In that case the hotel owner ends up with the short end of the stick. What they need is some type of mechanism that dynamically adjusts the price based on the amount of energy the solar panels are producing at any given time.
Let’s see what we can do.
The solution
After thinking about this problem for a few days the hotel owner pitches the following idea:
What if we take a second power sensor and puts it in the circuit between the neighbors solar panels and batteries? We then measure the amount of energy being produced by the solar panels and automatically adjust the price accordingly.
What a great idea, let’s start building..
The components
In this section I will only discuss added or changed components since the previous tutorial, please see the previous tutorial for details about components not listed here.
INA3221 current/voltage/power sensor
The INA3221 is 3 channel low cost current/voltage/power sensor that comes in the form of a breakout board that easily connects to the Raspberry PI’s GPIO pins. The great thing about the INA3221 (compared to the INA219 sensor we used in the previous tutorial) is that it has multiple channels that allows us to monitor multiple power sources in parallel. You should be able to get the INA3221 sensor off ebay or amazon for less that 10 USD.
Note!
Another option to using the INA3221 sensor for this project is to use two INA219 sensors.
Screw terminal blocks
My INA3221 did not come with any screw terminals for the input/output power channels, so i suggest you get some. They simply makes life easier when hooking up the power sources we want to monitor.
Solar panel
Solar panels comes in all shapes and sizes. For our project we only need a small panel capable of charging our 3V rechargeable battery. When doing this project I did not have any solar panels laying around so I ended up hacking some of my girlfriends solar powered garden lights. You can easily get the amount of power you need to charge the battery by wiring two or more of these small panels in series.
Diode
Finally we need a small diode placed in the circuit between the solar panel and the battery. Using the diode we make sure that current only flows from the solar panel to the battery, and not vise versa.
Note!
Make sure the diode is wired the correct way in your circuit, otherwise it will not work.
The wiring diagram
The circuit diagram for the second part of the tutorial is basically the same as for the first tutorial, except that we have replaced the single channel INA219 sensor with the multi channel INA3221 sensor. Also, notice how the INA3221 is now placed in the circuit between the solar panel and the battery. This allows us to monitor both the current going from the battery to the LED, and at the same time, the current going from the solar panel to the battery.
Required Software and libraries
The following Python libraries are required for this project.
The PyOTA library for communicating with the IOTA tangle.
The INA3221 Python library for communicating with the INA3221 sensor.
Note!
While the INA219 and INA3221 are similar in functionality, they use different on-board electronics that makes the libraries incompatible across the two units.
The Python Code
The main changes in our Python code from the previous tutorial (beside using a different library) is that we now not only monitor current going from the battery to the LED, but also the current going from the solar panel to the battery. The mW_price variable is also changed from a static variable to a dynamic variable that changes depending on the amount of energy being produced by the solar panel. The more energy the panel produces, the lower the price, and vice versa.
And here is the updated Python code..
You can download the code from here
Running the project
To run the project, you first need to save the Python code from the previous section to your machine.
Note!
You also need to save the SDL_Pi_INA3221.py file (library) from the INA3221 github repo. to the same folder.
To execute the code, simply start a new terminal window, navigate to the folder where you saved the file and type:
python p2p_energy_trade_p2.py
You should now see the current LED power usage, together with the amount of power being generated by the solar panel, printed to the terminal every second.
Notice how the LED power usage value changes as you turn the potentionmeter.
Also notice how the power generation value from the solar panel changes as you apply more light to the panel by holding it out in the sun, or shining on it with a powerful flashlight.
Every 60 seconds, the average LED power usage for the last period (60 seconds) together with the average solar power generation (for the same period) is calculated, before both values are printed to the monitor.
Next, the price (mW_price) is calculated based on the average amount of energy being produced by the solar panel for the last period (60 seconds).
Finally, we calculate the IOTA payment for this period (60 seconds) before sending a value transaction to the IOTA tangle.
Whats next?
Next time we will be talking to the IOTA tangle using the Amazon Alexa personal voice assistant. How cool is that!!, stay tuned.
Contributions
If you would like to make any contributions to this tutorial you will find a Github repository here
Donations
If you like this tutorial and want me to continue making others feel free to make a small donation to the IOTA address below.
NYZBHOVSMDWWABXSACAJTTWJOQRPVVAWLBSFQVSJSWWBJJLLSQKNZFC9XCRPQSVFQZPBJCJRANNPVMMEZQJRQSVVGZ
Also, Read
- The Best Crypto Trading Bot
- Crypto Copy Trading Platforms
- The Best Crypto Tax Software
- Best Crypto Trading Platforms
- Best Crypto Lending Platforms
- Best Blockchain Analysis Tools
- Crypto arbitrage guide: How to make money as a beginner
- Best Crypto Charting Tool
- Ledger vs Trezor
- What are the best books to learn about Bitcoin?
- 3Commas Review
- AAX Exchange Review | Referral Code, Trading Fee, Pros and Cons
- Deribit Review | Options, Fees, APIs and Testnet
- FTX Crypto Exchange Review
- NGRAVE ZERO review
- Bybit Exchange Review
- 3Commas vs Cryptohopper
- The Best Bitcoin Hardware wallet
- Best monero wallet
- ledger nano s vs x
- Bitsgap vs 3Commas vs Quadency
- Ledger Nano S vs Trezor one vs Trezor T vs Ledger Nano X
- BlockFi vs Celsius vs Hodlnaut
- Bitsgap review — A Crypto Trading Bot That Makes Easy Money
- Quadency Review- A Crypto Trading Bot Made For Professionals
- PrimeXBT Review | Leverage Trading, Fee and Covesting
- Ellipal Titan Review
- SecuX Stone Review
- BlockFi Review | Earn up to 8.6% interests on your Crypto