Step 4 of 6 ⏱ about 3 min
Fan
What you're adding
The fan on relay 4. A motor doesn't need a resistor.
Wire it
✔ All ticked. Now upload the code.
Upload the code
This is the same relay test sketch from Step 1. If it is still on the board, you don't need to upload it again.
- Close the Serial Monitor if it is open.
- Download the sketch below and open it in Arduino IDE (File → Open). If the IDE asks to put it in a folder, click OK.
- Plug the USB cable back in. Check Tools → Board says Arduino UNO and Tools → Port shows your COM port.
- Click Upload (the round → arrow button). Wait for Done uploading.
Show the code
// Step 1: test the relay module.
// Turns relay 1, 2, 3, 4 ON one at a time (1 second each), then all OFF.
// Wiring: IN1 = pin 8, IN2 = pin 9, IN3 = pin 10, IN4 = pin 11.
// This relay module is "active-LOW": LOW turns a relay ON, HIGH turns it OFF.
const int RELAY_PINS[4] = {8, 9, 10, 11};
const int RELAY_ON = LOW;
const int RELAY_OFF = HIGH;
void allOff()
{
for (int i = 0; i < 4; i++) {
digitalWrite(RELAY_PINS[i], RELAY_OFF);
}
}
void setup()
{
Serial.begin(9600);
for (int i = 0; i < 4; i++) {
pinMode(RELAY_PINS[i], OUTPUT);
}
allOff();
Serial.println("Relay test starting");
}
void loop()
{
for (int i = 0; i < 4; i++) {
allOff();
digitalWrite(RELAY_PINS[i], RELAY_ON);
Serial.print("Relay ");
Serial.print(i + 1);
Serial.println(" ON");
delay(1000);
}
allOff();
Serial.println("All OFF");
delay(1000);
}
You should see
- The three lights come on in turn, then the fan spins for a second.
If it doesn't work
The fan doesn't spin
Give the blades a gentle flick: small motors can get stuck. Check the battery is charged and the fan wire is on NO, not NC.
The fan spins all the time
The fan wire is on NC. Move it to NO.