Skip to content
Intermediate · 5 of 720 minintermediate

Introduction to Sensors

Understand the basics of hardware sensors in FTC, focusing on Digital vs Analog, and how to initialize them in your code.

By the end you can

  • Understand the difference between Digital and Analog sensors.
  • Learn how to use DigitalChannel in the HardwareMap.
  • Understand Normally Open vs Normally Closed states.
On this page · 4 sections

Robots are blind until you give them sensors. While we've used Odometry and Encoders to tell the robot where it is, we need different types of sensors to tell the robot what is happening inside or around it.

For example, how does the robot know if it has successfully collected a game piece? How does an elevator know when it has safely reached the bottom?

How To Program REV Touch Sensors· Brogan M. PrattWatch on YouTube

Digital vs Analog

There are two primary categories of sensors in FTC:

  1. Analog Sensors: These sensors return a continuous range of values. For example, a Distance Sensor might return 12.5 cm or 4.2 cm. A Color Sensor might return varying levels of Red, Green, and Blue light.
  2. Digital Sensors: These sensors are binary. They only ever return true or false (ON or OFF, HIGH or LOW).

Our team relies heavily on Digital Sensors for our internal mechanisms because they are incredibly fast, reliable, and easy to program.

The two most common digital sensors are:

  • Limit Switches: A physical button that gets clicked when a moving part hits it.
  • Beam Breaks: A laser that shines across an empty space into a receiver. If a game piece blocks the laser, the sensor triggers.

Initializing a Digital Sensor

In FTC, both Limit Switches and Beam Breaks plug into the digital ports on your Control Hub. In your Java code, they are both represented by the exact same class: DigitalChannel.

Here is how you initialize a digital sensor in a Subsystem:

import com.qualcomm.robotcore.hardware.DigitalChannel;
import com.qualcomm.robotcore.hardware.HardwareMap;
 
public class MySubsystem {
    
    // 1. Declare the sensor
    private DigitalChannel limitSwitch;
 
    public MySubsystem(HardwareMap hardwareMap) {
        // 2. Map it to the name configured on the Driver Station phone
        limitSwitch = hardwareMap.get(DigitalChannel.class, "liftResetSensor");
        
        // 3. Set the mode! (Crucial for digital sensors)
        limitSwitch.setMode(DigitalChannel.Mode.INPUT);
    }
    
    public boolean isSwitchPressed() {
        // 4. Read the state. A REV Touch Sensor reads false when pressed
        //    (see "Normally Open vs Normally Closed" below), so flip it.
        return !limitSwitch.getState();
    }
}

[!IMPORTANT] You must always call .setMode(DigitalChannel.Mode.INPUT) on a digital sensor before using it. This tells the Control Hub to read electricity from the port, rather than sending electricity out (which would be OUTPUT).

Normally Open vs Normally Closed

When reading the .getState() of a digital sensor, you might assume that true means "pressed/blocked" and false means "empty/open". On a REV hub, it is usually the other way round.

Every digital port on the Control and Expansion Hub has a built-in pull-up resistor: with nothing pulling it down, the signal sits at 3.3V and reads true. A switch works by connecting the signal to ground, which reads false. So it depends on how the switch is wired:

  • Normally Open (NO): the switch is open until it is pressed. .getState() returns true normally, and false when pressed. The REV Touch Sensor and Magnetic Limit Switch both work this way — REV calls it active-low.
  • Normally Closed (NC): the switch connects the signal to ground until it is pressed. .getState() returns false normally, and true when pressed.

Many teams wire their limit switches Normally Closed as a safety feature. If the wire unplugs during a match, the pull-up makes the port read true — exactly what "pressed" reads — so the mechanism stops instead of driving into its hard stop. A Normally Open switch fails the other way: an unplugged switch reads true, which means "not pressed", forever.

Beam-break sensors vary by model, so check the datasheet. Either way, test before you trust it: print .getState() to telemetry, then press the switch or block the beam and watch it change.

// A REV Touch Sensor is active-low: false means pressed.
public boolean isTouchPressed() {
    return !touchSensor.getState();
}
 
// A Normally Closed limit switch: true means pressed — or unplugged, which is
// why it fails safe.
public boolean isLimitHit() {
    return limitSwitch.getState();
}

Check Your Understanding

Check yourself

Why is it a good safety practice for limit switches to be wired Normally Closed (NC)?

Finished this lesson?

Mark it complete to track your progress.