Last Updated: 01/12/2021
Photointerrupter HY301
Components >> Photointerrupter HY301
Photointerrupter HY301
Photointerrupters pass an IR beam across a slot to a receiver. When the path is blocked the receiver output value (analogue) changes.
They are extrememly accurate so very useful for using as an indexing point for a stepper motor,
This is one of the components that I am using for my model railway DCC turntable project.
This tutorial will be based on the HY301 Photointerrupter although the code should work with models.
Components HY301 Photointerrupter
2 x 330 ohm resistors
Arduino Uno
Connections:
Pin 1 (H) Connect to pin A0 on Arduino and connect to Arduino Gnd through a 330OHM resistor
Pin 2 (Y) Connect to Arduino 5v
Pin 3 Connect to Arduino 5v through a 330ohm resistor
Pin 4 Connects to Arduino GND
As shown in photos below
Example 1: PhotoInterrupterHY301_21_test.ino
Click to Download code: PhotoInterrupterHY301_21_test.ino
NOTE: If the slot is blocked by a solid item, something like metal, the reading will drop to to Zero, however if the material is slightly opaque such as certain plastics the value may not drop totally to Zero as some light passes through the plastic.
Also in use try to block the whole slot at once so keep the material as square to the slot as possible for the best results.
/* 01/12/2021
PhotoInterrupterHY301_21_test
Simple Sketch to show the photointerupter is working
*/
//Variable that will hold the analog reading from Arduino pin A0
int photointerrupterState;
void setup() {
Serial.begin(9600);
Serial.print("PhotoInterrupterHY301_21_test");
}
void loop() {
photointerrupterState = analogRead(A0);
Serial.println(photointerrupterState);
delay(500);
}
Additional Resource Links
Functions 3 : analoglRead() Reading an Analog pin, converting to Voltage 03/09/2021
Comments
This site has been designed to be child friendly, this means that comments cannot be added to videos or directly to the site. To add a comment or ask a question please email the address in this image: and use Photointerrupter HY301 as a reference.