A compact rotary speed sensing module. This module incorporates an WYC-H206 infra-red sensor to sense a split object passing its IR emitter and receiver. It can be used in applications such as endstop sensing in mechanical devices such as CNC machines or 3D printers, or when used with a rotary encoder wheel, can be used for rotary speed sensing of motors and wheels.
The module has a single 3 pin 0.1” pitch header consisting of VCC & GND for power and a single digital schmitt triggered TTL output pin which signifies the sensor's current state. An onboard LED is also included as a visual indicator of the sensor's current state.
Specification:
Product code: HCMODU0240
Supply voltage: 3.3 to 5V
Slot width: 6mm
Dimensions ex header (LxWxH): 26.6 x 14.8 x 18.7mm
Mounting holes diameter: 3mm
Pinout:
OUT….Digital out (low = sensor interrupted)
VCC….3.3/5V
GND….Ground
Example Arduino Sketch:
- /* FILE: TMP102_Example.cpp
- DATE: 14/06/23
- VERSION: 1.0
- AUTHOR: Andrew Davies
- Library created by Hobby Components Ltd (HOBBYCOMPONENTS.COM)
- You may copy, alter and reuse this code in any way you like, but please leave
- reference to HobbyComponents.com in your comments if you redistribute this code.
- This software may not be used directly for the purpose of selling products that
- directly compete with Hobby Components Ltd's own range of products.
- THIS SOFTWARE IS PROVIDED "AS IS". HOBBY COMPONENTS MAKES NO WARRANTIES, WHETHER
- EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
- MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ACCURACY OR LACK OF NEGLIGENCE.
- HOBBY COMPONENTS SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR ANY DAMAGES,
- INCLUDING, BUT NOT LIMITED TO, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY
- REASON WHATSOEVER.
- */
- // Pin connected to the sensor's out pin. Must be an interrupt pin!
- #define SENSOR_PIN 2
- // Init variables used for pulse timing
- unsigned long newTime = 0, oldTime, pulseTime = 0;
- void setup()
- {
- Serial.begin(115200);
- pinMode(SENSOR_PIN, INPUT);
- attachInterrupt(digitalPinToInterrupt(SENSOR_PIN), isr, RISING);
- }
- void loop()
- {
- Serial.println(getRPM()); // Print out the current RPM
- delay(100); // Wait a little so not to flood the serial port
- }
- // Function to calculate the current RPM
- unsigned long getRPM(void)
- {
- // Only calculate RPM if the sensor has been triggered
- if(newTime)
- {
- // Calculate the pulse time in microseconds
- pulseTime = newTime - oldTime;
- // Check if we've had a recent update from the ISR and if not calculate
- // the pulse time based on the current time
- if(pulseTime < (micros() - newTime))
- {
- pulseTime = micros() - newTime;
- }
- // Return the new RPM
- return 60000000 / pulseTime;
- }else
- return 0; // The sensor has never been triggered so RPM = 0
- }
- // Interrupt service routine used to calculate the time
- // between each sensor trigger in microseconds
- void isr()
- {
- oldTime = newTime;
- newTime = micros();
- }
Libraries, example code, and diagrams are provided as an additional free service by Hobby Components and are not sold as part of this product. We do not provide any guarantees or warranties as to their accuracy or fitness for purpose.
Descriptions and diagrams on this page are copyright Hobby Components Ltd and may not be reproduced without permission.