Re: [tuto Diy] Domotiser un capteur PIR à 2,99
Publié : 23 août 2016, 17:31
Salut,
joli tuto
merci.
joli tuto
Reprenez le contrôle de votre domotique
https://easydomoticz.com/forum/
j'ai acheté les prises RF433 promax (10€ les 3) elles sont reconnues par mon rfxcom mais elles se dé-appairent en cas de coupure de courant.Fredok a écrit :Bonjour, oui il s'agit bien de cet action.fr qui vend d’ailleurs des prises RF433 promax ou une sonnette selectplus (pas plus cher) qui doivent être compatible RFlink ou rfxcom.
Merci.
Code : Tout sélectionner
#include <Arduino.h>
// +-\/-+
// Ain0 (D 5) PB5 1| |8 Vcc
// TX43 (D 3) PB3 2| |7 PB2 (D 2)
// Ain2 (D 4) PB4 3| |6 PB1 (D 1) >>OUTPIR
// GND 4| |5 PB0 (D 0)
*/
#define PIN_PIR 1
boolean presence;
boolean old_presence = LOW;
#include <avr/sleep.h>
#include <avr/power.h>
#include <RCSwitch.h>
#define PIN_433 3
#define CAPTEUR_ID 'd',4,3 //mettre l'id du capteur 'a' 'b' 'c' ou 'd' , 1 2 3 4 , 1 2 3 4
RCSwitch myswitch = RCSwitch();
void sleep() {
GIMSK |= _BV(PCIE); // Enable Pin Change Interrupts
PCMSK |= _BV(PCINT1); // Use PB1 as interrupt pin
// PCMSK |= _BV(PCINT1); // Use PB1 as interrupt pin
ADCSRA &= ~_BV(ADEN); // ADC off
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // replaces above statement
sleep_enable(); // Sets the Sleep Enable bit in the MCUCR Register (SE BIT)
sei(); // Enable interrupts
sleep_cpu(); // sleep
cli(); // Disable interrupts
PCMSK &= ~_BV(PCINT1); // Correction Turn off PB1 as interrupt pin
// PCMSK &= ~_BV(PCINT1); // Turn off PB1 as interrupt pin
sleep_disable(); // Clear SE bit
ADCSRA |= _BV(ADEN); // ADC on
sei(); // Enable interrupts
}
ISR (PCINT0_vect)
{
presence = digitalRead(PIN_PIR);
delay(100); //évite les oscillations de tension
if (presence == HIGH) myswitch.switchOn(CAPTEUR_ID);
if (presence == LOW) myswitch.switchOff(CAPTEUR_ID);
}
void setup()
{
pinMode(PIN_PIR,INPUT);
myswitch.enableTransmit(PIN_433);
myswitch.switchOff(CAPTEUR_ID); //
}
void loop() {
sleep();
}