[Solved] Relay wiring issues for 110v AC project

I'm having trouble with my project. I'm following this guide. From what I can tell, I've got my circuit set up correctly (here's a photo and here's the datasheet for the relay I have).

Here's the test code I'm running:

#define PIN 13

void setup()
{
  pinMode(PIN, OUTPUT);
  Serial.begin(9600); // open serial
  Serial.println("Press the spacebar to toggle relay on/off");
}

void loop()
{
  static int relayVal = 0;
  int cmd;
  
  while (Serial.available() > 0)
  {
    cmd = Serial.read();
      
    switch (cmd)
    {
    case ' ':
      {
        relayVal ^= 1; // xor current value with 1 (causes value to toggle)
        if (relayVal)
          Serial.println("Relay on");
        else
          Serial.println("Relay off");
        break;
      }
    default:
      {
        Serial.println("Press the spacebar to toggle relay on/off");
      }
    }
      
    if (relayVal)
    {
      digitalWrite(PIN, HIGH);
    } else {
      digitalWrite(PIN, LOW);
    }
   }
}

I'm using pin13 so that the onboard LED will light up when the pin is powered.

So for testing, here's what I've done:

  • When I have the I/O pin powered, I, as expected, read 4.66v across the ground and I/O pin. I read 0.75v when also measuring the 1k resistor. From the ground to the collector, I measure 2.65v. Across the relay pin, I read 2.12v.
  • With the I/O pin unpowered, I read 0v across the relay.

The problem is, the relay doesn't trigger when I change the state of the I/O pin even though the voltage across the relay pins goes from zero to 2.12v. I know that I have it wired in correctly because on the datasheet, it says that the magnetic coil side of the relay is on the side with the pins that are even and the side for the 110v has uneven pins and I've wired the arduino to the even pin side. I'm at a loss as to why the relay isn't triggering. I purchased three of them in case I damaged one or one came damaged, so I've tested it with several relays and that doesn't seem to have done anything.

An arduino output pin cannot supply enough current to activate the coil of a relay. You need a transistor or a fet or something to drive it. Many relay "modules" have this built in, so you can trip the relay using an output from a microcontroller. But the relay itself doesn't.

That datasheet has ten different relays on it. You might get away with driving the very smallest one, which requires 40 mA current, from the arduino. None of the others will work with an arduino.

And even if you have the very smallest one, it says it needs 3.7 volts across the coil to operate. If you want to drive this coil with 3.7 V and 40 mA, you need to review the value of the series resistor you are trying to use.

Dropping the resistor down to 470 ohms from 1k did the trick. Thanks!