Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

ASK AN EDUCATOR – “How can I measure AC voltage with my Arduino?”

Francisco asks:

Hi! Great job with ask an educator, just love it!

My question is, I want to read if a lamp in a 24 V alternating current circuit is on or off. I want to use an arduino, but I guess I have to do some kind of signal conditioning, any tips for breadbord testing?

Thank you! I am glad you like the posts!

Now, regarding the question. I have three methods you can employ to sense if your lamp is on or off, and each vary on how much hardware hacking you are looking to do. The first utilizes an opto-isolator to sense the presence of your AC voltage and convert it into a logic level (0 or 1) output that can be easily sensed by your Arduino. This is the most stable and easier to conceal method of the two. The second utilizes a relay, which activates when the lamp is turned on and is connected to the Arduino as you would a pushbutton. The third doesn’t actually interface with the lamp’s circuitry at all, rather relies on one of the Arduino’s ADCs and a photocell to sense a dramatic change in light intensity, indicating the lamp being turned on or off.

Sensing AC with an opto-isolator:

An opto-isolator or optocoupler is a electronic device that uses an LED and a phototransistor to electrically isolate two parts of a circuit. This comes in handy when interfacing microcontrollers with devices that produce a lot of electrical noise, or voltages that could be harmful. Digikey carries the HCPL-3700 which is, although a bit pricey, immediately capable of converting the presence of 5 – 240V AC/DC to a logic level output. In order to make a safe and stable circuit, I would recommend using series resistors for current protection on both the input and output as well as including the recommended 0.1uF filter. You can also complete the circuit using a cheaper isolator like the 4N25 and a few support components as the input is directly connected to the LED.

For more information, there is a nice overview and series of examples on W9XT’s HAM website.

There was a similar question to this on the Adafruit forums that might be of use as well.

Sensing AC with a relay:

A relay is an electro-mechanical device that physically switches its outputs based on the energized state of an electromagnetic coil. Relays typically have common(C), normally-closed (NC) and normally-open (NO) pins that refer to the state of connection relative to the state of the coil. If the relay is not powered, and your light is off, there will be an electrical connection between the C and NC pins. When the relay is powered, and your light is on, the electrical connection switches, connecting the C to the NO pin. These pins can then be connected to the Arduino in the same way you would connect a button. All you need to do is connect a pull-down resistor and an input to the C pin and connect the NO pin to VCC. When the power is supplied to the lamp, it will energize the relay’s coil and connect the NO pin to the C pin, thus changing the logic state from 0 to 1.

Sensing light with a photocell:

A photocell is a device that changes resistance in correlation to the quantity of light it is exposed to. As you are sensing the light from you lamp, I would recommend one used to sense frequencies in the visible light spectrum…..like these. The idea behind using a photocell for sensing the state of your lamp would be to continuously sense the ambient light level in the room. Then use software to implement a threshold that triggers when the light level jumps/drops. You should place the photocell as close to the lamp as possible in order to help eliminate false positives.

Adafruit happens to have a great tutorial and further explanation of the photocell on the adafruit learning system.

I hope these ideas have helped answer your question and good luck with your circuit!

Don’t forget, everyone is invited to ask a question!

Click here!

“Ask an Educator” questions are answered by Adam Kemp, a high school teacher who has been teaching courses in Energy Systems, Systems Engineering, Robotics and Prototyping since 2005.



Adafruit has had paid day off for voting for our team for years, if you need help getting that going for your organization, let us know – we can share how and why we did this as well as the good results. Here are some resources for voting by mail, voting in person, and some NY resources for our NY based teams as well. If there are additional resources to add, please let us know – adafruit.com/vote

Stop breadboarding and soldering – start making immediately! Adafruit’s Circuit Playground is jam-packed with LEDs, sensors, buttons, alligator clip pads and more. Build projects with Circuit Playground in a few minutes with the drag-and-drop MakeCode programming site, learn computer science using the CS Discoveries class on code.org, jump into CircuitPython to learn Python and hardware together, TinyGO, or even use the Arduino IDE. Circuit Playground Express is the newest and best Circuit Playground board, with support for CircuitPython, MakeCode, and Arduino. It has a powerful processor, 10 NeoPixels, mini speaker, InfraRed receive and transmit, two buttons, a switch, 14 alligator clip pads, and lots of sensors: capacitive touch, IR proximity, temperature, light, motion and sound. A whole wide world of electronics and coding is waiting for you, and it fits in the palm of your hand.

Join 24,000+ makers on Adafruit’s Discord channels and be part of the community! http://adafru.it/discord

Have an amazing project to share? The Electronics Show and Tell is every Wednesday at 7pm ET! To join, head over to YouTube and check out the show’s live chat – we’ll post the link there.

Join us every Wednesday night at 8pm ET for Ask an Engineer!

Follow Adafruit on Instagram for top secret new products, behinds the scenes and more https://www.instagram.com/adafruit/

CircuitPython – The easiest way to program microcontrollers – CircuitPython.org


Maker Business — To make it through a tough business cycle, layoffs should be a last resort

Wearables — Start with too much

Electronics — Desolder with… more solder!

Python for Microcontrollers — Python on Microcontrollers Newsletter: CircuitPython 6 beta 0, Discord 25k and much more! #Python #Adafruit #CircuitPython #CircuitPythonDay @micropython @ThePSF

Adafruit IoT Monthly — Mitigating Climate Change with IoT, LoRaWAN Gardens, and more!

Microsoft MakeCode — MakeCode and Wonder Woman 1984 Team Up

EYE on NPI — Maxim’s Himalaya uSLIC Step-Down Power Module #EyeOnNPI @maximintegrated @digikey

New Products – Adafruit Industries – Makers, hackers, artists, designers and engineers! — JP’s Product Pick of the Week — 4pm Eastern TODAY! 9/22/20 @adafruit @johnedgarpark #adafruit #newproductpick

Get the only spam-free daily newsletter about wearables, running a "maker business", electronic tips and more! Subscribe at AdafruitDaily.com !



4 Comments

  1. In the first scenario where should we put the 4n25, before the optocoupler or before the arduino? Also in the first example what are the support componentes that are refered?
    Best

  2. You may want to try salvaging an optocoupler from old or broken things. I’ve found quite a number of them that way.

  3. I use LTV-816, http://www.digikey.com/product-detail/en/LTV-816S-TA1/160-1892-1-ND/3306438, optocoupler for AC detection. its 47 cents.

  4. Oops, better make that the LTV-814, http://www.digikey.com/product-detail/en/LTV-814S-TA1/160-1891-1-ND/3306362. It has 2 diodes to sense AC voltages. 62 cents.

Sorry, the comment form is closed at this time.