Pulling pin closer to 0v

Hi there
I am using an arduino nano evry to monitor a voltage from a current sensor and switch an output pin High when it is above a set threshold. This is to drive a probe input to the motion controller of a cnc plasma cutter.
That output goes through an opto-isolator in order to change its voltage to a 24v signal.
The trouble i am having is the output of the nano never being absolute 0V is actualy making the opto-isolator flicker on and off, especially as it gets closer to the threshold voltage for setting the pin as High,
This is resulting in false probe hits which is bit annoying, but i dont want to simply increase the threshold voltage as i would loose sensitivity.

I did try a 1k resistor between the pin and ground, but i must have done something wrong as that didnt seem to work, the Low output still had around 0.5v or so and the led on the opto-isolator still flickers,

What am I getting wrong?
Any help greatly appreciated !

What ever the problem is then I doubt it is this.

We need to see a schematic and your code.

You might want to look at this How to get the best out of this forum before you proceed any further.

1 Like

0.5V shouldn't turn-on an LED. It could be noise from the power supply, or something.

What opto-isolator, and show us a schematic.

And what Arduino are you using?

...Output-low on an ATmega chip (Arduino Uno, etc.) can be as high as 1V if it's "sinking" current. (An input will read low as long as it's below 1.5V.)

That's a strange thing to say (or a strange way to word it) since you can't normally see the LED inside an opto-isolator. And I THINK they are usually infrared.

@Grumpy_Mike is asking for a schematic, that is the best you can do to help us help you. You appear to have a hardware problem, possible the Arduino or coupler.

1 Like

I am just in the process of figuring out how to draw a schematic and will get back to you!

this is the opto-isolator i am using, and when i mean the led is flickering, it is the "active" led on the top

cheers!

Makes me think there's a code bug hitting the LED intermittently. Please post your code, in code tags.

Sorry, Mike, used the wrong reply button.

When I clicked on the users manual it gave me this

Oops…

Looks like this page is missing.
Don’t worry though, our best man is on the case.

image

const int analogPin0 = A0;
const int analogPin1 = A1;
const int analogPin2 = A2;
const int outputPin = 2;

const float threshold0Min = 0.00;  // Minimum value of the analog input0
const float threshold0 = 2.680;    // Trigger voltage analog0
const float threshold0Max = 5.00;  // Maximum voltage analog0 (adjust as needed)

const float threshold1Min = 0.00;  // Minimum value of the analog input1
const float threshold1 = 2.680;    // Trigger voltage analog1
const float threshold1Max = 5.00;  // Maximum voltage analog1

const float threshold2Min = 0.00;  // Minimum value of the analog input2
const float threshold2 = 2.680;    // Trigger voltage analog2
const float threshold2Max = 5.00;  // Maximum voltage analog2

const int outputMin = LOW;   // Output LOW when below threshold
const int outputMax = HIGH;  // Output HIGH when above threshold

unsigned long nextUpdate = 0;
unsigned long maxPrintTime = 0;

void setup() {
  pinMode(outputPin, OUTPUT);
  digitalWrite(outputPin, outputMin);  // Set initial output state
  Serial.begin(9600);
}

void loop() {
  int analogValue0 = analogRead(analogPin0);
  int analogValue1 = analogRead(analogPin1);
  int analogValue2 = analogRead(analogPin2);

  // Map the analog values to the desired threshold ranges
  float actualVoltage0 = map(analogValue0, 0, 1023, threshold0Min * 1000, threshold0Max * 1000) / 1000.0;
  float actualVoltage1 = map(analogValue1, 0, 1023, threshold1Min * 1000, threshold1Max * 1000) / 1000.0;
  float actualVoltage2 = map(analogValue2, 0, 1023, threshold2Min * 1000, threshold2Max * 1000) / 1000.0;


  // Check if any of the voltages are above their respective thresholds
  if (actualVoltage0 > threshold0 || actualVoltage1 > threshold1 || actualVoltage2 > threshold2) {
    digitalWrite(outputPin, outputMax);
  } else {
    digitalWrite(outputPin, outputMin);
  }

  // Print the voltage readings
  if (nextUpdate < millis()) {
    Serial.print("Voltage0: ");
    Serial.print(actualVoltage0, 3);
    Serial.print("\t\t");
    Serial.print("Voltage1: ");
    Serial.print(actualVoltage1, 3);
    Serial.print("\t\t");
    Serial.print("Voltage2: ");
    Serial.print(actualVoltage2, 3);
    Serial.print("\t\t");

    Serial.print("Output Pin Status: ");
    Serial.print(digitalRead(outputPin) == HIGH ? "HIGH" : "LOW");
    Serial.print("\t\t");

    Serial.println();
    nextUpdate = millis() + 2000;
  }
}

thats the code i am using, still trying to make a diagram :laughing:
I am using 3 ACS712 current sensors on the phases of a servo motor,
For the most part the setup is working ok, but maybe could do with some for of filtering within the code? maybe a set amount of time one needs to be above the threshold before the output is made High?

cheers

If your code is flickering, you'll never know it from the print statements. Suggest you only print if at least one input exceeds it's threshold, or some other change event. That way, you'll catch flickers. Or, between the comprehensive 2s reports, just output single characters for each input if it exceeds. Something like the following might result:
verbose report
12323212332123212332
Verbose report

Take a look at KiCad, it is a complete schematic package that will take you from schematic capture to a finished PCB. You will not learn it in an evening. It is basically unlimited so no limit on parts, layers, etc. They ask for a donation but it is free and the same whether you donate or not. Something always helps.

Do you have a manual for the universal converted opto-isolation thing?

I dont have a manual for the opto-isolator i am afraid!

I am wondering if the issue could be related to my wiring, I dont have any pull down resistor on the output,
Also the output is fed down a single wire with no shielding, maybe i should swap that out for a shielded, twisted pair, (the +5v output and 0v from the ground pin on the nano?)

Pen and paper; next take a photo and upload it on the forum. Among the required details are resistor values, type of components and all power and GND lines.

I believe your problem is here, what do your serial.prints look like?

its not hard

Then we will never know if the nano can actually drive this device.
Maybe it requires logic levels different from the nano.
Maybe the logic is inverted.
Maybe it need more current than the nano can supply on an I/O

First step to finding a manual is to have a part number. If you don't have that, you'll never know if you're driving it properly, or working at a limit, or beyond it.

The RC-time of the filter in ACS712 is short (2μs).

You are measuring AC.

Your thresholds will be passed 100 or 120 times a second (50 or 60Hz).

The ADC may not detect it every time, but it does explain the flickering.

Try 10k/10μF between your ACS712 and the analog input.

1 Like

Did you take into account that ACS712 is a bi-directional current sensor, and that the output with zero current is half the supply voltage?
https://forum.allaboutcircuits.com/threads/acs712-current-sensor.189703/

1 Like

I stand corrected.

I’ve been reading the specsheet multiple times.

The text is not clear about it, and I assumed the output would reflect the absolute value of the current.

The graphics are clear about zero point at ½ Vcc, which I overlooked first time around.

That means that simple filtering is not gonna work.

That means that the program must make sense of a fast varying signal, for instance by tracking positive and negative peaks.

If using analogRead() results in in a loop-time that is not fast enough for the frequency of the current, interrupt handling is necessary.