Sensor

๐Ÿšง Crash Switch

๐Ÿ“Œ Description

A crash switch is a simple mechanical sensor that detects collisions or impacts. When the robot bumps into something, the switch is pressed, sending a signal to the board.

๐ŸŽฏ Use

In our projects, crash switches are used to:

  • Detect when the robot hits an obstacle.
  • Trigger safety actions (like stopping motors).
  • Help robots navigate by knowing when theyโ€™ve reached a wall or barrier.

๐Ÿ‘‰ Think of the crash switch as the robotโ€™s bumper โ€” it feels when the robot crashes into something.

Module parameters

Pin name Description
G GND (Power Input Negative)
V VCC (Power Input Cathode)
S Digital signal pins
  • Supply voltage: 3.3V/5V
  • Connection: PH2.0 terminal wire
  • Installation method: double screw fixing

๐Ÿ–ฅ๏ธ Code Explanation

import machine
import time

pin17 = machine.Pin(17, machine.Pin.IN)    # Crash switch input
pin26 = machine.Pin(26, machine.Pin.OUT)   # LED output

while True:
    if pin17.value() == 1:                 # If no impact
        pin26.value(0)                     # LED OFF
        print('No impact detected')
    else:                                  # If impact detected
        pin26.value(1)                     # LED ON
        print('The sensor detected an impact.')
        time.sleep(1)                      # Wait 1 second

Step by Step

  1. import machine, time โ†’ Tools to control pins and add pauses.
  2. pin17 = machine.Pin(17, machine.Pin.IN) โ†’ Pin 17 reads the crash switch (input).
  3. pin26 = machine.Pin(26, machine.Pin.OUT) โ†’ Pin 26 controls the LED (output).
  4. while True: โ†’ Loop that repeats forever.
  5. if pin17.value() == 1: โ†’ No impact detected.
  6. pin26.value(0) โ†’ LED stays off.
  7. print('No impact detected') โ†’ Message shows on screen.
  8. else: โ†’ If the switch is pressed (impact).
  9. pin26.value(1) โ†’ LED turns on.
  10. print('The sensor detected an impact.') โ†’ Message shows on screen.
  11. time.sleep(1) โ†’ Small delay before checking again.

๐Ÿ‘‰ Together, this program makes the LED light up and print a message when the robot crashes into something.


โœ… Conclusion of the Test

  • If the LED stays off when thereโ€™s no impact, and turns on with a message when the robot hits something, the program is working correctly.
  • This test shows how the robot can sense collisions and react with an output (LED + message).
  • Later, instead of just turning on a light, the crash switch could stop motors, reverse direction, or trigger alarms when an impact is detected.
On this page