relais-consigne.ino

Arduino Yún · File : relais-consigne.ino · Language : Arduino · Use case : Le Linux commande un relais : le croquis applique la consigne

The reverse of the first example: a plain curl on the Linux side drives a relay controlled by the microcontroller. Polling the setpoint with change detection avoids hammering the bridge needlessly.

Hardware

An Arduino Yun (ATmega32U4 + Linino Linux on an Atheros AR9331, Wi-Fi and Ethernet, microSD slot). 1 relay module (dry contact) + external supply if there is a load.

Wiring

Relay module IN to D7, VCC 5 V, common GND. Never wire a 230 V load without a proper relay module and closed enclosure.

How it works

valueGet re-reads the "relais" key from the bridge store; comparing with the last value avoids repeated writes. digitalWrite drives the module optocoupler.

Running it

Arduino IDE: select the serial port to upload, then the Arduino Yun board for the monitor. Linux side: ssh root@arduino.local (distribution password). The Yunwizard app configures the network.

Variants

Add an auto-off timer (millis), or a priority local physical button.

relais-consigne.ino

// Le Linux ecrit une consigne (valuePut), le croquis actionne.
#include <Bridge.h>

const int RELAIS = 7;
String derniere = "";

void setup() {
  pinMode(RELAIS, OUTPUT);
  digitalWrite(RELAIS, LOW);
  Bridge.begin();
  Serial.begin(9600);
}

void loop() {
  String consigne;
  Bridge.valueGet("relais", consigne);
  consigne.trim();

  if (consigne != derniere) {          // seulement si la consigne change
    derniere = consigne;
    if (consigne == "on") {
      digitalWrite(RELAIS, HIGH);
      Serial.println(F("relais ACTIVE"));
    } else {
      digitalWrite(RELAIS, LOW);
      Serial.println(F("relais libere"));
    }
  }
  delay(500);                          // scrutation douce
}

// Cote Linux :
//   curl -d "on"  http://localhost/data/relais
//   curl -d "off" http://localhost/data/relais

← Back to the board