A little curiosity. A whole lot of making.Robotics, CNC & connected ideas
robodatech.
Arduino sample library

Relay Control 22

Switch pumps, lamps, valves, and classroom loads through relay modules.

Open in compiler →
/*
  Roboda verified Arduino sample 0543
  Feature: Relay Control
  Generated for online build, classroom practice, and hardware upload testing.
*/

const byte relayPin = 12;
const unsigned long onTime = 710;

void setup() {
  pinMode(relayPin, OUTPUT);
}

void loop() {
  digitalWrite(relayPin, HIGH);
  delay(onTime);
  digitalWrite(relayPin, LOW);
  delay(1000);
}

How it works

Practice this Arduino feature with a verified Roboda sketch.

  1. Read the constants at the top of the sketch.
  2. Wire the pins exactly as listed in the pin map.
  3. Upload or compile once before changing values.
  4. Change one value at a time and watch Serial Monitor or the output device.

Connections

PinConnect toNote
D12Relay module IN pinUse a relay module/driver, not a bare relay coil from the Arduino pin.

Good ideas start here.

Robotics lessons, build notes and useful updates. Subscribe by entering your email.