Voltage Sensor values change using thingspeak
Show older comments
when I don't include thingspeak in the code line the value of a voltage sensor is accurately read in the serial monitor, but when I start the code with thingspeak the value that reads is inaccurate and read by the serial moitor is also inaccurate, the value is not accurate only when installing thingspeak, whether this incident likes to happen please solution
#include <Filters.h>
#include <SPI.h>
#include <Wire.h>
#include <Ethernet.h>
#include <ThingSpeak.h>
float testFrequency = 50;
float windowLength = 40.0/testFrequency;
//tegangan
int Sensor = 0;
float intercept = -1;
float slope = 1.1833;
float current_Volts;
unsigned long printPeriod = 1000; //Refresh rate
unsigned long previousMillis = 0;
//Ethernet
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
EthernetClient client;
//thingspeak
String apikey = "xxxxxxxxxxxxx";
unsigned long myChanelNumber = xxxxxxxxxxx;
const char * myWriteAPIKey = "xxxxxxxxxxxx";
void setup() {
Serial.begin(9600);
//tes ethernet
//jaringan
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
for (;;);
}
Serial.print("My IP Address: ");
Serial.println(Ethernet.localIP());
delay(1000);
Serial.println("");
ThingSpeak.begin(client);
}
void loop() {
RunningStatistics inputStatsV;
inputStatsV.setWindowSecs( windowLength );
while( true ) {
Sensor = analogRead(A0);
inputStatsV.input(Sensor);
if((unsigned long)(millis() - previousMillis) >= printPeriod) {
previousMillis = millis();
//tegangan
current_Volts = intercept + slope * inputStatsV.sigma();
//tegangan
Serial.print(" Voltage : ");
Serial.println( current_Volts );
ThingSpeak.writeField(myChanelNumber, 1, current_Volts, myWriteAPIKey );
}
}
}
Answers (0)
Communities
More Answers in the ThingSpeak Community
Categories
Find more on Read Data from Channel in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!