Hello, I just begin using arduino a few days ago and i'm struggling with analogic inputs
how can I convert negative numbers into positive? i'm using an acs712 currency sensor, which outputs 2,5v when the current is 0, but the currency floats from -30 to 30 amp when measuring alternate currency
anyway, when I do a average of the currency, i always get 0, because its alternate currency!
if needed, heres the code i'm using, thanks!!
#include <LiquidCrystal.h> //library for LCD
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
//Measuring Current Using ACS712
const int analogIn = 0; //Connect current sensor with A0 of Arduino
int mVperAmp = 66; // use 100 for 20A Module and 66 for 30A Module
int RawValue= 0;
int ACSoffset = 2476;
int Pot = 0;
int custo = 0;
int sample;
int value;
double Voltage = 0; //voltage measuring
double Amps = 0;// Current measuring
void setup() {
//baud rate
Serial.begin(9600);//baud rate at which arduino communicates with Laptop/PC
// set up the LCD's number of columns and rows:
lcd.begin(16, 2); //LCD order
// Print a message to the LCD.
}
void loop() //method to run the source code repeatedly
{
for(int x=0;x<10;x++)
{
sample+=analogRead(analogIn); //read the voltage from the sensor
delay(20);
}
sample=sample/11;
value = 0;
RawValue = analogRead(analogIn);//reading the value from the analog pin
Voltage = (sample / 1024.0) * 5000; // Gets you mV
Amps = ((Voltage - ACSoffset) / mVperAmp);
Pot = Amps * 220;
custo = Pot * 0.45
//Prints on the serial port
; Serial.print("Raw Value = " ); // prints on the serial monitor
Serial.print(RawValue); //prints the results on the serial monitor
lcd.display();
lcd.setCursor(1,0);
lcd.print(Pot);
lcd.print("W ");
lcd.print(custo);
lcd.print("R$H ");
Serial.print("\t mV = "); // shows the voltage measured
Serial.print(Voltage,3); // the '3' after voltage allows you to display 3 digits after decimal point
Serial.print("sample = ");
Serial.print(sample);
Serial.print("\t Amps = "); // shows the voltage measured
Serial.println(Amps,3);// the '3' after voltage allows you to display 3 digits after decimal point
lcd.setCursor(1,2);
lcd.print(Amps);
lcd.print(" Amperes ");
delay(500); delay;
}