|
| 1 | + |
| 2 | +[](https://github.com/marketplace/actions/arduino_ci) |
| 3 | +[](https://github.com/RobTillaart/TCRT5000/actions/workflows/arduino-lint.yml) |
| 4 | +[](https://github.com/RobTillaart/TCRT5000/actions/workflows/jsoncheck.yml) |
| 5 | +[](https://github.com/RobTillaart/TCRT5000/issues) |
| 6 | + |
| 7 | +[](https://github.com/RobTillaart/TCRT5000/blob/master/LICENSE) |
| 8 | +[](https://github.com/RobTillaart/TCRT5000/releases) |
| 9 | +[](https://registry.platformio.org/libraries/robtillaart/TCRT5000) |
| 10 | + |
| 11 | + |
| 12 | +# TCRT5000 |
| 13 | + |
| 14 | +Arduino library for the TCRT5000 reflective optical sensor (IR). |
| 15 | + |
| 16 | + |
| 17 | +## Description |
| 18 | + |
| 19 | +**Experimental** |
| 20 | + |
| 21 | +The TCRT5000 sensor is an infrared reflective sensor. |
| 22 | +This library is written to use with a TCRT5000 breakout's analog output |
| 23 | +and handle a threshold in software. |
| 24 | + |
| 25 | +These breakouts have typical two outputs, a digital and an analog one. |
| 26 | +The analog output returns a "raw" signal strength. |
| 27 | +The digital output has a threshold level depending on a potentiometer |
| 28 | +which is typically set once. |
| 29 | + |
| 30 | +The library allows to set a threshold in software and compare if the |
| 31 | +raw signal is either above or below this set threshold. |
| 32 | +As the threshold is set in software it can be changed runtime. |
| 33 | +This can be useful to adapt e.g. to changing lighting conditions. |
| 34 | + |
| 35 | +As always feedback is welcome. |
| 36 | + |
| 37 | + |
| 38 | +Uses analog output. |
| 39 | + |
| 40 | + |
| 41 | +### Related |
| 42 | + |
| 43 | +- https://github.com/RobTillaart/PIR |
| 44 | + |
| 45 | + |
| 46 | +## Interface |
| 47 | + |
| 48 | +```cpp |
| 49 | +#include "TCRT5000.h" |
| 50 | +``` |
| 51 | + |
| 52 | +### Base |
| 53 | + |
| 54 | +- **TCRT5000(uint8_t analogPin)** |
| 55 | +- **int read()** |
| 56 | +- **int lastRead()** |
| 57 | + |
| 58 | +### Threshold |
| 59 | + |
| 60 | +Default threshold **TCRT5000_DEFAULT_THRESHOLD (500)**. |
| 61 | +This is about 50% of the UNO R3 ADC, so you might need to change this. |
| 62 | + |
| 63 | +- **void setThreshold(int threshold)** idem |
| 64 | +- **int getThreshold()** returns set value or the default. |
| 65 | +- **bool aboveThreshold()** reads the sensor and returns true is above |
| 66 | +the set (or default) threshold. |
| 67 | +- **bool belowThreshold()** reads the sensor and returns true is below |
| 68 | +or equal to the set (or default) threshold. |
| 69 | + |
| 70 | + |
| 71 | +## Future |
| 72 | + |
| 73 | +#### Must |
| 74 | + |
| 75 | +- improve documentation |
| 76 | + |
| 77 | +#### Should |
| 78 | + |
| 79 | +- add examples |
| 80 | + |
| 81 | +#### Could |
| 82 | + |
| 83 | +- compare to threshold, (use case?) |
| 84 | + - **int absoluteTH()** == read() - threshold; |
| 85 | + - **float relativeTH()** == ((read() - threshold) x 1.0)/ threshold; |
| 86 | + - **float percentageTH()** == 100 x relativeTH(); |
| 87 | + |
| 88 | +#### Wont |
| 89 | + |
| 90 | +- convert to distance |
| 91 | + - depends on a lot of factors. |
| 92 | + |
| 93 | +## Support |
| 94 | + |
| 95 | +If you appreciate my libraries, you can support the development and maintenance. |
| 96 | +Improve the quality of the libraries by providing issues and Pull Requests, or |
| 97 | +donate through PayPal or GitHub sponsors. |
| 98 | + |
| 99 | +Thank you, |
| 100 | + |
| 101 | + |
0 commit comments