Input goes from 30 to zero every couple of s for arduino, stable on multimeter

Hi,
I'm using Arduino Uno to read the output of a current sensor, that goes through a LM358 (non inverting amplifier configuration) and then directly to A0. On A1 I've a reference voltage (a threshold to compare the current signal to), using a trimmer.

My problem is that:

  • on A1 (trimmer) analogRead is ok (reads 10, ~50mV on multimeter)
  • LM358 output is ~50mV too, according to the multimeter, and very stable
  • LM358 output is directly connected to A0. Arduino readings follow (with delay(100) in the loop)
0
0
0
0
0
0
2
7
9
10
11
12
12
13
15
16
15
14
15
16
16
17
18
19
20
20
20
25
27
30
30
30
30
30
28
28
26
26
21
14
10
9
7
5
4
2
2
2
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

Do you have any idea?

Do you have any idea?

Several!
Post the code, using code tags.
Post a wiring diagram (hand drawn, not Fritizing).
For instructions, read the "How to use this forum" post and follow the directions.

Thank you. I'll post the wiring tomorrow. The code is the standard analogRead example, that's why I didn't post it. The strange thing is that I'm reading voltage both with Arduino and multimeter at the same time, and while the multimeter measure is stable, arduino goes up and down as described.

Thanks again

vad_:
I'm using Arduino Uno to read the output of a current sensor,

that goes through a LM358 (non inverting amplifier configuration) and then directly to A0. On A1 I've a reference voltage (a threshold to compare the current signal to), using a trimmer.

What current sensor.
Are you trying to measure AC or DC.
Leo..

while the multimeter measure is stable, arduino goes up and down as described.

You forgot to connect the grounds.

This is how I connect the current sensor to Arduino: link.

LM358P power comes from arduino +5V pin.

This is the actual circuit: link.

The trimmer is 54 Ohm, the feedback R is 1.1kOhm.

Mmmh.... it must be because I'm measuring AC current, right? But I don't get how to amplify the small voltage the SCT-013 gives me and measure it with arduino.

You need to bias the CT to mid-voltage if you want to measure the full sinewave of AC.
Lots of info on this website.
Leo..

I only need to understand if there's current or not. I've just implemented a brute force approach, doing 200 analogRead() and then comparing min and max to understand if there's AC. It works fine but i don't know if this puts too much stress on the AD converter. I've read a lot about biasing the CT but I don't understand how to make it work with the op-amp, since without amplification the CT voltage is too small.

Another idea would be to keep the amplified positive tension I have and use a condenser to stabilize it, right?

Thank you

Don't know how much gain you have with that LM358.
Not sure if you have your facts right.
I see a 10k resistor, not 1k1. And do you mean the pot is set to 54ohms.

Try to measure AC voltage of the current sensor (without any burden resistor) with a DMM set to ACvolt.
Post back the AC voltage you have measured.
Leo..

vad_:
It works fine but i don’t know if this puts too much stress on the AD converter.

No, the MCU works all the time. Not important what it does.

Try this sketch (untested) without the LM358.
It uses the internal reference for 5x gain, and 200 samples to catch at least one half of the sine wave.
Only use a burden resistor across the CT if you have to (reduces sensitivity).
Leo…

// Current or no current detector only
// CT connected to A0 and ground, with 1k protection resistor between CT and A0

const byte ledPin = 13; // use buildin LED as current indicator
int rawValue;
int peakValue;
int threshold = 0; // change this value if too sensitive

void setup() {
  analogReference(INTERNAL); // use the internal ~1.1volt reference | change (INTERNAL) to (INTERNAL1V1) for a Mega
  Serial.begin(9600);
}

void loop() {
  peakValue = 0;
  for (int i = 0; i < 200; i++) { // 200 reads to catch at least one sine wave
    rawValue = analogRead(A0);
    if (rawValue > peakValue) peakValue = rawValue;
  }
  if (peakValue > threshold) digitalWrite(ledPin, HIGH);
  else {
    digitalWrite(ledPin, LOW);
  }
  Serial.print("Peak A/D value is: ");
  Serial.println(peakValue);
  delay(250); // remove when combined with other code
}