Power meter with LCD 20x4 + HC-05 BT readings - HEELP

Hello Inventor funs!
I'm trying to built a power meter with Arduino Uno (using ZMPT101B/voltage + ACS712/current sensors).
My sketch seems to work fine and i get the appropriate results on the LCD (after calibration). I calculate the Vrms, Irms, total power & real time cost and then i print the measurements on my LCD. My problem is that....i can't built the appropriate app in MIT Inventor !! I follow some "ready to go" examples with no result !! I want to send the total power and the real time cost (2 parameters) on my Android phone (EMUI 10.0)....I used the HC-05 bluetooth module for my communication (and alternatively the HM-10 bluetooth module).
Any suggestion about building the rigth App in Inventor ???
I attach my code and the circuit diagram:

#include <SoftwareSerial.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4);
SoftwareSerial BTserial(8,9);

float Volts;
float Amps;

void setup() {
lcd.print("Voltage = V");
lcd.print("Current = A");
lcd.print("Power = W");
lcd.print("Cost/h = euro");

void loop() {

int sensorValue1 = analogRead(A0);
int sensorValue2 = analogRead(A1);

float voltage = sensorValue1 * (5.0 / 1023.0);
float current = sensorValue2 * (5.0 / 1023.0);

float MaxV = voltage;
for (int i=0; i<2500;i++)
sensorValue1 = analogRead(A0);
voltage = sensorValue1 * (5.0 / 1023.0);
if (voltage > MaxV)
MaxV = voltage;

float MaxA = current;
for (int i=0; i<2500;i++)
sensorValue2 = analogRead(A1);
current = sensorValue2 *(5.0 / 1023.0);
if (current > MaxA)
MaxA = current;

lcd.print(VoltsAmps); // Total power <------- On LCD
Amps)/1000*0.22); // Real time cost <------- On LCD

if (Serial.available()) {
Serial.println(VoltsAmps); // Total power <------- I want this on my Android phone
Amps)/1000*0.22); // Real time cost <------- I want this on my Android phone

LCD measurements

1 Like

Hi - "If Serial Available" waits for incoming values - so, since there are none, the output values do not get sent.....


  1. Use Serial.print (not println) for the values and the value separator. At the end of the Serial stream, use a single, empty Serial.println() to indicate end-of-data.
  2. Do not use Delay in the main loop - it stops everything. Instead, use elapsed milliseconds.
  3. You have not shown your App Inventor code. The project must use the same value separator and end-of-data flag as the Sketch in order to work. It must also be set to run approx 20% faster than the Sketch loop if the stream is repeating.

Please see the Delimiter article in FAQ

Be sure to use println() at the end of each message to send from the sending device, to signal end of message. Do not rely on timing for this, which is unreliable.

In the AI2 Designer, set the Delimiter attribute of the BlueTooth Client component to 10 to recognize the End of Line character.

Also, return data is not immediately available after sending a request,
you have to start a Clock Timer repeating and watch for its arrival in the Clock Timer event. The repeat rate of the Clock Timer should be faster than the transmission rate in the sending device, to not flood the AI2 buffers.

In your Clock Timer, you should check

  Is the BlueTooth Client still Connected?
  Is Bytes Available > 0?
     IF Bytes Available > 0 THEN
       set message var  to BT.ReceiveText(-1) 

This takes advantage of a special case in the ReceiveText block:

Receive text from the connected Bluetooth device. If numberOfBytes is less than 0, read until a delimiter byte value is received.

If you are sending multiple data values per message separated by | or comma, have your message split into a local or global variable for inspection before trying to select list items from it. Test if (length of list(split list result) >= expected list length) before doing any select list item operations, to avoid taking a long walk on a short pier. This bulletproofing is necessary in case your sending device sneaks in some commentary messages with the data values.

By the way, your Arduino code separates data with '|',
but your blocks split at 'x'.

Make up your mind.

We await YOUR code.