Overview
An optical reflective sensor is a composite electronic device with two elements - an IR LED and an IR photo-transistor. The IR LED blasts light, and when something bounces the light back to the photo-transistor, the transistor turns on and the amount of current flowing through it increases.
This makes the sensor great at detecting when something is in front of the sensor: when nothing is there the IR light never gets reflected back and the transistor stays off.
We have two versions of this sensor that are 'breadboard' friendly, the ITR20001 and a chunky all-in-one Infrared Reflective Sensor, but both are tough to mount, and require wiring up with resistors to get working. To make usage super fast and no-soldering-or-breadboarding-required, the Adafruit STEMMA Reflective Photo Interrupt Sensor is ready to go out of the box.
Power it with 3 to 5V DC and read the signal off the output pin to quickly detect reflective surfaces. A green LED tells you that the board is powered, and a red LED will light up to let you know when the phototransistor is activated. (Both LEDs can be disabled).
Onboard we have a TCRT1000 right-angle sensor module. A potentiometer allows adjustment of how bright the IR emitter is, turn it all the way down for about 10mA, turn it all the way up for about 100mA. Then the receiving phototransistor is biased with a 10K pullup.
When no IR light is detected, the output signal pin is high. When IR is bounced back, the voltage will drop down towards 0V.
This board has a simple plug-and-play JST PH (2mm pitch) input connector for solderless use. For use with a Circuit Playground or micro:bit, this JST to alligator-clip cable works best. Red is power, ground is black and signal is white.
For use with a breadboard, try this JST to male/plug-header. (We also have a socket-header cable if you want).
Page last edited April 08, 2024
Text editor powered by tinymce.
Pinouts
Power Pins
- VIN - this is the power pin. To power the board, give it the same power as the logic level of your microcontroller - e.g. for a 5V microcontroller like Arduino, use 5V.
- GND - common ground for power and logic.
Signal Output
- SIG - this is the output signal from the TCRT1000. When no IR light is detected by the TCRT1000, the output signal pin is high. When IR light is bounced back, the voltage will drop down towards 0V.
STEMMA JST PH
-
STEMMA JST PH - 2mm pitch STEMMA JST port for use with 3-pin STEMMA JST PH cables. It has connections for:
- GND - common ground for power and data. It is the black wire on the JST PH cable.
- VIN/V+ - power input for the TCRT1000. It is the red wire on the JST PH cable.
- SIG/In - signal to your microcontroller. It is the white wire on the JST PH cable.
Potentiometer
In the center of the board is a small potentiometer. It allows adjustment of how bright the IR emitter is. When it is turned all the way down it has a current of about 10mA, decreasing the sensitivity. When it is turned all the way up it has a current of about 100mA, increasing the sensitivity.
Signal LED and Jumper
- Signal LED - to the left of the JST PH connector is the signal LED, labeled Sig. It is the red LED. It will light up when an object is detected by the TCRT1000.
- LED jumper - in the lower center portion on the back of the board is a jumper for the signal LED. It is labeled Sig on the board silk. If you want to disable the signal LED, cut the trace on this jumper.
Power LED and Jumper
- Power LED - to the right of the JST PH connector is the power LED, labeled ON. It is the green LED.
- LED jumper - in the top center portion on the back of the board is a jumper for the power LED. It is labeled On on the board silk. If you want to disable the power LED, cut the trace on this jumper.
Page last edited April 08, 2024
Text editor powered by tinymce.
CircuitPython and Python
It's easy to use the STEMMA Reflective Photo Interrupt Sensor with CircuitPython and the digitalio core module. This module allows you to easily write Python code for accessing basic digital inputs and outputs.
You can use this driver with any CircuitPython microcontroller board or with a computer that has GPIO and Python thanks to Adafruit_Blinka, our CircuitPython-for-Python compatibility library.
CircuitPython Microcontroller Wiring
First wire up the sensor to your board exactly as follows. The following is the sensor wired to a Feather RP2040 with a JST PH cable.
-
Board 3V to sensor JST PH VIN (red wire)
-
Board GND to sensor JST PH GND (black wire)
- Board pin 5 to sensor JST PH SIG (white wire)
The following is the switch wired to a Feather RP2040 using a solderless breadboard:
-
Board 3V to sensor VIN (red wire)
-
Board GND to sensor GND (black wire)
- Board pin 5 to sensor SIG (white wire)
Python Computer Wiring
Since there are dozens of Linux computers/boards you can use, we will show wiring for Raspberry Pi. For other platforms, please visit the guide for CircuitPython on Linux to see whether your platform is supported.
Here's the Raspberry Pi wired to the sensor using a JST PH cable:
- Pi 3V to sensor JST PH VIN (red wire)
- Pi GND to sensor JST PH GND (black wire)
- Pi GPIO5 to sensor JST PH SIG (white wire)
Here is how you'll wire the sensor to a Raspberry Pi with a breadboard:
- Pi 3V to sensor VIN (red wire)
- Pi GND to sensor GND (black wire)
- Pi GPIO5 to sensor SIG (white wire)
CircuitPython Usage
To use with CircuitPython, you need to update code.py with the example script.
In the example below, click the Download Project Bundle button below to download the code.py file in a zip file. Extract the contents of the zip file, and copy the code.py file to your CIRCUITPY drive.
Python Usage
Once you have the library pip3 installed on your computer, copy or download the following example to your computer, and run the following, replacing code.py with whatever you named the file:
python3 code.py
Example Code
If running CircuitPython: Once everything is saved to the CIRCUITPY drive, connect to the serial console to see the data printed out!
If running Python: The console output will appear wherever you are running Python.
# SPDX-FileCopyrightText: 2023 Liz Clark for Adafruit Industries
#
# SPDX-License-Identifier: MIT
import time
import board
from digitalio import DigitalInOut, Direction, Pull
ir = DigitalInOut(board.D5)
ir.direction = Direction.INPUT
ir.pull = Pull.UP
while True:
if not ir.value:
print("object detected!")
else:
print("waiting for object...")
time.sleep(0.01)
The SIG output from the sensor is setup as a digital input. In the loop, if an input is detected object detected! is printed to the serial monitor. Otherwise waiting for object... is printed. You can experiment with the potentiometer position to increase and decrease the sensitivity of the sensor.
Page last edited April 08, 2024
Text editor powered by tinymce.
Arduino
Using the STEMMA Reflective Photo Interrupt Sensor with Arduino involves wiring up the sensor to your Arduino-compatible microcontroller and running the provided example code.
Wiring
Wire as shown for a 5V board like an Uno. If you are using a 3V board, like an Adafruit Feather, wire the board's 3V pin to the breakout VIN.
Here is an Adafruit Metro wired up to the sensor using a JST PH cable.
-
Board 5V to sensor JST PH VIN (red wire)
-
Board GND to sensor JST PH GND (black wire)
- Board pin 5 to sensor JST PH SIG (white wire)
Here is an Adafruit Metro wired up using a solderless breadboard:
-
Board 5V to sensor VIN (red wire)
-
Board GND to sensor GND (black wire)
- Board pin 5 to sensor SIG (white wire)
// SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries
//
// SPDX-License-Identifier: MIT
void setup() {
//start serial connection
Serial.begin(115200);
pinMode(5, INPUT_PULLUP);
}
void loop() {
int sensorVal = digitalRead(5);
if (sensorVal == LOW) {
Serial.println("object detected!");
} else {
Serial.println("waiting for object..");
}
delay(200);
}
Upload the sketch to your board and open up the Serial Monitor (Tools -> Serial Monitor) at 115200 baud. You'll see object detected! printed to the Serial Monitor if an input is detected. Otherwise waiting for object... is printed. You can experiment with the potentiometer position to increase and decrease the sensitivity of the sensor.
Page last edited April 08, 2024
Text editor powered by tinymce.
WipperSnapper
What is WipperSnapper
WipperSnapper is a firmware designed to turn any WiFi-capable board into an Internet-of-Things device without programming a single line of code. WipperSnapper connects to Adafruit IO, a web platform designed (by Adafruit!) to display, respond, and interact with your project's data.
Simply load the WipperSnapper firmware onto your board, add credentials, and plug it into power. Your board will automatically register itself with your Adafruit IO account.
From there, you can add components to your board such as buttons, switches, potentiometers, sensors, and more! Components are dynamically added to hardware, so you can immediately start interacting, logging, and streaming the data your projects produce without writing code.
If you've never used WipperSnapper, click below to read through the quick start guide before continuing.
Wiring
First, wire up an Adafruit STEMMA Reflective Photo Interrupt Sensor (TCTR1000) to your board exactly as follows.
Here is an example of the TCTR1000 wired to an Adafruit ESP32 Feather V2 using a STEMMA JST PH 2mm 3-Pin to Male Header Cable (no soldering required)
- Board 3V to sensor VIN (red wire on STEMMA)
- Board GND to sensor GND (black wire on STEMMA)
- Board A0 to sensor SIG (white wire on STEMMA)
Usage
Connect your board to Adafruit IO Wippersnapper and navigate to the WipperSnapper board list.
On this page, select the WipperSnapper board you're using to be brought to the board's interface page.
If you do not see your board listed here - you need to connect your board to Adafruit IO first.
On the device page, quickly check that you're running the latest version of the WipperSnapper firmware.
The device tile on the left indicates the version number of the firmware running on the connected board.
- If the firmware version is green with a checkmark - continue with this guide.
- If the firmware version is red with an exclamation mark "!" - update to the latest WipperSnapper firmware on your board before continuing.
With the sensor wired and device up-to-date, you're ready to add the sensor component to your board.
Click the New Component button or the + button to bring up the component picker.
Adafruit IO supports a large amount of components. To quickly find your sensor, type TCTR into the search bar, then select the TCTR1000 component.
On the component configuration page, the TCTR1000's pin option should be listed along with the sensor's settings. Set the pin to something appropriate for a digital input, for this example use the pin labelled D26 / (A0).
The Return Interval setting is specific to each sensor's measurements and allows toggling between periodic or reactive triggering.
The Return Interval's periodic option controls how often the Feather reads the TCTR1000 sensor and sends data to Adafruit IO. You can select intervals from every 30 seconds to every 24 hours. Another choice is "On Change." It immediately sends data to Adafruit IO when the sensor changes state.
For this example set the Return Interval to On Change, then click Create Component.
Your device interface should now show the sensor components you created. After the interval you configured elapses, WipperSnapper will automatically read values from the sensor(s) and send them to Adafruit IO.
Why Did I get a "Throttle Warning"?
This happens when you exceed the data limit. Adafruit IO's free plan allows 30 data points per minute, compared to 60 data points per minute IO Plus (Paid) plan.
If this happens to you, don't worry! Your device will resume sending data once it's back under the limit.
To view the logged data from the sensor, click the graph by the sensor's name.
Here, on the Feed Page, you can view and edit a feed's history, name, privacy, and related webhooks. If you want to learn more about how feeds work, check out this page.
Page last edited April 08, 2024
Text editor powered by tinymce.
Downloads
Page last edited April 08, 2024
Text editor powered by tinymce.