Mini Limit Switch 5A 250V Documentation
The Mini Limit Switch 5A 250V is a compact and versatile switch designed for use in a variety of IoT applications. It features a maximum current rating of 5A and a voltage rating of 250V, making it suitable for low-to-medium power devices. This switch has a built-in push-button mechanism, allowing it to be used as a manual trigger or as an automatic sensor in robotic, automation, and other IoT projects.
The Mini Limit Switch 5A 250V has three terminals:
COM (Common): The common terminal is connected to the normally closed (NC) and normally open (NO) terminals.
NC (Normally Closed): The normally closed terminal is connected to the COM terminal when the switch is not pressed.
NO (Normally Open): The normally open terminal is connected to the COM terminal when the switch is pressed.
Example 1: Basic On/Off Control using Arduino
This example demonstrates how to use the Mini Limit Switch 5A 250V to control an LED connected to an Arduino board.
```c++
const int ledPin = 13; // LED connected to digital pin 13
const int switchPin = 2; // Mini Limit Switch connected to digital pin 2
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(switchPin, INPUT);
}
void loop() {
int switchState = digitalRead(switchPin);
if (switchState == HIGH) {
digitalWrite(ledPin, HIGH); // Turn on the LED when the switch is pressed
} else {
digitalWrite(ledPin, LOW); // Turn off the LED when the switch is not pressed
}
}
```
Example 2: Automation using Raspberry Pi
This example shows how to use the Mini Limit Switch 5A 250V to trigger a Python script on a Raspberry Pi when the switch is pressed.
```python
import RPi.GPIO as GPIO
import time
# Set up GPIO mode
GPIO.setmode(GPIO.BCM)
# Set up the Mini Limit Switch pin as an input
switch_pin = 17
GPIO.setup(switch_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
while True:
if GPIO.input(switch_pin) == False: # Switch is pressed
print("Switch is pressed!")
# Execute your Python script or code here
time.sleep(0.5) # Debounce time
```
Example 3: IoT Application using ESP32
This example demonstrates how to use the Mini Limit Switch 5A 250V to send a notification to a webhook when the switch is pressed, using an ESP32 board.
```c++
#include <WiFi.h>
#include <HTTPClient.h>
const char ssid = "your_wifi_ssid";
const char password = "your_wifi_password";
const char webhookUrl = "https://example.com/webhook";
const int switchPin = 32; // Mini Limit Switch connected to GPIO 32
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
pinMode(switchPin, INPUT);
}
void loop() {
int switchState = digitalRead(switchPin);
if (switchState == HIGH) {
Serial.println("Switch is pressed!");
// Send a notification to the webhook
HTTPClient http;
http.begin(webhookUrl);
int responseCode = http.POST("Switch is pressed!");
http.end();
delay(1000);
}
}
```
Note: In these examples, you may need to adjust the pin numbers and configurations according to your specific board and setup.