Published June 30, 2025 | Version v1
Software Open

Smart meter Code used for the blink frequency calculation

  • 1. University of West Attica, School of Engineering, Department of Electrical and Electronic Engineering, Smart Technologies, R.E.S. and Quality Lab

Description

Firstly, the code utilises several variables, each accompanied by a brief comment explaining its purpose. Subsequently, the setup of the BH1750 sensor is performed. The sensor is utilised in its high-resolution continuous mode.

The loop begins after ensuring the sensor has been properly initialised. The Arduino waits for a measurement to be received. As the data transmitted to the Arduino via the I2C protocol is already in digital form, no additional signal processing is necessary. When the LED blinks, the code detects a peak lux value, which is received by the code. The example code states that the blink corresponds to a peak of at least 5 lux (lux > 5). However, this value can be adjusted if the blink is less intense. The sensor can distinguish blinks that exceed 1 lux (blink energy > 1 lux).

The program measures the average time between blinks and calculates the average hourly consumption using this parameter. Each time a blink is detected, the variables t0 and t1 are updated, and the difference between them is stored in the ratio variable. This difference is then added to the variable total Sum. This part of the code can be observed in lines of main code 29 to 53 and is used for the blink frequency calculation. In the code for the blink frequency calculation, the value is obtained in milliseconds and converted then to seconds.

Subsequently, the variable totalSum is divided by the number of blinks detected by the sensor. This calculation yields the average time difference. The program performs this calculation every 15 seconds. This time difference is used for the consumption calculation and is utilised for the consumption calculation. For increased accuracy, the consumption is also calculated in Wh (watt-hours).

Files

smart_meters.zip

Files (1.4 kB)

Name Size Download all
md5:5e384da61bc4e766b6bd4d89d592b708
1.4 kB Preview Download