Need help with outputting data to Blynk

I make a current sensor on the SCT-013-100 sensor, in the assembly of Arduino Uno and Bluetooth HC06. And I want to transmit the sensor readings to a smartphone (android) via Bluetooth.

Problem is:

I wrote the program, through the port Monitor in the arduino IDE shows all the data (sensor readings), but through the Blynk application there is no reading. Please help me to get a reading in the Blynk app!

I was guided by this article LINK

My code:

#define BLYNK_PRINT Serial
#include "EmonLib.h"
#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(2, 3); // RX, TX
#include <BlynkSimpleSerialBLE.h>
EnergyMonitor emon1;
#define currCalibration 111.1
BlynkTimer timer;

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "vXkUgCkcqlGZXBsqJaC1YWz9ZhQ6FQLj";

float kWh = 0;
unsigned long lastmillis = millis();

void myTimerEvent() {
    emon1.calcVI(20, 2000);
    Serial.print("\tIrms: ");
    Serial.print(emon1.Irms, 4);
    Serial.print("A");
    Blynk.virtualWrite(V1, emon1.Irms);
    Serial.print("\tPower: ");
    Serial.print(emon1.Irms*220, 4);
    Serial.print("W");
    Blynk.virtualWrite(V2, emon1.apparentPower);
    Serial.print("\tkWh: ");
    kWh = kWh + emon1.Irms*220*(millis()-lastmillis)/3600000000.0;
    Serial.print(kWh, 4);
    Serial.println("kWh");
    lastmillis = millis();
    Blynk.virtualWrite(V3, kWh);
}

void setup() {
  Serial.begin(9600);
  emon1.current(1, currCalibration); // Current: input pin, calibration.
  Blynk.begin(Serial, auth);
  timer.setInterval(5000L, myTimerEvent);
}

void loop() {
  Blynk.run();
  timer.run();
}

You’ve created a SoftwareSerial port called DebugSerial which doesn’t have a matching begin statement and isn’t used for anything, but your hardware serial port is being use to communicate with your BT module and for debugging, which will never work as your debug data will interfere with the AT commands sent to your BT module.

Pete.

Can you tell me what to change DebugSerial to? and if it is not difficult to correct the code, thank you!

You don’t need to change it to anything, but the sensible approach would be to connect your BT module to your SoftwareSerial port (pins 2&3) and give that port a more meaningful name, such as BTSerial.
You then need to initialise that serial port with a begin command and use it in your Blynk.begin command.

It is difficult because I don’t have the same hardware, or any details of your energy monitor and how it’s wired, or any desire to ever use Bluetooth as. Blynk connection method.

Pete.

1 Like

Have a look at this link. It may help you with setting up Blynk for your use.

https://how2electronics.com/iot-based-electricity-energy-meter-using-esp32-blynk/

1 Like

thank you for the link, but the problem is that I can not combine the Arduino uno and HC06 and the current sensor with the Blink application (the application does not show the readings).

Maybe you should take a step back and explain in detail what hardware you are using, how it is wired and how it is powered, and provide information about the changes you’ve masked based on the feedback you’ve received, and what results you’ve obtained as a result.

Pete.

the system does not allow more than one image to be uploaded to the forum, what should I do?

Use words not pictures!

Pete.

1) the equipment includes arduino uno, bluetooth HC 06, and SCT-013-100 sensor.

2) I connected everything according to the ready-made scheme, the bluetooth output to rx and tx, the current sensor to the analog output A1.

3) I edited the firmware as you suggested (Need help with outputting data to Blynk - #2 by PeteKnight)

#define BLYNK_PRINT Serial

#include "EmonLib.h"
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(2, 3); // RX, TX
#include <BlynkSimpleSerialBLE.h>
EnergyMonitor emon1;
BlynkTimer timer;

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "vXkUgCkcqlGZXBsqJaC1YWz9ZhQ6FQLj";

float kWh = 0;
unsigned long lastmillis = millis();

void myTimerEvent() {
    emon1.calcVI(20, 2000);
    Serial.print("\tIrms: ");
    Serial.print(emon1.Irms, 4);
    Serial.print("A");
    Blynk.virtualWrite(V1, emon1.Irms);
    Serial.print("\tPower: ");
    Serial.print(emon1.Irms*220, 4);
    Serial.print("W");
    Blynk.virtualWrite(V2, emon1.apparentPower);
    Serial.print("\tkWh: ");
    kWh = kWh + emon1.Irms*220*(millis()-lastmillis)/3600000000.0;
    Serial.print(kWh, 4);
    Serial.println("kWh");
    lastmillis = millis();
    Blynk.virtualWrite(V3, kWh);
}

void setup() {
  Serial.begin(9600);
  emon1.current(1, 111.1); // Current: input pin, calibration.
  Blynk.begin(BTSerial, auth);
  timer.setInterval(5000L, myTimerEvent);
}

void loop() {
  Blynk.run();
  timer.run();
}

4) port monitor readings on arduino ide (connected via BT to HC06)

[0] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.6.7 on Arduino Uno

[89] Connecting...
[3189] Login timeout
[5189] Connecting...
[8270] Login timeout
[10270] Connecting...
[13351] Login timeout
[15351] Connecting...

5) port monitor readings on arduino ide. with the original firmware (Need help with outputting data to Blynk)(connected via BT to HC06)

[0] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.6.7 on Arduino Uno

[89] Connecting...
vXkUgCkcqlGZXBsqJaC1YWz9ZhQ6FQLj[3258] Login timeout
[5258] Connecting...
[15466] Connecting...
vXkUgCkcqlGZXBsqJaC1YWz9ZhQ6FQLj[17552] Ready
Irms: 1.6574A vw Power: 364.6242W  kWh: 0.0027kWh

Not pins 2 & 3?

Pete.

there is, I tried to connect it there, but it is useless

I don’t understand.
Your BT module needs to be connected to your SoftwareSerial port, and you need a BTSerial.begin command, as I said before…

Pete.

I tried it more than once, but now there is no indication in the port monitor

If you want help then you’ll have to provided more information than that.

What have you changed in your code and your wiring?

Pete.

#define BLYNK_PRINT Serial

#include "EmonLib.h"
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(2, 3); // RX, TX
#include <BlynkSimpleSerialBLE.h>
EnergyMonitor emon1;
BlynkTimer timer;

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "vXkUgCkcqlGZXBsqJaC1YWz9ZhQ6FQLj";

float kWh = 0;
unsigned long lastmillis = millis();

void myTimerEvent() {
    emon1.calcVI(20, 2000);
    BTSerial.print("\tIrms: ");
    BTSerial.print(emon1.Irms, 4);
    BTSerial.print("A");
    Blynk.virtualWrite(V1, emon1.Irms);
    Serial.print("\tPower: ");
    Serial.print(emon1.Irms*220, 4);
    Serial.print("W");
    Blynk.virtualWrite(V2, emon1.apparentPower);
    Serial.print("\tkWh: ");
    kWh = kWh + emon1.Irms*220*(millis()-lastmillis)/3600000000.0;
    Serial.print(kWh, 4);
    Serial.println("kWh");
    lastmillis = millis();
    Blynk.virtualWrite(V3, kWh);
}

void setup() {
  BTSerial.begin(9600);
  emon1.current(1, 111.1); // Current: input pin, calibration.
  Blynk.begin(BTSerial, auth);
  timer.setInterval(5000L, myTimerEvent);
}

void loop() {
  Blynk.run();
  timer.run();
}

That’s because you’ve removed your Serial.begin(9600); command!

Pete.

connected to the digital output pin 2 and 3

So is it working now?

Pete.