Final release

master
marcel 2 years ago
parent b34c00d4be
commit e45c02ee49
  1. 2
      CHANGELOG.md
  2. 23
      MQTT_energymeter.ino
  3. 12
      README.md
  4. BIN
      hardware/MQTT_energy_meter-B_Cu.pdf
  5. BIN
      hardware/MQTT_energy_meter-F_SilkS.pdf
  6. 1042
      hardware/MQTT_energy_meter.kicad_pcb
  7. 1818
      hardware/MQTT_energy_meter.kicad_pcb-bak
  8. 10
      hardware/MQTT_energy_meter.net
  9. BIN
      hardware/MQTT_energy_meter.pdf
  10. BIN
      hardware/MQTT_energy_meter.png
  11. 18
      hardware/MQTT_energy_meter.sch
  12. 6
      hardware/MQTT_energy_meter.sch-bak
  13. BIN
      hardware/MQTT_energy_meter_3D_view.png

@ -9,5 +9,5 @@ All notable changes to this project will be documented in this file.
Fixed : for any bug fixes.
Security : in case of vulnerabilities.
## [1.0.0] - 2022-11-29
## [1.0.0] - 2023-01-06
First working version.

@ -42,14 +42,14 @@
/* CHANGE THESE VALUES TO CUSTOMIZE DATA LOGGER */
#define CLIENT_ID "MeesElectronics" // Our MQTT client ID
#define CLIENT_TOPIC "energy/solar" // Name of the topic we publish
#define CLIENT_TOPIC "distributioncabinet/energy/solar" // Name of the topic we publish
//IPAddress IP_MQTT_broker(192, 168, 89, 10); // IP address of the MQTT broker
//String string_ip_mqtt_broker = "192.168.88.10";
char IP_string_MQTT_broker[20] = "192.168.88.11";
uint16_t MQTT_port = 1884;
uint16_t MQTT_port = 1883;
IPAddress IP_MQTT_broker;
#define PULSES_PER_KWH 500 // 500 pulses from the energy meter is one kWh
#define PULSES_PER_KWH 1000 // 500 pulses from the energy meter is one kWh
/* END USER DEFINABLE VALUES */
uint8_t mac[6] = {MACADDRESS};
@ -63,7 +63,7 @@ EthernetClient ethClient;
PubSubClient mqttClient;
#define PULSES_PER_WH 1000/PULSES_PER_KWH // Calculates how many pulses corresponds to a Wh
#define INTERVAL 10000 // 10 sec delay between MQTT publishings
#define INTERVAL 60000 // 60 sec delay between MQTT publishings
long previousMillis;
char numberArray[20];
@ -71,6 +71,8 @@ uint32_t PulseCount=0; // This variable holds the pul
uint32_t EnergyReading=0; // This variable holds the number of Watt-hours
uint32_t stored_kwh_count=0; // Counted whole kWh value sored in EEPROM
#define LED 9
void onDetectInterrupt()
{
// The Arduino calls this function when it detects a falling edge on pin 2.
@ -118,6 +120,9 @@ void setup() {
pinMode(2, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(2), onDetectInterrupt, FALLING);
pinMode(LED, OUTPUT);
digitalWrite(LED, HIGH);
// initialize the ethernet device
//Ethernet.begin(mac,myIP,myDNS,myGW,myMASK);
Serial.print(F("Configuring ethernet..."));
@ -240,6 +245,11 @@ void loop() {
else
{
client.write("?",1);
//client.write("?\n",2);
//client.write(": <IP> sets ip of broker.\n",26);
//client.write("P <port> set port op broker.\n",29);
//client.write("I prints ip and port of broker.\n",32);
//client.write("S saves settings to EEPROM.,27");
Serial.println(F("?"));
}
client.write("\n",1);
@ -258,6 +268,11 @@ void loop() {
}
mqttClient.loop();
readEnergymeter();
if (digitalRead(2))
digitalWrite(LED, HIGH);
else
digitalWrite(LED, LOW);
}
void sendData() {

@ -1,16 +1,24 @@
# Datalogger reading kWh pulses from a utility grid meter and publising it via MQTT
(C) 2022 M. Konstapel https://meezenest.nl/mees
(C) 2023 M. Konstapel https://meezenest.nl/mees
Inspired by https://www.instructables.com/A-Simple-MQTT-PubSub-Node-With-Arduino-UNO-and-ENC/
![Board layout](./hardware/MQTT_energy_meter_3D_view.png "board layout")
## Design
Most mains energy meters have an LED which flashes 500 or 1000 pulses for every measured kWh. A photo-diode mounted in front of this LED detects the flashes. Every pulse is converted to a clean digital signal by an adjustable comparator with hysteresis followed by a 74HC14 Schmitt-trigger. The resulting pulses can be inverted by means of a jumper. A falling edge triggers an interrupt of the ATMega328. The firmware counts the interrupts and calculates the equivalent energy in Wh. Every 60 seconds the result is published to the MQTT broker on topic 'distributioncabinet/energy/solar'.
![Schematic](./hardware/MQTT_energy_meter.png "schematic")
## Features
- Runs on low spec microcontroller (Uno, Nano, Mini, and other ATMega328-based boards)
- Wired ethernet via ENC28J60 Ethernet module
- Gets ip address via DHCP
- Stores data in EEPROM to prevent data loss
- Easy to configure by telnet port 1000
- Easy to configure via telnet port 1000
## Requirements

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -1,14 +1,14 @@
(export (version D)
(design
(source /home/marcel/Documenten/electronische_projecten/atmega328p_mqtt_energy_meter/MQTT_energy_meter/MQTT_energy_meter.sch)
(date "ma 02 jan 2023 15:23:33 CET")
(source /home/marcel/Documenten/electronische_projecten/atmega328p_mqtt_energy_meter/firmware/atmega328p_mqtt_energy_meter/hardware/MQTT_energy_meter.sch)
(date "di 10 jan 2023 21:21:15 CET")
(tool "Eeschema 5.1.8-5.1.8")
(sheet (number 1) (name /) (tstamps /)
(title_block
(title "MQTT ethernet energy meter")
(company "M. Konstapel")
(rev 1)
(date 2022-11-21)
(date 2023-01-02)
(source MQTT_energy_meter.sch)
(comment (number 1) (value meezenest.nl/mees))
(comment (number 2) (value "Mees Electronics"))
@ -554,7 +554,7 @@
(node (ref R1) (pin 2))
(node (ref U3) (pin 16))
(node (ref C6) (pin 2))
(node (ref J1) (pin 2))
(node (ref J1) (pin 1))
(node (ref U5) (pin 7))
(node (ref U5) (pin 9))
(node (ref U5) (pin 5))
@ -580,7 +580,7 @@
(node (ref D2) (pin 2)))
(net (code 14) (name "Net-(C4-Pad1)")
(node (ref U6) (pin 1))
(node (ref J1) (pin 1))
(node (ref J1) (pin 2))
(node (ref C5) (pin 1))
(node (ref C4) (pin 1)))
(net (code 15) (name "Net-(U1-Pad1)")

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

@ -499,8 +499,8 @@ F 3 "" H 5250 2525 50 0001 C CNN
$EndComp
Wire Wire Line
5250 2525 5175 2525
Text Notes 5575 2625 0 50 ~ 0
Short this jumper\nto configure device\nvia serial port.
Text Notes 4800 2650 0 50 ~ 0
For future use.
$Comp
L Device:R_Small R4
U 1 1 6385274C
@ -648,13 +648,13 @@ Connection ~ 9125 1500
$Comp
L Connector:Conn_01x02_Male J1
U 1 1 6392A12E
P 7250 1500
F 0 "J1" H 7358 1681 50 0000 C CNN
F 1 "8-24V in" H 7275 1300 50 0000 C CNN
F 2 "TerminalBlock_Phoenix:TerminalBlock_Phoenix_MKDS-1,5-2_1x02_P5.00mm_Horizontal" H 7250 1500 50 0001 C CNN
F 3 "~" H 7250 1500 50 0001 C CNN
1 7250 1500
1 0 0 -1
P 7250 1600
F 0 "J1" H 7250 1425 50 0000 C CNN
F 1 "8-24V in" H 7275 1675 50 0000 C CNN
F 2 "TerminalBlock_Phoenix:TerminalBlock_Phoenix_MKDS-1,5-2_1x02_P5.00mm_Horizontal" H 7250 1600 50 0001 C CNN
F 3 "~" H 7250 1600 50 0001 C CNN
1 7250 1600
1 0 0 1
$EndComp
Wire Wire Line
7450 1500 7725 1500

@ -5,7 +5,7 @@ $Descr A4 11693 8268
encoding utf-8
Sheet 1 1
Title "MQTT ethernet energy meter"
Date "2022-11-21"
Date "2023-01-02"
Rev "1"
Comp "M. Konstapel"
Comment1 "meezenest.nl/mees"
@ -499,8 +499,8 @@ F 3 "" H 5250 2525 50 0001 C CNN
$EndComp
Wire Wire Line
5250 2525 5175 2525
Text Notes 5575 2625 0 50 ~ 0
Short this jumper\nto configure device\nvia serial port.
Text Notes 4800 2650 0 50 ~ 0
For future use.
$Comp
L Device:R_Small R4
U 1 1 6385274C

Binary file not shown.

After

Width:  |  Height:  |  Size: 237 KiB

Loading…
Cancel
Save