Principe de fonctionnement
le deux relais est activé si et seulement si la valeur du courant mesuré ne dépasse pas la valeur choisit par le potentiomètre
dans le cas contraire un seul relais est activé
// include the library code:
#include <LiquidCrystal.h> //library for LCD
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);
#define relay 7
#define Relay 6
//Measuring Current Using ACS712
const int Sensor_Pi = A0; //Connect current sensor with A0 of Arduino
int sensitivit = 100; // use 100 for 20A Module and 66 for 30A Module
int offsetvoltag = 2532;
float POT;
float I_Max;
void setup()
{ Serial.begin(9600);
lcd.begin(20, 4); // set up the LCD's number of columns and rows:
pinMode(relay,OUTPUT);
pinMode(Relay,OUTPUT);
pinMode(POT,INPUT);
}
void loop()
{ POT = analogRead(A1);
I_Max = map(POT,0,1023,0,20);
//digitalWrite(relay,HIGH);
unsigned int tem=0;
float maxpoin = 0;
for(int T=0;T<500;T++)
{
if(tem = analogRead(Sensor_Pi), tem>maxpoin)
{
maxpoin = tem;
}
}
float ADCvalu = maxpoin;
double Voltag = (ADCvalu / 1024.0) * 5000; // Gets you mV
double Curren = ((Voltag - offsetvoltag) / sensitivit);
double AC_Curren = ( Curren ) / ( sqrt(2) );
lcd.setCursor(0,0);
lcd.print("I_Max : ");
lcd.print(I_Max);
lcd.print(" A ");
// lcd.setCursor(0,1);
// lcd.print(" ");
lcd.setCursor(0,2);
lcd.print(" AC Current = ");
lcd.print(AC_Curren,2);
lcd.print("A "); //unit for the current to be measured
delay(100); //delay in milli-sec
switch ((AC_Curren)<I_Max) {
case 1: digitalWrite(relay,HIGH);
digitalWrite(Relay, HIGH);
break;
case 2:digitalWrite(relay,HIGH);
digitalWrite(Relay, LOW);
break;}
}