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 !
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.
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
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?
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.
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.
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.