If your relay module does not follow the standard labeling of COM, NO, and NC pins, and instead has terminal descriptions that you're not familiar with, it might be a relay module designed for easier integration with microcontroller projects, including Arduino. These modules often come with built-in driving circuits, meaning you won’t typically need an external diode or resistor for the relay coil, and they usually have three main connections: VCC, GND, and IN (Signal). Let's adjust the steps to use such a relay module:
Adjusted Steps for a Relay Module with Terminals:
Step 1: Connecting the Relay Module to the Arduino
- Connect the VCC pin of the relay module to the 5V output on the Arduino.
- Connect the GND pin of the relay module to one of the GND pins on the Arduino.
- Connect the IN (Signal) pin of the relay module to a digital pin on the Arduino (for example, D2).
Step 2: Wiring the DC Motor and Power Supply
- Connect the positive terminal of the DC motor to one of the switching terminals on the relay module. The relay module may label the switching terminals differently, but if it only has two terminals (not counting VCC, GND, and IN), one will be for the incoming power (this would go to your motor), and the other to complete the circuit with your power supply. If it has three, it's similar to a typical relay: you want the normally open (NO) terminal here.
- Connect the negative terminal of the DC motor to the negative (–) terminal of the 9V battery.
- Connect the positive terminal (+) of the 9V battery to the remaining switching terminal on the relay. If your relay module has three switching terminals and is labeled, you’ll want to use the Common (COM) terminal.
Reminder on Relay Terminals on Modules
- VCC: Connect to the Arduino's 5V.
- GND: Connect to Arduino's ground.
- IN (Signal): Control pin, connect to an Arduino digital pin.
- Switching Terminals: Where your load (the DC motor) connects, along with the power source (9V battery).
Wiring the Pushbutton
Connect the pushbutton just like in the original instruction:
- Place the pushbutton on the breadboard.
- Connect one terminal to the Arduino's GND.
- Connect the other terminal to D3 on the Arduino through a 2.2k ohm resistor.
- Also enable a pull-up resistor by connecting it to 5V or using
INPUT_PULLUP in code for the button pin.
Adjusted Arduino Code
The code remains virtually the same, just ensure you've correctly defined your button and relay pins according to how you've connected them:
#define BUTTON_PIN 3 // Connect your button to pin 3
#define RELAY_PIN 2 // Connect your relay to pin 2
void setup() {
pinMode(BUTTON_PIN, INPUT_PULLUP); // Button as an input with internal pull-up
pinMode(RELAY_PIN, OUTPUT); // Relay control pin as an output
digitalWrite(RELAY_PIN, LOW); // Ensures relay starts OFF
}
void loop() {
// Check if the button is pressed (button pin goes LOW)
if(digitalRead(BUTTON_PIN) == LOW) {
digitalWrite(RELAY_PIN, HIGH); // Turn on the relay (motor spins)
delay(5000); // Motor on for 5 seconds
digitalWrite(RELAY_PIN, LOW); // Turn off the relay (motor stops)
while(digitalRead(BUTTON_PIN) == LOW); // Wait for button release
}
}
Testing
Once everything is wired up and the code is uploaded:
- Ensure all connections are secured.
- Power the Arduino and the battery.
- Press the pushbutton; the motor should activate for 5 seconds.
This setup, using a relay module, simplifies the process by not requiring additional components to safely drive the relay. If your relay module is still slightly different or if you're unsure about any steps, look for a datasheet or any documentation specific to your module model for detailed pin descriptions and wiring instructions.