
Using Relays — SIK Circuit 13
Control a relay with a transistor to switch between two LEDs. Learn about electromechanical switching, SPDT relays, Normally Open vs Normally Closed contacts, and flyback protection.
คำแนะนำ
Parts & Introduction
Parts & Introduction
A relay is an electrically-operated mechanical switch. A small current energizes a coil that physically moves a contact arm, switching a separate circuit. Relays can control high-power devices (motors, lights, appliances) from low-power Arduino signals. This experiment uses an SPDT (Single Pole Double Throw) relay to alternate between two LEDs.
Parts Needed
- 1x Arduino Uno + USB cable
- 1x Breadboard
- 1x SPDT Relay
- 1x NPN Transistor (P2N2222A)
- 1x Diode (1N4148)
- 2x LEDs (different colors)
- 2x 330Ω Resistors
- 14x Jumper Wires
วัสดุสำหรับขั้นตอนนี้:
SparkFun Inventors Kit - V3.21 ชุด
Arduino Uno R31 ชิ้น
Breadboard1 ชิ้น
NPN Transistor (P2N2222A)1 ชิ้น
Diode (1N4148)1 ชิ้น
5mm LED1 ชิ้น
330 Ohm Resistor2 ชิ้น
Jumper Wires8 ชิ้นเครื่องมือที่ต้องใช้:
Hardware Hookup
Hardware Hookup
Wiring Instructions
Transistor + Relay Coil
- Connect transistor Base through 330Ω resistor to Arduino Digital Pin 2.
- Connect transistor Emitter to GND.
- Connect one side of the relay coil to transistor Collector.
- Connect other side of relay coil to 5V.
- Flyback Diode: Band (cathode) to 5V, anode to Collector.
Relay Contacts + LEDs
- Connect relay COMMON through a 330Ω resistor to 5V.
- Connect relay NC (Normally Closed) to LED 1 positive leg.
- Connect relay NO (Normally Open) to LED 2 positive leg.
- Connect both LED negative legs to GND.
วัสดุสำหรับขั้นตอนนี้:
NPN Transistor (P2N2222A)1 ชิ้น
Diode (1N4148)1 ชิ้น
5mm LED1 ชิ้น
330 Ohm Resistor2 ชิ้น
Breadboard1 ชิ้น
Jumper Wires8 ชิ้นArduino Code
Arduino Code
Open the Arduino IDE and upload the following sketch to your Arduino board.
/*
SparkFun Inventor's Kit
Example sketch 13 — RELAYS
Use a transistor to drive a relay, alternating two LEDs.
Hardware connections:
Transistor BASE through 330 ohm resistor to digital pin 2
Transistor EMITTER to GND
Relay coil: one side to COLLECTOR, other to 5V
Flyback diode: band to 5V, anode to COLLECTOR
Relay COMMON through 330 ohm to 5V
Relay NC to LED 1 positive, Relay NO to LED 2 positive
Both LED negatives to GND
This code is completely free for any use.
*/
const int relayPin = 2;
const int timeDelay = 1000;
void setup()
{
pinMode(relayPin, OUTPUT);
}
void loop()
{
digitalWrite(relayPin, HIGH); // Relay on (COM connects to NO)
delay(timeDelay);
digitalWrite(relayPin, LOW); // Relay off (COM connects to NC)
delay(timeDelay);
}วัสดุสำหรับขั้นตอนนี้:
Arduino Uno R31 ชิ้นเครื่องมือที่ต้องใช้:
Test & Experiment
Test & Experiment
What You Should See
You should hear the relay clicking, and see the two LEDs alternating — one on, one off — switching every second.
Troubleshooting
- LEDs not lighting: Check LED polarity — longer leg is positive.
- No clicking sound: The transistor or coil circuit isn't working. Verify transistor orientation and coil connections.
- Relay not making good contact: The SIK relay is designed for soldering, not breadboarding. Press it firmly to ensure all pins contact.
- Confusion: Don't mix up the TMP36 temperature sensor with the transistor!
Experiments to Try
- Replace the LEDs with a motor on the NO contact — use the relay as a motor on/off switch.
- Use a button to control when the relay toggles.
- Add variable delay to create morse code patterns.
วัสดุ
9- $105.00
- 1 ชิ้นตัวยึดตำแหน่ง
- 1 ชิ้นตัวยึดตำแหน่ง
- SPDT Relay1 ชิ้น
- ตัวยึดตำแหน่ง
- ตัวยึดตำแหน่ง
- $3.00
CC0 สาธารณสมบัติ
พิมพ์เขียวนี้เผยแพร่ภายใต้ CC0 คุณสามารถคัดลอก แก้ไข แจกจ่าย และใช้งานผลงานนี้เพื่อวัตถุประสงค์ใดก็ได้ โดยไม่ต้องขออนุญาต
สนับสนุนเมกเกอร์โดยซื้อสินค้าผ่านพิมพ์เขียวของพวกเขา ซึ่งพวกเขาจะได้รับ ค่าคอมมิชชันเมกเกอร์ ที่ผู้ขายกำหนด หรือสร้างเวอร์ชันใหม่ของพิมพ์เขียวนี้และรวมเป็นการเชื่อมต่อในพิมพ์เขียวของคุณเพื่อแบ่งรายได้