3 Pin Toggle Switch (3A 230V) Documentation
The 3 Pin Toggle Switch is a electrical component designed for switching AC loads up to 3A and 230V. This switch is commonly used in IoT projects to control high-power devices such as lamps, motors, and pumps. The switch has three pins: one common pin and two output pins.
Pin 1: Common (COM)
Pin 2: Normally Open (NO)
Pin 3: Normally Closed (NC)
The 3 Pin Toggle Switch works by connecting the common pin (COM) to the power source, and the normally open (NO) and normally closed (NC) pins to the load. When the switch is toggled, the connection between the COM pin and the NO/NC pins is reversed, switching the load on or off.
### Example 1: Controlling a Lamp using Arduino
In this example, we will use an Arduino board to control a lamp using the 3 Pin Toggle Switch.
3 Pin Toggle Switch (3A 230V)
Arduino Board (e.g. Arduino Uno)
Lamp (up to 3A 230V)
Jumper wires
Code:
```c++
const int switchPin = 2; // pin connected to the switch
const int lampPin = 13; // pin connected to the lamp
void setup() {
pinMode(switchPin, INPUT);
pinMode(lampPin, OUTPUT);
}
void loop() {
int switchState = digitalRead(switchPin);
if (switchState == HIGH) {
digitalWrite(lampPin, HIGH); // turn the lamp on
} else {
digitalWrite(lampPin, LOW); // turn the lamp off
}
delay(50);
}
```
Explanation:
In this example, we connect the switch to digital pin 2 of the Arduino board. We then read the state of the switch using the `digitalRead()` function. If the switch is in the HIGH state (i.e. toggle is up), we set the lamp pin (connected to digital pin 13) to HIGH, turning the lamp on. Otherwise, we set the lamp pin to LOW, turning the lamp off.
### Example 2: Controlling a Motor using Raspberry Pi
In this example, we will use a Raspberry Pi to control a motor using the 3 Pin Toggle Switch.
3 Pin Toggle Switch (3A 230V)
Raspberry Pi (e.g. Raspberry Pi 4)
Motor (up to 3A 230V)
Jumper wires
Relay module (optional)
Code:
```python
import RPi.GPIO as GPIO
# Set up GPIO mode
GPIO.setmode(GPIO.BCM)
# Define the pin connected to the switch
switch_pin = 17
# Define the pin connected to the motor (or relay module)
motor_pin = 23
# Set up the pins as inputs and outputs
GPIO.setup(switch_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(motor_pin, GPIO.OUT)
try:
while True:
switch_state = GPIO.input(switch_pin)
if switch_state:
GPIO.output(motor_pin, GPIO.HIGH) # turn the motor on
else:
GPIO.output(motor_pin, GPIO.LOW) # turn the motor off
time.sleep(0.1)
except KeyboardInterrupt:
GPIO.cleanup()
```
Explanation:
In this example, we connect the switch to GPIO pin 17 of the Raspberry Pi. We then read the state of the switch using the `GPIO.input()` function. If the switch is in the HIGH state (i.e. toggle is up), we set the motor pin (connected to GPIO pin 23) to HIGH, turning the motor on. Otherwise, we set the motor pin to LOW, turning the motor off. Note that if you're using a relay module, you'll need to connect the motor to the relay module and configure the relay module accordingly.