ATTINY85 RF433 (3xAAA 1.2V) MC-38 DOOR SENSOR

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello Everybody,

 

I am creating a smart home with home assistant.

My goal is creating "cheap" components for my DIY Smart Home.

This time it is a Door/Window/Garage sensor powered on 3 AAA rechargable batteries .

I am going to create in my next post the fritzing drawing and provide you all with the code.

The intention is to maybe improve my code or schematics with team forum efforts and mainly mine effort to understand more about the controllers.

Thanks in advance and i will post the next day more info :)

 

The code is not completely finished but here is an example already:

#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
#include <RCSwitch.h>
#define INTERRUPT_PIN PCINT3 
#define INT_PIN PB3   
RCSwitch mySwitch = RCSwitch();
int timerhigh = 0;
int timerlow = 0;
void setup() {
   mySwitch.enableTransmit(1);
   mySwitch.setProtocol(1);
   mySwitch.setPulseLength(320);
   mySwitch.setRepeatTransmit(5);
   pinMode(INT_PIN, INPUT_PULLUP);


}

void external_interrupt()
{
  sei();                //enabling global interrupt
  GIMSK|= (1<<PCIE);    //Pin change interrupt enable
  PCMSK|=(1<<INTERRUPT_PIN);   //Pin change interrupt to 2nd pin PB2
}

void enters_sleep()
{  
  MCUCR|=(1<<SM1);      // enabling sleep mode and powerdown sleep mode
  MCUCR|= (1<<SE);     //Enabling sleep enable bit
  __asm__ __volatile__ ( "sleep" "\n\t" :: ); //Sleep instruction to put controller to sleep
  //controller stops executing instruction after entering sleep mode  
} 

void loop() {


if( digitalRead(INT_PIN) == HIGH && timerhigh < 5  ) {
timerlow = 0;
mySwitch.send(10107000, 24);
delay(1000);
timerhigh++;
}else if( digitalRead(INT_PIN) == LOW && timerlow < 5  ){
timerhigh = 0;
mySwitch.send(10108000, 24);
delay(1000);
timerlow++;
}else{
delay(1000);
timerhigh = 0;
timerlow = 0;
external_interrupt(); 
enters_sleep();
}}

 

Last Edited: Wed. Feb 10, 2021 - 12:19 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why are there lots of repetitive delays in your code?---seems like a bad way to go (wasteful).  If might be ok as a first cut, but should consider some sort of very simple state machine--then you can burn up time waiting to transition to new states, but  you have this time available to use for other things if needed.  Delays gobble it up and throw it into the trashcan.

 

It would be nicer reading to indent code under your if & else...that may just be due to the posting itself.

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Same topic as in https://www.avrfreaks.net/forum/...

 

Stay there.

 

Moderator

 

Ross McKenzie ValuSoft Melbourne Australia

Topic locked