Introduction: EnergyChain

/* Work still in progress */

Energy Chain is a POC which combine IOT and Blockchain.

What we made allow people to sell the energy they produce to anyone without any tier needed. To ensure safety between the producer and the consumer, the consumer can connect whatever he wants on it and get energy. The box measures the amount of current consumed and write the equivalent

Step 1: Materials

To make this projet we will use :

- 1 Raspberry Pi Zero

- 1 current sensor AS712 (20A)

- 1 ADC 16bit I2C ADS1555

- 1 RFID sensor RC522

- 1 relay 5V

- 1AC/DC 5V/2A converter ECL10US05-E from Farnell

- 1 electrical outlet

Step 2: Wiring

We need to wire everything together as it's shown in the picture, be carefull to the current delivered by the Raspberry Pi.

Command wiring :

  • 3v3 Power - Relay 5V Vcc/Current Sensor Vcc/RFID Vcc/ADC Vcc
  • 5v Power - AC/DC converter 5v
  • Ground - Relay 5V GND/Current Sensor GND/AC/DC converter GND/RFID GND/ADC input and output GND
  • BCM 2 - ADC SDA
  • BCM 3 - ADC SCL
  • BCM 4 - ADC CLK
  • BCM 6 - RFID SDA
  • BCM 9 - RFID MISO
  • BCM 10 - RFID MOSI
  • BCM 11 - RFID SCK
  • BCM 17 - Relay 5V IN

  • BCM 24 - RFID Reset
  • BCM 25 - RFID RST

Step 3: Code

This code works as follow :

The RFID sensor waits for a tag and write it in the Terminal.Then the current sensor measures the amount of AC current consumed and display in the terminal the instantaneous power every 100 measures. Thanks to that, we can get the amount of kWh.

import socket, json
import sys
from threading import Thread
from pirc522 import RFID
import RPi.GPIO as GPIO ## Import GPIO library
import signal
import time
import Adafruit_ADS1x15
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11, GPIO.OUT)
GPIO.output(11,True)
rdr = RFID()
util = rdr.util()
util.debug = True
TCP_IP = '172.31.29.215'
TCP_PORT = 5000
BUFFER_SIZE = 1024
adc = Adafruit_ADS1x15.ADS1115()
def end_read(signal,frame):
    global run
    print("\nCtrl+C captured, ending read.")
    run = False
    rdr.cleanup()
    sys.exit()
signal.signal(signal.SIGINT, end_read)
def loopRead(s):
    DemandeTag=1
    DemandeMesure=0
    bol = True
    while (bol):
        if DemandeTag==1:
            tag()
            DemandeTag=0
            DemandeMesure=1
        if DemandeMesure==1:
            Mesure2()
        try:
            data = s.recv(BUFFER_SIZE)
            if not data:
                break
            print data
            dataJSON = json.loads(data)
            if "message" in dataJSON:
                print dataJSON['message']
                if dataJSON['message'] == "exit":
                    print('Exit demande')
                    GPIO.output(11, GPIO.HIGH)
                    DemandeTag=0
                    DemandeMesure=0
                    bol = False
                if dataJSON['message'] == "on":
                    GPIO.output(11, GPIO.LOW)
                    DemandeMesure=1
                    DemandeTag=1
                if dataJSON['message'] == "off":
                    GPIO.output(11, GPIO.HIGH)
                    DemandeTag=1
                message=''
        except Exception as e:
            continue
    s.close()
def tag():
    rdr.wait_for_tag()
    (error, data) = rdr.request()
    time.sleep(0.25)
    (error, uid) = rdr.anticoll()
    ID=str(uid[0])+'.'+str(uid[1])+'.'+str(uid[2])+'.'+str(uid[3])
    print("Card read UID: "+ID)
    GPIO.output(11, GPIO.LOW)
def Mesure():
    mesure_voltage = 0
    Nbre_mesure=100
    i = 0
    while i
def Mesure2():
    mesure_voltage = 0
    Nbre_mesure=200
    max_voltage=0
    min_voltage=32768
    mVparAmp = 100
    Puissance=0
    i = 0
    readValue=0
    while imax_voltage:
            max_voltage=readValue
        if readValue
def Mesure3():
    print(str(adc.read_adc(0, gain=1)))
if __name__ == "__main__":
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    #s.connect((TCP_IP, TCP_PORT))
    #s.setblocking(0)  
    loopRead(s)

Step 4: The Box

To make all the electronics more compact, we designed a box which will contain everything inside. To screw on everything we will use M3 screws.

3D File