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… 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 publishes a wide range of writing and video content, including interviews and reporting on the maker market and the wider technology world. Our standards page is intended as a guide to best practices that Adafruit uses, as well as an outline of the ethical standards Adafruit aspires to. While Adafruit is not an independent journalistic institution, Adafruit strives to be a fair, informative, and positive voice within the community – check it out here:

Join Adafruit on Mastodon

Adafruit is on Mastodon, join in!

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, 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.

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!

Join over 36,000+ makers on Adafruit’s Discord channels and be part of the community!

CircuitPython – The easiest way to program microcontrollers –

Maker Business — “Packaging” chips in the US

Wearables — Enclosures help fight body humidity in costumes

Electronics — Transformers: More than meets the eye!

Python for Microcontrollers — Python on Microcontrollers Newsletter: Silicon Labs introduces CircuitPython support, and more! #CircuitPython #Python #micropython @ThePSF @Raspberry_Pi

Adafruit IoT Monthly — Guardian Robot, Weather-wise Umbrella Stand, and more!

Microsoft MakeCode — MakeCode Thank You!

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

New Products – Adafruit Industries – Makers, hackers, artists, designers and engineers! — #NewProds 7/19/23 Feat. Adafruit Matrix Portal S3 CircuitPython Powered Internet Display!

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


  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?

  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,, optocoupler for AC detection. its 47 cents.

  4. Oops, better make that the LTV-814, It has 2 diodes to sense AC voltages. 62 cents.

Sorry, the comment form is closed at this time.