Si, puoi farlo non è niente di molto diverso di quello che hai detto.
Sostanzialmente la prima cosa da fare è capire il tipo di uscita del tuo sensore, se è un contatto fisico (rele ,contatto o reed) o se è una open collector.
Se è passivo, quindi non alimentato ne con batterie a bordo, è al 100% un contatto , quindi è semplice.
Io ti consiglio di fare cosi tanto per cominciare:
Prendi una resistrenza da 10k e vai a comporre lo schema come illustrato nella foto sotto:
Sostituisci i 2 contatti utilizzati dello switch e metti le 2 terminazioni del tuo sensore.
Per le prove serve qualcosa che ti indichi lo stato dell'uscita verso la centrale( che per ora per semplicita ometteremo).
Utilizzi il led a bordo scheda collegato al pin 13. Acceso contatto chiuso, spento contatto aperto(per le prove va più che bene)
A livello hardware sei già pronto a fare prove!
Ora serve uno straccio di sketch:
// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
// Variables will change:
int ledState = HIGH; // the current state of the output pin
int buttonState; // the current reading from the input pin
int lastButtonState = LOW; // the previous reading from the input pin
// the following variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long lastDebounceTime = 0; // the last time the output pin was toggled
long debounceDelay = 50; // the debounce time; increase if the output flickers
void setup() {
pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);
}
void loop() {
// read the state of the switch into a local variable:
int reading = digitalRead(buttonPin);
// check to see if you just pressed the button
// (i.e. the input went from LOW to HIGH), and you've waited
// long enough since the last press to ignore any noise:
// If the switch changed, due to noise or pressing:
if (reading != lastButtonState) {
// reset the debouncing timer
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
// whatever the reading is at, it's been there for longer
// than the debounce delay, so take it as the actual current state:
buttonState = reading;
}
// set the LED using the state of the button:
digitalWrite(ledPin, buttonState);
// save the reading. Next time through the loop,
// it'll be the lastButtonState:
lastButtonState = reading;
}
Tratto dal playground descrimina la chiusura del contatto con debounce.
Con questo sketch avrai l'accensione del led ad ogni chiusura del contatto.
Modificando lo sketch puoi ottenere il condizionamento del segnale che desideri, ovviamente le politiche da adottare e la logica di analisi da applicare devi deciderle tu!
Buon divertimento