Infrared Detector WIth 1Mhz Attiny85

Ah.

OK. I see what you mean about the existing vs the new controls

I have a similar situation in my lounge, I have a battery powered LCD timer / thermostat unit, that switches on my central heating, by connecting 2 wires together

The 2 wires actually have 24V AC on them.

So what I was able to do was to rig up a circuit to draw a small amount of power from the switching wires, e.g. 5mA which is low enough so that the heating system doesn't think the wires are connected

This 5mA charges a battery, so that when my Arduino circuit shorts the wires using a low current reed relay, the Arduino still has power to run on. As once the wires from the heating are connected, I can't get any power to run the arduino

Well, I may be able to, but it was simpler just to charge a battery

However I agree this is a rather complicated setup

;-)

@dlloyd,

Yes, I think I understand what you're saying. Technically I should be able to see the start of an ir code within 600us after waking up the ir detector, if the sleep loop is small and the ir read is only about say 5ms before I give up, this might make it almost seamless. I am going to try your suggestion.

My calculated sleep current is 4.5uA so that is pretty low. I don't think there is much current leaking during the sleep.

Regards, Jose

Hi All,

Just a quick follow-up in case someone runs into this while searching. I look @dlloyd advice and got it to work pretty reliably my sleeping less, but when awake quickly looking to see if the ir is sending at all, and if not, then go back to sleep. I found that setting the wdt to 64ms and checking the ir line for a low transition a few times (I searched like 7 times) did the trick.

I found this application note: http://www.cypress.com/?docID=46755, that states that the ir detector takes about 1ma to wake up after vdd has been activated. To be safe, I wait 3ms after turning on the IR detector, check for “activity” 7 times and give up on the detector if I don’t find anything.

Here is the main loop:

void loop(void) {
  
   // go to sleep here
   goToSleep();
  
   
   // turn on the IR detector   
   //digitalWrite(IRVDDPIN, HIGH);
   IRVDDPORT |= 1<<IRVDDPIN;
   
   // wait 3 ms for ir to wake up
   for(unsigned long i=0; i< 1500; i++) { 
      delay2us();
   }
   
  // check for ir sending; 
  if(!snoopIR()) {
     IRVDDPORT &= ~(1<<IRVDDPIN);
     return;
  }  
  
   // ir is sending stuff 
   // listen for IR command;  
   cli(); // disable wdt
   IRCode = listenForIRCode();
   sei(); // enable wdt
      
   if(IRCode > 0 ) { 
      if(IRCode == OFF) { 
         fireOff();
      } else if(IRCode == ON) {   
         fireOn();
      }
   } 
   IRVDDPORT &= ~(1<<IRVDDPIN);  
}

I use direct port manipulation for turning on/off the IR receiver to make sure the attiny is on for as little as possible.

I also found that the “snoopIR()” had to be carefully coded.

For instance:

boolean snoopIR() { 
   unsigned retry = 128; // 7 times
 
   // check a few times for ir to go low
   while( retry && (IRpin_PIN & (1<<IRpin)) ){
      retry >>=1;
      delay2us();
   }
   
   // if we saw a low transition, then ir is receiving
   if(retry) { 
      return true;
   }
   
   // ir is ilde
   return false;
}

is A LOT faster than

boolean snoopIR() { 
   unsigned retry = 7; // 7 times
 
   // check a few times for ir to go low
   while( retry-- && (IRpin_PIN & (1<<IRpin)) ){
      delay2us();
   }
   
   // if we saw a low transition, then ir is receiving
   if(retry) { 
      return true;
   }
   
   // ir is ilde
   return false;
}

makes sense, since the compiler probably resorts to subtraction the second way.

I also found that running the processor at anything less than 8Mhz is not reliable, so I gave up on that idea.

So the final normal sleep vs. active is 64ms vs 4ms active, except if the IR is active. So the ratio is about 6% active. I tried different delays for the WDT, but found that 64ms was the most responsive while still saying below 10% active. So far so good. I will be eye balling the battery life on this one. Without any power savings, the battery seems to be depleted at around 1.5 days, but I did not start with a fresh batch of batteries. I compute that they should have lasted around 3 days. At 6% active, I expect then to now last over a month.

Any more ideas would be great. Thanks for all the pointers.

Regards,
Jose

hi all, will this suggestion work or not? The problem is, 1 MHz is not sufficient speed to generate or receive the IR pulses, so everything is in library only right? so if that is the case. Then can we increase or decrase the time period of IR pulses in library? for Both transmitter and receiver side. By doing that, will i be able to catch the proper message what we have to receive or transmit?