"I have a 12V single-channel relay and a 12V solenoid lock connected to an Arduino Mega with WiFi. I want to test the solenoid and relay, but the issue is that the solenoid operates immediately when powered on, instead of waiting to be triggered. Additionally, the relay's indicator light (yellow/green and red) just dims and brightens instead of turning on or off as expected. Ideally, when the relay's light turns off, the solenoid should activate, and when the light turns on, the solenoid should release."
heres my testing code
#define RELAY_PIN 12 // Use Pin 12 for relay control
void setup() {
pinMode(RELAY_PIN, OUTPUT); // Set Pin 12 as output
digitalWrite(RELAY_PIN, HIGH); // Default OFF (active LOW relay)
}
void loop() {
digitalWrite(RELAY_PIN, LOW); // Turn relay ON
delay(3000); // Wait for 3 seconds
digitalWrite(RELAY_PIN, HIGH); // Turn relay OFF
delay(3000); // Wait for 3 seconds
}
and the pins
12V Solenoid Lock:
- to NO of the 12V Relay.
- to GND of the 12V power supply.
12V Relay:
COM to + of the 12V power supply.
IN to D7 PWM of the Arduino Mega 2560.
GND to GND of the Arduino Mega 2560.
VCC to + of the 12V power supply.
im sorry im newbie guys hope someone help me