Using the STEMMA Analog SPDT Switch with Arduino involves wiring up the breakout to your Arduino-compatible microcontroller and running the provided example code.
Wiring
Wire as shown for a 5V board like an Uno. If you are using a 3V board, like an Adafruit Feather, wire the board's 3V pin to the breakout VIN.
Here is an Adafruit Metro wired up to the breakout using the JST PH connector. You'll connect your two external analog inputs to NO and NC.
-
Board 5V to switch JST PH VIN (red wire)
-
Board GND to switch JST PH GND (black wire)
-
Board pin 5 to switch JST PH SCL (white wire)
- Board pin A1 to switch terminal block common (yellow wire)
- Analog input 1 to switch terminal block NO (blue wire)
- Analog input 2 to switch terminal block NC (green wire)
Here is an Adafruit Metro wired up using a solderless breadboard:
-
Board 5V to switch VIN (red wire)
-
Board GND to switch GND (black wire)
-
Board pin 5 to switch SIG (white wire)
- Board pin A1 to switch common (yellow wire)
- Analog input 1 to switch NO (blue wire)
- Analog input 2 to switch NC (green wire)
// SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries // // SPDX-License-Identifier: MIT int analogIn = A1; int digitalOut = 5; int analogValue = 0; unsigned long timer = 2000; unsigned long startTime = millis(); void setup() { Serial.begin(115200); pinMode(digitalOut, OUTPUT); } // the loop function runs over and over again forever void loop() { analogValue = analogRead(analogIn); Serial.println(analogValue); if ((millis() - startTime) >= timer) { digitalWrite(digitalOut, !digitalRead(digitalOut)); startTime = millis(); } delay(10); }
Upload the sketch to your board and open up the Serial Plotter (Tools -> Serial Plotter) at 115200 baud. You'll see the analog data printed to the plotter. Every 2 seconds, the analog output from the common pin will be switched by toggling pin 5 high or low.
Text editor powered by tinymce.