Hello!
I'm working project about Telemetry Street Lamp. Using ACS712 for current sensor(AC current) and Rectifier for voltage sensor (and LCD i2c for interface), when i test each code, it work properly but when i joined current sensor code and LCD code. LCD not show the character.
ACS712 code
#include <Filters.h>
float testFrequency = 60; // test signal frequency (Hz)
float windowLength = 20.0/testFrequency; // how long to average the signal, for statistist
int sensorValue = 0;
float intercept = -0.1129; // to be adjusted based on calibration testing
float slope = 0.0405; // to be adjusted based on calibration testing
float current_amps; // estimated actual current in amps
unsigned long printPeriod = 1000; // in milliseconds
// Track time in milliseconds since last reading
unsigned long previousMillis = 0;
void setup() {
Serial.begin( 57600 ); // start the serial port
}
void loop() {
RunningStatistics inputStats; // create statistics to look at the raw test signal
inputStats.setWindowSecs( windowLength );
while( true ) {
sensorValue = analogRead(A0); // read the analog in value:
inputStats.input(sensorValue); // log to Stats function
if((unsigned long)(millis() - previousMillis) >= printPeriod) {
previousMillis = millis(); // update time
// display current values to the screen
Serial.print( "\n" );
// output sigma or variation values associated with the inputValue itsel
Serial.print( "\tsigma: " ); Serial.print( inputStats.sigma() );
// convert signal sigma value to current in amps
current_amps = intercept + slope * inputStats.sigma();
Serial.print( "\tamps: " ); Serial.print( current_amps );
}
}
}
LCD code
/* http://www.electronoobs.com */
/*-----( Inport library )-----*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
//i2c pins
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); //
int volt=0;
int amp=0;
void setup()
{
Serial.begin(9600);
//WE define our LCD 16 columns and 2 rows
lcd.begin(16,2);
lcd.backlight();//Power on the back light
//lcd.backlight(); Power off the back light
}
void loop()
{
//Write your text:
lcd.setCursor(0,0); //we start writing from the first row first column
lcd.print("Tegangan: "); //16 characters poer line
lcd.setCursor(0,1);
lcd.print("Arus: ");
delay(1000);
}
final code
#include <Filters.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
//i2c pins
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); //
int volt = 0;
int amp = 0;
float testFrequency = 60; // test signal frequency (Hz)
float windowLength = 20.0 / testFrequency; // how long to average the signal, for statistist
int sensorValue = 0;
float intercept = -0.1129; // to be adjusted based on calibration testing
float slope = 0.0405; // to be adjusted based on calibration testing
float current_amps; // estimated actual current in amps
unsigned long printPeriod = 1000; // in milliseconds
// Track time in milliseconds since last reading
unsigned long previousMillis = 0;
void setup() {
Serial.begin( 9600 ); // start the serial port
lcd.begin(16, 2);
lcd.backlight();
}
void loop() {
RunningStatistics inputStats; // create statistics to look at the raw test signal
inputStats.setWindowSecs( windowLength );
while ( true ) {
sensorValue = analogRead(A0); // read the analog in value:
inputStats.input(sensorValue); // log to Stats function
if ((unsigned long)(millis() - previousMillis) >= printPeriod) {
previousMillis = millis(); // update time
// display current values to the screen
Serial.print( "\n" );
// output sigma or variation values associated with the inputValue itsel
Serial.print( "\tsigma: " ); Serial.print( inputStats.sigma() );
// convert signal sigma value to current in amps
current_amps = intercept + slope * inputStats.sigma();
Serial.print( "\tamps: " ); Serial.print( current_amps );
}
}
lcd.setCursor(0, 0); //we start writing from the first row first column
lcd.print("Tegangan: "); //16 characters poer line
lcd.setCursor(0, 1);
lcd.print("Arus: "); lcd.print(current_amps, 5);
}
Every advice may helps my problem here
Thanks