Advertisement
microrobotics

MTS-302 Switch 250V 3A, 3P3T, 3 Position

May 10th, 2023
1,735
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. The MTS-302 is a simple mechanical switch and doesn't directly interface with code. However, you can read its state using a microcontroller like an Arduino. The MTS-302 is a 3P3T switch, meaning it has 3 poles and 3 throws. This can be treated as three individual SP3T (single pole, triple throw) switches.
  3.  
  4. In this sketch, each throw of the switch is connected to a different digital input pin on the Arduino. The internal pull-up resistors are used, so you'll connect the other side of the switch to ground.
  5.  
  6. Every half second, the sketch reads the state of the switch and prints it to the serial monitor. If all the switches are open (in the case of the MTS-302, this would mean the switch is in a position that isn't connected to one of the throws you're reading), it will print "Unknown".
  7.  
  8. Remember to be careful with the switch ratings. The MTS-302 is rated for 250V and 3A, but your Arduino can't handle those levels. If you're switching something that uses high voltage or current, you'll need to use a relay or similar device.
  9.  
  10. Here's a simple Arduino sketch that reads the state of one pole. You'd repeat this for each pole, using different input pins.
  11. */
  12.  
  13. const int switchPin1 = 2; // connect this to one throw of the switch
  14. const int switchPin2 = 3; // connect this to the second throw of the switch
  15. const int switchPin3 = 4; // connect this to the third throw of the switch
  16.  
  17. void setup() {
  18.   pinMode(switchPin1, INPUT_PULLUP);
  19.   pinMode(switchPin2, INPUT_PULLUP);
  20.   pinMode(switchPin3, INPUT_PULLUP);
  21.  
  22.   Serial.begin(9600);
  23. }
  24.  
  25. void loop() {
  26.   int switchState1 = digitalRead(switchPin1);
  27.   int switchState2 = digitalRead(switchPin2);
  28.   int switchState3 = digitalRead(switchPin3);
  29.  
  30.   Serial.print("Switch position: ");
  31.   if (switchState1 == LOW) {
  32.     Serial.println("Position 1");
  33.   } else if (switchState2 == LOW) {
  34.     Serial.println("Position 2");
  35.   } else if (switchState3 == LOW) {
  36.     Serial.println("Position 3");
  37.   } else {
  38.     Serial.println("Unknown");
  39.   }
  40.  
  41.   delay(500);
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement