My project is the entrance gate of my property, two 6 ft steel doors powered by 12V electric motors.
The Arduino Uno has 4 optically isolated 30 Amp relays with limit switches in the coil circuits.
To maintain isolation I cannot any of the limit switches to Arduino pins, so I use 4 current sensor boards (ACS-712) with an extra shunt to protect them against the inrush current. The raw output of the sensors is approx. 515, how that converts to Amps is irrelevant in my application:
int leftmaxCurrent = 750; //the left motor is larger than the right one
int rightmaxCurrent = 650;
int minCurrent = 525;
/* There are 2 limit switches on each gate, interrupting the power to
the relay coils when the end of the travel is reached. That can be detected
by the drop of current flowing to the electric motors. If that does not happen because
of a mechanical malfunction, the time-out function will terminate the process.
An increase of current, caused by mechanical obstruction triggers the safety
leftCurrent = analogRead (leftcurrentPin); //to be measured on each loop
rightCurrent = analogRead (rightcurrentPin); //to be measured on each loop
if (leftCurrent >= leftmaxCurrent) //abnormally high current measured
if (rightCurrent >= rightmaxCurrent) //abnormally high current measured
safetyFlag = digitalRead (safetyPin);
if (safetyFlag == HIGH) //one or more safety devices activated
/* The next steps are part of a normal operation to determine when a particular
operation has been completed and the corresponding relay signals can be
This is for any situation where one or two gates have been opening: */
if (leftCurrent <= minCurrent && gateOpening == HIGH) //end of travel reached
digitalWrite (leftgateopenPin, HIGH);
pedestrian = false; // If this was a pedestrian cycle, it has been completed
if (rightCurrent <= minCurrent && gateOpening == HIGH) //end of travel reached
digitalWrite (rightgateopenPin, HIGH); //release the relay
gateOpening = LOW; //completes both car and pedestrian opening cycle
The high current sensing works as expected, but low current sensing doesn’t.
During normal operation the gates stop at random because the current seems to have been below the threshold for a fraction of a second. I probably could insert a resistor and a capacitor between the sensor boards and the analog inputs, but I would prefer a software solution where a few measurements are made in succession and the average value is used in the IF statement.
How do I accomplish that?