Inexpensive HC-SR04 ultrasonic sensors [[Image(https://www.robotshop.com/media/catalog/product/cache/image/625x625/9df78eab33525d08d6e5fb8d27136e95/h/c/hc-sr04-ultrasonic-range-finder-2.png,240px,right)]] are helpful for learning about sensors and making basic robots more interactive. Every team should have a box of sensors and cables ready to connect to a roboRIO. The sensors are cheap and plentiful; the main obstacle is usually cabling and although students can crimp nice new cables with locking connectors, for many purposes, it is quicker and easier to make cables using off-the-shelf materials; it takes only a few minutes to wire them as needed and this is something rookie students can do without special training and minimal supervision to get comfortable with wiring. It also avoids most of the hassle associated with poor crimps. Materials Needed: - One HC-SR04 sensor (cost: [https://www.aliexpress.com/item/Free-shipping-1pcs-Ultrasonic-Module-HC-SR04-Distance-Measuring-Transducer-Sensor-for-Arduino-Samples-Best-prices/690139020.html $0.70] - [https://www.amazon.com/Ultrasonic-LGDehome-Measuring-Distance-Transmitter/dp/B07558LH2P $1.50]) - One 4-pin female-to-female dupont jumper wires (cost: [https://www.aliexpress.com/item/10PCS-LOT-2P-3P-5P-6P-7P-8P-9P-10P-Pin-Female-To-Female-Connector-with/32850724255.html $0.38] - [https://www.amazon.com/gp/product/B00KWA1UWK $1.20]) - Two 3-pin female dupont shell/housings (less than [https://www.aliexpress.com/item/For-dupont-connector-6pin-single-row-2-54mm-for-dupont-plastic-shell-through-hole-100pcs-lot/32637991458.html $0.02] each or from an [https://www.amazon.com/100pcs-Dupont-Jumper-Housing-Connector/dp/B07H19SX83 amazon/US supplier]) Everything is available from Amazon, [https://www.aliexpress.com AliExpress], Gearbest, Banggood, etc. depending on how fast you need it. Instructions for students: Using [https://www.amazon.com/Marrywindix-Precision-Anti-static-Electronics-Jewelry-making/dp/B00DVIEJ14 sharp tweezers] or the tip of a pointy knife or small screwdriver, remove the two black plastic shell/housings from the 4-wire cable: slightly lift the black tabs that retain each wire in the connector and slide the wires out so you're left with a 4-wire bundle and two 4-pin shells. Watch [https://www.youtube.com/watch?v=-InoAbkNVdQ this video] to see how it's done. 1. Reinsert the wires from one end of the 4-wire bundle into one of the 4-pin shells in this order: Red(Vcc), White(Trig), Yellow(Echo), Black(Gnd). 2. Reinsert 3 of the 4 wires on the other end of the bundle into a 3-pin shell in this order: Black (Gnd), Red (5v), Yellow (S) and label it A 3. Reinsert the last wire into one end of another 3-pin shell: White (S), Empty, Empty and label it B 4. You can discard or save the left-over 4-pin shell housing. Use the new cable to connect the ultrasonic sensor to the RoboRIO as follows: 1. Plug the 4-pin connector into the HC-SR04 with the Red wire on the Vcc pin and the Black wire on the Gnd pin - this is important because the sensor will be destroyed if you connect it backwards. 2. Plug connector A into one of the DIO ports (let's say DIO 0) with the black wire on the OUTSIDE edge of the roboRIO 3. Plug connector B into another DIO port (let's say DIO 1) with the white wire towards the INSIDE edge of the roboRIO You can use the ultrasonic sensor in your programs by creating an Ultrasonic object. WPILib already provides an [http://first.wpi.edu/FRC/roborio/release/docs/java/edu/wpi/first/wpilibj/Ultrasonic.html Ultrasonic class] that makes things easy. A sample snippet is below: {{{ import edu.wpi.first.wpilibj.Ultrasonic; public class Robot extends IterativeRobot { private Ultrasonic ultrasonic; @Override public void robotInit() { ultrasonic = new Ultrasonic(1,0); // trig, echo ultrasonic.setAutomaticMode(true); ultrasonic.setEnabled(true); } @Override public void teleopPeriodic() { double range = ultrasonic.getRangeInches(); // do something with the range } } }}} Students should first get comfortable using the sensor and displaying the range readings on the console, a good next exercise is to add collision avoidance to a robot. * [https://www.mouser.com/ds/2/813/HCSR04-1022824.pdf HC-SR04 Datasheet] * Mounting solutions * Acrylic mounts from [https://www.amazon.com/HC-SR04-Cartoon-Ultrasonic-Distance-Mounting/dp/B01MRHKD1S amazon] * Printable models from [https://www.thingiverse.com/tag:HC-SR04 thingverse]