I have a wire with a 0-5v current. I want to detect if the current is there or not (HIGH/LOW.)

I'm using an optocoupler to avoid putting too much current into my micro, as it is only a 3.3V micro. I'm nervous about powering this on as one of my other micros stopped working although it's not clear if it could have been the circuit?

enter image description here I could not find my optocoupler in fritzing. This is it: http://www.amazon.com/gp/product/B00CGXK1RG?psc=1&redirect=true&ref_=oh_aui_detailpage_o07_s00

This is my plan.

The microcontroller is a spark/particle core. It the yellow wire connects to the analog/digital pin A6. The screw terminals connect to the wire with the 5v current that I'm trying to detect.

The microcontroller is a spark/particle core 3.3v. It the yellow wire connects to the analog pin A6. The screw terminals connect to the wire with the 5v current that I'm trying to detect.

I based my circuit on this:

enter image description here

But I don't know if it will do the same thing.

enter image description here

  • What's the optocoupler for again? – Ignacio Vazquez-Abrams Jul 11 '15 at 1:23
  • The micro is at 3.3v but the signal I'm trying to detect passively is at 5v – futurebird Jul 11 '15 at 1:24
  • I thought you were trying to read a photoresistor. – Ignacio Vazquez-Abrams Jul 11 '15 at 1:25
  • 1
    Do you want to detect a current or a voltage? Why not just use a voltage divider to detect if the voltage is there? – Nick Gammon Jul 11 '15 at 3:05
  • 3
    White LED needs about 3V to operate. Here it eats all your breakfast. Short LED, short R4,. Make R2 say 1K. Connect A6 input to R2 to opto junction. connection. – Russell McMahon Jul 11 '15 at 3:22

Based on the revised information given above I present a different answer. Use the opto-coupler as shown here:

Your kettle LED will be in series with the optocoupler (note the polarity, not reversed like in your question).

If the LED is on the transistor in the PC817 will conduct and the Arduino pin will be LOW. If the LED is off the transistor will not conduct and the Arduino pin will be HIGH.

enter image description here

Note: The Arduino pin will be the reverse of the kettle LED.

I'm leaving the other answer there because I think it is a reasonable answer to the question of "detect a voltage".

  • This works! Thanks for the help. I learned a good deal from both of these answers. – futurebird Jul 13 '15 at 16:04

Wouldn't this be simpler?

3.3v voltage detector

Note: amended answer increases R1 to 10 k.

The 10 k resistor limits current to 0.17 mA. The 3.3 V zener diode clamps the input voltage to 3.3 V (I measured 2.3 V on mine so that is well within spec). The other end of the zener diode goes to the Arduino ground pin.

I originally had R1 as 1 k however if you had a high voltage input (like 20 V) it didn't quite clamp the pin to 3.3 V (more like 3.8 V). This is a bit high for an input pin, so I tried 10 k instead.

This gives:

  • For an input voltage of 5 V -> 2.3 V on the Arduino input
  • For an input voltage of 10 V -> 2.6 V on the Arduino input
  • For an input voltage of 20 V -> 2.9 V on the Arduino input
  • For an input voltage of 30 V -> 3.1 V on the Arduino input

This is all within spec for the Arduino.

Now the question is, will 2.3 V on the input pin register as HIGH? The answer is "yes" because high is considered to be 0.6 * VCC.

3.3 * 0.6 = 1.98

Thus any voltage of 1.98 or above is considered HIGH, and it will successfully read 2.3 V as high.

  • What is the zener diode connected to? If there is a voltage spike what happens? – futurebird Jul 11 '15 at 3:29
  • 1
    It's connected to ground (the triangle part). I tested with higher input voltages, and increased R1 to 10 k (from 1 k in my original answer). That clamped input voltages as high as 30 V to a safe level. – Nick Gammon Jul 11 '15 at 3:53
  • this won't work. it triggers the device to turn on and off. I can't ground the 5v signal except using the ground line associated with it. I tried a voyage divider which is a similar concept and that didn't work. – futurebird Jul 11 '15 at 21:52
  • I'm really unclear about this. How does connecting it via a 10 k resistor "ground the 5 V signal"? Can you describe your set-up more completely? Are you saying the ground from your device, and the ground from the Arduino, need to be separate? What is this device exactly? In your question, your images seems to show an LED (is this the device?) wired backwards in polarity to the opto-coupler you are using. – Nick Gammon Jul 11 '15 at 22:07
  • The device is a kettle. it has a 5v board with the on off buttons and temp display. I have successfully emulated the momentary button presses the turn the kettle on and off with a relay via Internet. but I need to know if it worked. I also need to know if the kettle is in an on state due to a manual button press. these cables are two of five cables that form the the input output for the 5v board. every time my micro reads it triggers the kettle to turn on or off. – futurebird Jul 11 '15 at 22:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.