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() {
Serial.begin(9600);
BTserial.begin(9600);
lcd.init();
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("Voltage = V");
lcd.setCursor(0,1);
lcd.print("Current = A");
lcd.setCursor(0,2);
lcd.print("Power = W");
lcd.setCursor(0,3);
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;
Volts=(abs(MaxV-2.5)/1.21)*230;
}
delayMicroseconds(500);
}
float MaxA = current;
for (int i=0; i<2500;i++)
{
sensorValue2 = analogRead(A1);
current = sensorValue2 *(5.0 / 1023.0);
if (current > MaxA)
{
MaxA = current;
Amps=(abs(MaxA-2.5)/0.74)*8.6;
}
delayMicroseconds(500);
}
lcd.setCursor(10,0);
lcd.print(Volts);
lcd.setCursor(10,1);
lcd.print(Amps);
lcd.setCursor(8,2);
lcd.print(VoltsAmps); // Total power <------- On LCD
lcd.setCursor(9,3);
lcd.print((VoltsAmps)/1000*0.22); // Real time cost <------- On LCD
if (Serial.available()) {
Serial.println(VoltsAmps); // Total power <------- I want this on my Android phone
Serial.print("|");
Serial.println((VoltsAmps)/1000*0.22); // Real time cost <------- I want this on my Android phone
delay(1000);
}
}