Loading...
Loading...
// Electromagnetic Uncoupler
const int IR_SENSOR = 2;
const int BUTTON = 3;
const int MAGNET = 9;
const int ACTIVATION_TIME = 2000; // 2 seconds
void setup() {
pinMode(IR_SENSOR, INPUT);
pinMode(BUTTON, INPUT_PULLUP);
pinMode(MAGNET, OUTPUT);
}
void activateMagnet() {
digitalWrite(MAGNET, HIGH);
delay(ACTIVATION_TIME);
digitalWrite(MAGNET, LOW);
}
void loop() {
if (digitalRead(IR_SENSOR) == LOW ||
digitalRead(BUTTON) == LOW) {
activateMagnet();
delay(1000); // Debounce
}
}This is starter code - modify and expand for your specific needs.
Before building this project, make sure you have the Arduino IDE installed and are comfortable uploading basic sketches to your board.
Most projects use standard Arduino libraries. Some may require additional libraries like AccelStepper, Servo, or NmraDcc - install these through the Arduino Library Manager.