Smart Home Automation Forum
[Arduino source code for KC868-M16v2]-05 simple usage detect AC voltage - Printable Version

+- Smart Home Automation Forum (https://www.kincony.com/forum)
+-- Forum: Technical Support (https://www.kincony.com/forum/forumdisplay.php?fid=20)
+--- Forum: KC868-M16 / M1 / MB / M30 (https://www.kincony.com/forum/forumdisplay.php?fid=50)
+--- Thread: [Arduino source code for KC868-M16v2]-05 simple usage detect AC voltage (/showthread.php?tid=3090)



[Arduino source code for KC868-M16v2]-05 simple usage detect AC voltage - admin - 07-18-2023

Code:
/**
* This program shows you how to use the basics of this library.
*/

#include <ZMPT101B.h>

//#define SENSITIVITY 500.0f
#define SENSITIVITY 507.25f

// ZMPT101B sensor output connected to analog pin A0
// and the voltage source frequency is 50 Hz.
ZMPT101B voltageSensor(34, 50.0);

void setup() {
  Serial.begin(115200);
  // Change the sensitivity value based on value you got from the calibrate
  // example.
  voltageSensor.setSensitivity(SENSITIVITY);
}

void loop() {
  // read the voltage and then print via Serial.
  float voltage = voltageSensor.getRmsVoltage();
  Serial.println(voltage);

  delay(1000);
}
before use code, install zmpt101b arduino library firstly.
[Image: attachment.php?aid=2665]