Analog voltage oscillation with diode

I am finding that adding a diode to my circuit is causing my voltage to oscillate. I’ve reduced the circuit to the simplest version that demonstrates the problem. I have a voltage divider splitting 5V into 2.5V using two 10kohm resistors. From the 2.5V I have an N4001 diode to an analog in pin. I’ve attached a picture of the whole thing wired up.

My code is:
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(A1, INPUT);
}

void loop() {
// put your main code here, to run repeatedly:
delay(200);
}

I’ve tried several measurements, all using ‘analogRead(A1)’:

1. 5V row on the breadboard - 1024 (yay!)
2. GND row on the breadboard - 0 (yay!)
3. Voltage divider - 512 (yay!)
4. After the diode - Oscillates inexplicably

I’ve attached a plot of the voltage measured after the diode too.

Anyone have any idea what is going on here?

Anode connected to the pin? (Otherwise you would have ~2volt on the pin).

The pin could be "floating".

Why this voltage divider with diode?
Leo..

This line configures your pin as a digital input, instead of analogue like you want:-

``````pinMode(A1, INPUT);
``````

I've attached a picture of the whole thing wired up.

No, you've only attached a picture of a waveform. It looks like the waveform from a full-wave rectified mains supply. A 'floating' pin as Wawa says.

Sorry, the wiring picture didn’t go up the first time. File was too big. Its here now.

What do you guys mean by floating pin? What am I supposed to use instead of pinMode(A1, INPUT)?

If I just comment the pinMode line out, it doesn’t fix the issue.

ericksonla:
What do you guys mean by floating pin?

A pin that is not being held in a particular state - 0 or 1 for a digital pin, or at a particular voltage for an analogue pin.

What am I supposed to use instead of pinMode(A1, INPUT)?

Nothing. You only need to configure 'digital' pins. See the >Help >Reference section in the IDE, under 'analogRead()'.

Edit: And why exactly did you add that diode?

Alright, its sort of fixed. I added another resistor from the measurement side of the diode to ground and now the voltage is flat. I'm guessing the arduino wasn't sinking enough current to maintaing a consistent voltage across the diode. Weird problem, but thanks for helping me sort it out!

So out of interest, what's the diode for?
In fact, what's the whole thing supposed to achieve? What's the aim?

The diode was not active, so the pin floating, the voltage from the Voltage divider can not get to the analog in pin A1.

The diode serve no purpose in the circuit.

Edit:
If you need to protect from negative input like this

I am trying to convert the output from an AC transformer (Non-Invasive Current Sensor - 30A - SEN-11005 - SparkFun Electronics) to DC. I don't need a precision current, just whether a device is on or not, so I was just going to use the diode to rectify the voltage. As we've cleared up here though, that doesn't really work here though since the diode isn't in the active part of the circuit. I'm working on a better version now.

ericksonla:
I am trying to convert the output from an AC transformer (Non-Invasive Current Sensor - 30A - SEN-11005 - SparkFun Electronics) to DC. I don't need a precision current, just whether a device is on or not, so I was just going to use the diode to rectify the voltage. As we've cleared up here though, that doesn't really work here though since the diode isn't in the active part of the circuit. I'm working on a better version now.

I won't tell you how, because I think you're enjoying the exercise, but don't forget to include a cap for smoothing.

What is current draw of your device.

You can connect the current transformer from your link directly to an analogue pin.
No other parts needed.
Detection can all be done in software.
Leo…

Wawa:
What is current draw of your device.

You can connect the current transformer from your link directly to an analogue pin.
No other parts needed.
Detection can all be done in software.
Leo..

Serves me right for not looking at that link - didn't realise it was a 'current' transformer. I thought he was detecting the on-state of a mains voltage transformer, when he said "AC transformer".

Wawa:
What is current draw of your device.

You can connect the current transformer from your link directly to an analogue pin.
No other parts needed.
Detection can all be done in software.
Leo..

No, you can't do that, it need to be connected like this, AC negative voltage can kill Arduino

http://openenergymonitor.org/emon/node/58

I hope I have interpreted the datasheet correctly.
CT output is 5mV/Amp
Takes a LOT of amps to reach the ~500mV threshold of the input pin protection diode.
The A/D will only see the positive peaks of the transformer.
No problem, because OP only wants to detect if the load is on or off.
The only problem I can see is that if the user draws <1Amp, the A/D is not able to detect it.
If you’re worried about pin fault current, use a 1-10k resistor in series with the transformer.

The diagram from post#12 is for “clean” current waveform measurements.
Not needed here.
Leo…