A current sensor produce a current graph and power graph

Hye . I need help . I want to use value from sensor to produce graph one for current and one for power . I used acs712 current sensor . So, first graph for value of current directly from sensor . Another graph is for current which value from sensor multiply with voltage . I pass the value sensor from arduino uno to nodemcu . Here the coding . Please help me .

CAYENNE_OUT(3)
{
NodeMCU.print(0xA0);
NodeMCU.print(“\n”);
while (NodeMCU.available()>0){
float val = NodeMCU.parseFloat ();
if(NodeMCU.read()== ‘\n’){
Serial.println(val-0.02);
Cayenne.virtualWrite(3,val);
}
}
}

CAYENNE_OUT(4)
{
NodeMCU.print(0xA0);
NodeMCU.print(“\n”);
while (NodeMCU.available()>0){
float val = NodeMCU.parseFloat ();
if(NodeMCU.read()== ‘\n’){
Serial.println(val230);
Cayenne.virtualWrite(4,val
230);
}
}
}

I try this code but not work .

i would suggest, try to see if you can get data from the sensor without adding the cayenne code. once that is done, sending data to cayenne is easy. can you share the entire code.

Here is the coding . I used Nodemcu and arduino uno. The value of sensor I got from arduino then pass it to nodemcu. I need one more help . I want to display the value of (val) and (power) on lcd 16x2 but there nothing appear. Can you help me where should I put the lcd.print(power); ??

#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>
#include <SoftwareSerial.h>
#include <ESP8266WiFi.h>
SoftwareSerial NodeMCU(D2, D3); //RX|TX
#include <LiquidCrystal.h>

const int rs = 14, en = 12, d4 = 13, d5 = 15, d6 = 3, d7 = 1;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

char ssid[] = “abc”;
char wifiPassword[] = “123”;

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = “abc”;
char password[] = “123”;
char clientID[] = “abc123”;

void setup() {
// put your setup code here, to run once:
NodeMCU.begin(4800);
pinMode(D2, INPUT);
pinMode(D3, OUTPUT);
pinMode(2, OUTPUT);
lcd.begin(16, 2);
Serial.begin(115200);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
}

void loop() {
// put your main code here, to run repeatedly:
Cayenne.loop();
}

CAYENNE_IN(2) //channel 2 cayenne virtual
{
CAYENNE_LOG(“Got a value: %s”, getValue.asStr());
// You can also use:
int i = getValue.asInt();// or
if (i <= 0)
{
digitalWrite(2, HIGH);
}
else if (i > 0)
{
digitalWrite(2, LOW);
}
}

/*CAYENNE_OUT(3)
{
NodeMCU.print(0xA0);
NodeMCU.print("\n");
while (NodeMCU.available()>0){
float val = NodeMCU.parseFloat ();
if(NodeMCU.read()== ‘\n’){
//Serial.println(val-0.02);
Cayenne.virtualWrite(3,val);
}
}
}
*/

CAYENNE_OUT(5)
{
NodeMCU.print(0xA0);
NodeMCU.print("\n");
while (NodeMCU.available() > 0) {
float val = NodeMCU.parseFloat ();
if (NodeMCU.read() == ‘\n’) {
float power = val * 240;
Cayenne.virtualWrite(5, power);
Serial.println(power);
Cayenne.virtualWrite(3, val);
Serial.println (val);
}
}

}

where had you tired placing the LCD code? you can place it in CAYENNE_OUT().

Can do like that ?

1 Like

yes that should work.