Saturday, December 3, 2016

51: Yet More About Relay Switches

I've discussed relays in earlier posts, but I keep learning more. I used 4 relays to swap cold/heat on a Peltier device. Now I need to switch polarity on 2 motors using a single Particle Photon. However, the Photon only has 8 digital GPIOs. My 4-relay plan would use all of them. So I asked around and came up with this arrangement:


This wiring works and takes only 2 GPIOs per motor. I tested with a multimeter. Here's a bit of code:

#define SW1  D1
#define SW2  D2
. . . 
void setup() {
   pinMode(SW1, OUTPUT);
   pinMode(SW2, OUTPUT);
. . .
}

void loop() {
. . .
    // blue wire +
   digitalWrite(SW1, HIGH);
   digitalWrite(SW2, LOW);
. . .
   // green wire +
   digitalWrite(SW2, HIGH);
   digitalWrite(SW1, LOW);
. . .
   // all OFF
   digitalWrite(SW1, LOW);
   digitalWrite(SW2, LOW);
. . .
}

No comments:

Post a Comment