This circuit is designed to control an LED strip and a loudspeaker using an Arduino UNO microcontroller. The system is activated by a pushbutton, which when pressed, triggers the Arduino to turn on the LED strip and the loudspeaker for a brief period before turning them off again. The circuit includes two TIP120 high-current Darlington transistors to drive the LED strip and the loudspeaker, which are powered by separate 12V power supplies. Resistors are used to limit the current to the bases of the transistors.
D9
connected to one end of a resistor (controls the loudspeaker via a transistor).D8
connected to one end of another resistor (controls the LED strip via a transistor).D2
connected to one side of the pushbutton.B
connected to the blue pin of the RGB LED.+12V
connected to the positive terminal of one 12V power supply.R
connected to the red pin of the RGB LED.G
connected to the green pin of the RGB LED.B
connected to the blue pin of the LED Strip.R
connected to the red pin of the LED Strip.G
connected to the green pin of the LED Strip.GND
connected to the collector of one TIP120 transistor.+
connected to the +12V
pin of the LED Strip and the positive terminal of the loudspeaker.-
connected to the emitter of the TIP120 transistors.BASE
connected to the other end of the resistors.COLLECTOR
connected to the GND
pin of the RGB LED and one terminal of the loudspeaker.EMITTER
connected to the negative terminal of the 12V power supplies.D9
and D8
pins of the Arduino UNO.D2
pin of the Arduino UNO.const int buttonPin = 2; // 按鈕引腳
const int relayLightPin = 8; // 繼電器控制燈的引腳
const int relaySpeakerPin = 9; // 繼電器控制喇叭的引腳
// 變數
int buttonState = 0; // 按鈕狀態
void setup() {
pinMode(buttonPin, INPUT_PULLUP); // 設定按鈕引腳為輸入,啟用內部上拉電阻
pinMode(relayLightPin, OUTPUT); // 設定燈的繼電器引腳為輸出
pinMode(relaySpeakerPin, OUTPUT); // 設定喇叭的繼電器引腳為輸出
// 初始關閉燈和喇叭
digitalWrite(relayLightPin, HIGH);
digitalWrite(relaySpeakerPin, HIGH);
}
void loop() {
// 讀取按鈕狀態
buttonState = digitalRead(buttonPin);
// 如果按鈕被按下(LOW 狀態),則重啟燈和喇叭
if (buttonState == LOW) {
// 開啟燈和喇叭
digitalWrite(relayLightPin, LOW);
digitalWrite(relaySpeakerPin, LOW);
// 等待 1 秒
delay(1000);
// 關閉燈和喇叭
digitalWrite(relayLightPin, HIGH);
digitalWrite(relaySpeakerPin, HIGH);
// 等待一段時間以避免重複觸發
delay(2000);
}
}
The code is written for the Arduino UNO microcontroller. It initializes the button and relay control pins, sets an initial state for the relays, and contains a loop that checks the button state. If the button is pressed, it activates the relays to turn on the LED strip and loudspeaker for one second, then turns them off and waits for two seconds to prevent immediate re-triggering.