Voltage Sensor values change using thingspeak
이전 댓글 표시
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 );
}
}
}
답변 (0개)
커뮤니티
더 많은 답변 보기: ThingSpeak 커뮤니티
카테고리
도움말 센터 및 File Exchange에서 Read Data from Channel에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!