12V DC (maximum)
12V DC (maximum)
50 m
100 M
100,000 cycles
Environmental Characteristics
-20C to 70C
-40C to 85C
90% RH (non-condensing)
Applications
| The 4-Pins DIP Momentary Square Tactile Push Button Switch is suitable for a wide range of applications, including |
Electronic devices with limited space, such as wearable devices, smart home devices, and IoT projects.
Industrial control systems, robotics, and automation.
Medical devices, audio equipment, and other applications requiring tactile feedback and momentary action.
Packaging and Availability
The switch comes in a package of 10 pieces, making it an ideal option for prototyping, development, and production runs.
Component Documentation: 4-Pins DIP Momentary Square Tactile Push Button Switch 10 Pieces - 6x6x8mmOverviewThe 4-Pins DIP Momentary Square Tactile Push Button Switch is a compact, durable, and versatile switch designed for a wide range of IoT applications. With its small form factor (6x6x8mm) and DIP (Dual In-Line Package) design, it is easy to integrate into breadboards, PCBs, or other electronic circuits.PinoutThe switch has four pins, labeled as follows:Pin 1: NC (Normally Closed)
Pin 2: COM (Common)
Pin 3: NO (Normally Open)
Pin 4: GND (Ground)Operating PrincipleThe switch operates as a momentary switch, meaning it only closes the connection between the NO (Normally Open) and COM (Common) pins when pressed. When released, the connection opens, and the switch returns to its normal state.Code Examples### Example 1: Basic Switch Debouncing with ArduinoIn this example, we'll use the switch to trigger an LED to turn on and off. We'll also implement debouncing to prevent multiple switch registrations when the button is pressed.
```c++
const int switchPin = 2; // Pin connected to NO (Normally Open) of the switch
const int ledPin = 13; // Pin connected to an LEDbool switchState = false;
bool lastSwitchState = false;void setup() {
pinMode(switchPin, INPUT);
pinMode(ledPin, OUTPUT);
}void loop() {
bool currentState = digitalRead(switchPin);
if (currentState != lastSwitchState) {
delay(50); // Debouncing delay
if (currentState == HIGH) {
switchState = !switchState;
}
}
lastSwitchState = currentState;if (switchState) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
}
```
### Example 2: Raspberry Pi GPIO Interrupt with PythonIn this example, we'll use the switch to trigger a Python script when pressed. We'll use the RPi.GPIO library to set up an interrupt on the GPIO pin connected to the switch.
```python
import RPi.GPIO as GPIO
import timeGPIO.setmode(GPIO.BCM)
switch_pin = 17 # Pin connected to NO (Normally Open) of the switch
GPIO.setup(switch_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)def switch_callback(channel):
print("Switch pressed!")
# Add your custom code here, e.g., sending a notification or controlling an LEDGPIO.add_event_detect(switch_pin, GPIO.FALLING, callback=switch_callback, bouncetime=200)try:
while True:
time.sleep(1)
except KeyboardInterrupt:
GPIO.cleanup()
```
### Example 3: ESP32 Microcontroller with C++In this example, we'll use the switch to trigger a simple Wi-Fi network scan when pressed.
```c++
#include <WiFi.h>const int switchPin = 5; // Pin connected to NO (Normally Open) of the switchvoid setup() {
Serial.begin(115200);
pinMode(switchPin, INPUT);
}void loop() {
int switchState = digitalRead(switchPin);
if (switchState == HIGH) {
Serial.println("Switch pressed!");
// Perform Wi-Fi network scan
WiFi.scanNetworks();
delay(1000);
}
}
```
Additional NotesWhen using the switch with microcontrollers or single-board computers, ensure that the GPIO pin connected to the switch is configured correctly as an input.
In some cases, you may need to add a pull-up or pull-down resistor to the switch pin to ensure proper operation.
The above code examples assume that the switch is connected to a digital input pin. If you're using an analog input pin, you'll need to modify the code accordingly.