first commit
This commit is contained in:
51
ATMEGA_HALL_CONTINU/ATMEGA_HALL_CONTINU.ino
Normal file
51
ATMEGA_HALL_CONTINU/ATMEGA_HALL_CONTINU.ino
Normal file
@@ -0,0 +1,51 @@
|
||||
//Measuring Current Using ACS712
|
||||
|
||||
const int analogIn = A0; //Connect current sensor with A0 of Arduino
|
||||
int mVperAmp = 185; // use 100 for 20A Module and 66 for 30A Module
|
||||
int RawValue= 0;
|
||||
int ACSoffset = 2500;
|
||||
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
|
||||
delay(2000);//delay for 2 sec
|
||||
}
|
||||
|
||||
float valeurACS712( int pin )
|
||||
{
|
||||
int valeur;
|
||||
float moyenne = 0;
|
||||
int nbr_lectures = 50;
|
||||
|
||||
for( int i = 0; i < nbr_lectures; i++ )
|
||||
{
|
||||
valeur = analogRead( pin );
|
||||
moyenne = moyenne + float(valeur);
|
||||
delay(10);
|
||||
}
|
||||
moyenne = moyenne / float(nbr_lectures);
|
||||
return moyenne -235;
|
||||
}
|
||||
|
||||
void loop() //method to run the source code repeatedly
|
||||
{
|
||||
|
||||
RawValue = valeurACS712(analogIn);//reading the value from the analog pin
|
||||
Voltage = (RawValue / 1024.0) * 5000; // Gets you mV
|
||||
Amps = ((Voltage - ACSoffset) / mVperAmp);
|
||||
|
||||
//Prints on the serial port
|
||||
Serial.print("Raw Value = " ); // prints on the serial monitor
|
||||
Serial.print(RawValue); //prints the results on the serial monitor
|
||||
|
||||
|
||||
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("\t Amps = "); // shows the voltage measured
|
||||
Serial.println(Amps,3);// the '3' after voltage allows you to display 3 digits after decimal point
|
||||
|
||||
delay(2500);
|
||||
}
|
||||
Reference in New Issue
Block a user