Robin2:
First, please post your program so we have some idea what the problem is.
It is not unusal to get small variations in readings from an ADC. You could write some code that only prints a new value if it differs from the previous value by X
...R
I have posted my code here. Pls read it and tell how to avoid voltage variations and how to implement in coding.
#define LCD_CS A3 // Chip Select A3
#define LCD_CD A2 // Command/Data Register Select A2
#define LCD_RD A0 // LCD Read goes to Analog 0
#define LCD_RESET A4 // LCD Reset A4
// Assign human-readable names to some common 16-bit color values:
#define BLACK 0x0000
#define WHITE 0xFFFF
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define BLUE 0x001F
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
// If using the shield, all control and data lines are fixed, and
// a simpler declaration can optionally be used:
// Adafruit_TFTLCD tft;
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
const int analogInPin0 = A11; // Analog input pin that the potentiometer1 is attached to
const int analogInPin2 = A13; // Analog input pin that the potentiometer2 is attached to
const int analogInPin4 = A15; // Analog input pin that the potentiometer3 is attached to
int sensorValue1 = 0; // value read from the pot1
int sensorValue2 = 0; // value read from the pot2
int sensorValue3 = 0; // value read from the pot3
float battery_voltage;
float temperature = 0.0;
float input_current;
float previous_volt;
float present_volt;
float present_current;
float previous_current;
float previous_temp = 0.0;
float present_temp = 0.0;
float actual_batt_volt;
float offset_voltage = 2.44;
const int R1 = 6900;
const int R2 = 2350;
int mVperAmp = 185;
int ACSoffset = 2500;
float Amps;
void tftlcd_setup()
{
tft.reset(); // reset tft
tft.begin(0x9341); // SDFP5408
tft.setRotation(3); // Need for the Mega, please changed for your choice or rotation initial
tft.fillScreen(BLACK);
tft.setCursor(3, 24);
}
void setup(void)
{
Serial.begin(9600);
float present_temp = 0.0;
tftlcd_setup();
display_homepage();
while(1)
{
sensorValue1 = analogRead(analogInPin0);
sensorValue2 = analogRead(analogInPin2);
sensorValue3 = analogRead(analogInPin4);
Serial.println(sensorValue1);
//Conversion formula for voltage
battery_voltage = (sensorValue1 / 1024.0) * 5.0;
Serial.println(battery_voltage);
actual_batt_volt = (battery_voltage * (R1+R2)) / R2;
Serial.println(actual_batt_volt);
actual_batt_volt = actual_batt_volt - offset_voltage;
//Serial.println(sensorValue2);
//Conversion formula for current
input_current = (sensorValue2 / 1024.0) * 5000; // Gets you mV
//Serial.println(input_current);
Amps = ((input_current - ACSoffset) / mVperAmp);
//Serial.println(Amps);
//Amps = Amps - offset2;
Amps = Amps * 2;
//Conversion formula for temperature
temperature = (sensorValue3 * 100.0) / 1023;
present_temp = temperature;
delay(500);
} // end while
} // end main