Skip to content

Commit d834eab

Browse files
committed
0.1.0 TCRT5000
1 parent 30e7eef commit d834eab

File tree

14 files changed

+453
-0
lines changed

14 files changed

+453
-0
lines changed

libraries/TCRT5000/.arduino-ci.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
platforms:
2+
rpipico:
3+
board: rp2040:rp2040:rpipico
4+
package: rp2040:rp2040
5+
gcc:
6+
features:
7+
defines:
8+
- ARDUINO_ARCH_RP2040
9+
warnings:
10+
flags:
11+
12+
packages:
13+
rp2040:rp2040:
14+
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
15+
16+
compile:
17+
# Choosing to run compilation tests on 2 different Arduino platforms
18+
platforms:
19+
- uno
20+
# - due
21+
# - zero
22+
# - leonardo
23+
- m4
24+
- esp32
25+
- esp8266
26+
# - mega2560
27+
- rpipico
28+
29+
libraries:
30+
- "printHelpers"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# These are supported funding model platforms
2+
3+
github: RobTillaart
4+
custom: "https://www.paypal.me/robtillaart"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: Arduino-lint
2+
3+
on: [push, pull_request]
4+
jobs:
5+
lint:
6+
runs-on: ubuntu-latest
7+
timeout-minutes: 5
8+
steps:
9+
- uses: actions/checkout@v4
10+
- uses: arduino/arduino-lint-action@v1
11+
with:
12+
library-manager: update
13+
compliance: strict
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Arduino CI
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
runTest:
7+
runs-on: ubuntu-latest
8+
timeout-minutes: 20
9+
10+
steps:
11+
- uses: actions/checkout@v4
12+
- uses: ruby/setup-ruby@v1
13+
with:
14+
ruby-version: 2.6
15+
- run: |
16+
gem install arduino_ci
17+
arduino_ci.rb
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: JSON check
2+
3+
on:
4+
push:
5+
paths:
6+
- '**.json'
7+
pull_request:
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
timeout-minutes: 5
13+
steps:
14+
- uses: actions/checkout@v4
15+
- name: json-syntax-check
16+
uses: limitusus/json-syntax-check@v2
17+
with:
18+
pattern: "\\.json$"

libraries/TCRT5000/CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Change Log TCRT5000
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](http://keepachangelog.com/)
6+
and this project adheres to [Semantic Versioning](http://semver.org/).
7+
8+
9+
## [0.1.0] - 2025-06-20
10+
- initial version
11+

libraries/TCRT5000/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025-2025 Rob Tillaart
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

libraries/TCRT5000/README.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
2+
[![Arduino CI](https://github.com/RobTillaart/TCRT5000/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
3+
[![Arduino-lint](https://github.com/RobTillaart/TCRT5000/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/TCRT5000/actions/workflows/arduino-lint.yml)
4+
[![JSON check](https://github.com/RobTillaart/TCRT5000/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/TCRT5000/actions/workflows/jsoncheck.yml)
5+
[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/TCRT5000.svg)](https://github.com/RobTillaart/TCRT5000/issues)
6+
7+
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/TCRT5000/blob/master/LICENSE)
8+
[![GitHub release](https://img.shields.io/github/release/RobTillaart/TCRT5000.svg?maxAge=3600)](https://github.com/RobTillaart/TCRT5000/releases)
9+
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/TCRT5000.svg)](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+

libraries/TCRT5000/TCRT5000.h

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#pragma once
2+
//
3+
// FILE: TCRT5000.h
4+
// AUTHOR: Rob Tillaart
5+
// DATE: 2025-02-23
6+
// VERSION: 0.1.0
7+
// PURPOSE: Arduino library for the TCRT5000 reflective optical sensor (IR).
8+
// URL: https://github.com/RobTillaart/TCRT5000
9+
//
10+
11+
12+
#include "Arduino.h"
13+
14+
15+
#define TCRT5000_LIB_VERSION (F("0.1.0"))
16+
17+
#ifndef TCRT5000_DEFAULT_THRESHOLD
18+
#define TCRT5000_DEFAULT_THRESHOLD 500
19+
#endif
20+
21+
22+
class TCRT5000
23+
{
24+
public:
25+
TCRT5000(uint8_t analogPin)
26+
{
27+
_pin = analogPin;
28+
}
29+
30+
int read()
31+
{
32+
_lastRead = analogRead(_pin);
33+
return _lastRead;
34+
}
35+
36+
int lastRead()
37+
{
38+
return _lastRead;
39+
}
40+
41+
void setThreshold(int threshold)
42+
{
43+
_threshold = threshold;
44+
}
45+
46+
int getThreshold()
47+
{
48+
return _threshold;
49+
}
50+
51+
bool aboveThreshold()
52+
{
53+
return this->read() > _threshold;
54+
}
55+
56+
bool belowThreshold()
57+
{
58+
return this->read() <= _threshold;
59+
}
60+
61+
private:
62+
uint8_t _pin;
63+
int _threshold = TCRT5000_DEFAULT_THRESHOLD;
64+
int _lastRead = 0;
65+
};
66+
67+
68+
// -- END OF FILE --
69+
70+
71+
72+
73+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
//
3+
// FILE: TCRT5000_demo.ino
4+
// AUTHOR: Rob Tillaart
5+
// PURPOSE: test basic behaviour and performance
6+
// URL: https://github.com/RobTillaart/TCRT5000
7+
8+
9+
#include "TCRT5000.h"
10+
11+
12+
TCRT5000 tcrt(14);
13+
14+
15+
void setup()
16+
{
17+
Serial.begin(115200);
18+
Serial.println();
19+
Serial.println(__FILE__);
20+
Serial.print("TCRT5000_LIB_VERSION: ");
21+
Serial.println(TCRT5000_LIB_VERSION);
22+
Serial.println();
23+
24+
tcrt.setThreshold(250);
25+
}
26+
27+
28+
void loop()
29+
{
30+
if (tcrt.belowThreshold())
31+
{
32+
Serial.println(tcrt.lastRead());
33+
}
34+
delay(25);
35+
}
36+
37+
38+
// -- END OF FILE --

0 commit comments

Comments
 (0)