Life is fantastic

Reading an H21A optical interruptor switch using an Arduino UNO - The simple way that really works

Written by Alain Sanguinetti no comments

About the Arduino and the H21A optical interruptor switch

Arduino is an open electronics development platform. It is widely used to power electronics projects. There are several boards that feature different capabilities. In my case, I am using an Arduino R3.

The H21A optical interruptor switch is a common piece of hardware. It is composed of an IR led and a photoresistor.

My goal is to use an Arduino to detect when the light is interrupted. As I am a newcomer to electronics and arduino, I started by looking on the internet for information on how to connect the two.

Some examples found on the internet

I found this search result to be relevant : http://www.electroschematics.com/10494/arduino-optical-position-rotary-encoder/

However, it did not worked, maybe because I did not had the recommended resistors at hand.

My solution

The solution that I found to be working is to simply connect the output pin of the H21A to a digital input pin of the Arduino. The trick is to declare the pin as "INPUT_PULLUP", this removes the need for a pull-up resistor ! :-)

Hope this helps !

Rss feed of the tag

© 2020 Alain Sanguinetti

Site édité par Alain Sanguinetti
Responsable de la publication : M. Sanguinetti

Site hébergé par OVH
2 rue Kellermann 59100 Roubaix
Tél. : +33 9 72 10 10 07