Limit Switch

I’m trying to test a rev robotics magnetic limit switch and it doesn’t work.

Here is the link: http://www.revrobotics.com/rev-31-1462/

Here is the code

/*----------------------------------------------------------------------------*/
/* Copyright (c) 2018 FIRST. All Rights Reserved.                             */
/* Open Source Software - may be modified and shared by FRC teams. The code   */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project.                                                               */
/*----------------------------------------------------------------------------*/

package frc.robot;

import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;

/**
 * The VM is configured to automatically run this class, and to call the
 * functions corresponding to each mode, as described in the TimedRobot
 * documentation. If you change the name of this class or the package after
 * creating this project, you must also update the build.gradle file in the
 * project.
 */
public class Robot extends TimedRobot {
  /**
   * This function is run when the robot is first started up and should be used
   * for any initialization code.
   */

  DigitalInput forearm_LimitSwitchUp; 

  @Override
  public void robotInit() {

    forearm_LimitSwitchUp = new DigitalInput(0);

  }

  @Override
  public void autonomousInit() {
  }

  @Override
  public void autonomousPeriodic() {
  }

  @Override
  public void teleopInit() {
  }

  @Override
  public void teleopPeriodic() {

    if (!forearm_LimitSwitchUp.get())
      {
        SmartDashboard.putBoolean("Forearm Limit Switch", forearm_LimitSwitchUp.get());
      }

  }

  @Override
  public void testInit() {
  }

  @Override
  public void testPeriodic() {
  }

}

Is the limit switch plugged into DIO 0 on the roboRIO?

Does the switch work when you test it with a multimeter?

How is is connected? I believe the Roborio is active low meaning you should be connected to the ground and signal. (Page 15) http://www.ni.com/pdf/manuals/374474a.pdf When switch is closed you will get a false and when open you get true.

Yes, it is connected to the DIO 0. How do I test the limitswitch with the multimeter?

Set the multimeter to continuity mode (aka beep mode). Touch one lead to signal (blue) and one to ground (black). If it beeps when the magnet is close and stops beeping when you remove the magnet, it’s working. The sensor should also have a light that turns on when the magnet is close and off when it’s removed.

Are you using the premade PWM adapter or did you make your own?

It doesn’t beep. Im using the premade PWM adpater and a homemade pwm cable to extend it.

If you plug in the PWM wire into DIO 0 and put a magnet near the sensor, does the LED on the sensor light up?

Also, try unplugging the sensor from your cable and doing a continuity test between the ground and a signal pin (e.g. the two at the ends) and see if it beeps when the magnet is brought close. If it doesn’t beep, you have a bad switch. If it does beep, time to check the cable for continuity.

Sorry, thought these were reed switches.

The Magnetic Limit Switch needs power to operate, so unplugging it completely won’t show you anything.

@Dacosta Can you confirm whether or not the LED is illuminated when the magnet is in range? The LED is part of the signal path so it is a reliable indicator if the sensor is working.

To use a multimeter you would need to keep the sensor plugged in to the DIO and measure the voltage between the GND pin and Signal Pin. You’ll measure 0V when triggered and 5V when not triggered. With a PWM extension, you can probably get your probes on the little bit of exposed metal on the connector housings.

Feel free to send a picture of your wiring.

It all worked. Thanks!

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.