Sensors
Line detector
An LED that lights when the sensor is over a black line. This is the eye of every line-following robot.
- Easy
- about 20 min
- Arduino Uno
- No soldering
- 7 parts
- 6 wires
- 17 lines of code
Opens this circuit, already wired, with the sketch loaded. Free, nothing to install.
Idea
The sensor shines infrared light down and measures how much comes back. Black tape reflects little, white paper a lot. Build this before a robot, to see what the sensor sees.
What you learn
Reading a digital sensor, and how a robot tells the line from the floor.
How it works
input
Infrared line sensor
decides
Arduino Uno
output
LED
Powered with 5 V from the Uno's USB cable. No battery and no soldering.
This circuit and sketch are run in the ManuStem simulator before the pack is published. Real parts vary between makers: follow the labels printed on your own module, not its position in the picture.
Parts
0 of 7 ready
No prices here: they change by shop and by week. Buy each part by its name and the note beside it.
You also need
A computer with Arduino IDE 2 installed (free)
3D wiring
One jumper per step. Unplug the USB cable while you wire.
Step 0 of 6
Lay out the parts
Push the small parts into the breadboard as shown. Nothing is connected yet.
All connections
line-detector.ino
// Line detector
// ManuStem Build Pack: https://stem.manusignal.com/packs/line-detector
const int IR_PIN = 2;
const int LED_PIN = 9;
void setup() {
pinMode(IR_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
}
void loop() {
if (digitalRead(IR_PIN) == HIGH) {
digitalWrite(LED_PIN, HIGH);
} else {
digitalWrite(LED_PIN, LOW);
}
}
Libraries
None. It uses only what the Arduino IDE has built in.
Uploading
- Open the sketch in Arduino IDE.
- Plug the Uno in with the USB cable.
- Tools > Board > Arduino Uno, then Tools > Port and choose the board's port.
- Press Upload (the arrow). Wait for “Done uploading”.