Trying To Get an IR Receiver to Work with an ATTiny85 Question

Hello everyone.

I'm having an issue using using the IRremote library with an ATTiny85.

I'm trying to write a sketch that turns on an LED when I press the power button on a remote control, and then turns it off when I press it again.

I know the IRremote library supports the ATTiny85, because it says that it the documentation. I thought that maybe that I was using the wrong pin, but even when I tried the other pins, they wouldn't work either. The pinout diagram on SparkFun says that pin 1 is capable of doing PWM, which is what I need for the IR receiver.

I'm thinking that maybe my wiring is wrong, or that it has something to do with the "Timers" column in the IRremote documentation that says "TINY0", under the ATTiny85 row. I'm not really sure what that means. Another possibility is that I'm not starting the IR receiver properly in the setup() method.

Also, I'm using the Tiny AVR Programmer to upload the code to the ATTiny85.
(www.sparkfun.com/products/11801)

Anyway, here is my code (I haven't put a default in my case statement just yet):

#include <IRremote.h> 


#define NUM_BUTTONS 1

  
const uint16_t BUTTON_POWER = 0xFFC03F; 

boolean ledEnable = 0; // Start with the LED off.

int RECV_PIN = 1;

int LED_PIN = 0;
IRrecv irrecv(RECV_PIN);

decode_results results; // This will store our IR received codes
uint16_t lastCode = 0; // This keeps track of the last code RX'd


  
void setup() 
{
  
   irrecv.enableIRIn(); // Start the receiver
   pinMode(LED_PIN, OUTPUT);
  

  
   

}

void loop() 
{
  
 
    
   if (irrecv.decode(&results))
   {
        uint16_t resultCode = (results.value & 0xFFFF);

        if (resultCode == 0xFFFF)
          resultCode = lastCode;
        else
           lastCode = resultCode;

        switch(resultCode)
        {
             
        case BUTTON_POWER:
  

          if (ledEnable)
          {
             digitalWrite(LED_PIN, LOW);
             ledEnable = 0;
             brightness = 0;
             

          }
          else
          {
          
              ledEnable = 1;
              digitalWrite(LED_PIN, HIGH);
     
              
              
          }
          break; 
          
        }
        irrecv.resume(); // Receive the next value

     
   } 

}

I've also attached the breadboard diagram I made in Fritzing.

Any help would be appreciated.

Thanks in advance.

For one thing, your resistor is wired in parallel with the LED, not in series as it should be.

I haven't put a default in my case statement just yet

That would be the next obvious thing to do. Make it switch the led on.
That tests if it receiving anything from the IR remote and that your LED is wired correctly.

const uint16_t BUTTON_POWER = 0xFFC03F;

How many bits does 0xFFC03F need?

EDIT: never mind, missed the & 0xFFFF later.

Hello everybody..
Like edpgamer, I have problem uploading sketch on attiny85.

I write code that works on arduino uno perfectly, but when i upload it to attiny 85, nothing happens.

Can any one help me with this, please..

here is my code:

#include <IRremote.h>

int receiver = 1;
int relay = 3;

IRrecv irrecv(receiver);
decode_results results;

void setup()
{
pinMode(receiver, INPUT);
pinMode(relay, OUTPUT);
irrecv.enableIRIn();
}
int on = 0;
unsigned long last = millis();

void loop() {
if (irrecv.decode(&results))
{
on = !on;
translateIR();
irrecv.resume();
}
}

void translateIR()

{
switch(results.value)
{
case 0xE0E020DF: digitalWrite(relay, on ? HIGH : LOW);
}
delay(500);
}

IRremote_back_light.ino (514 Bytes)

I just got this to work but there are many places it can go wrong so i thought I would share them.

Make sure you know the pins on your receiver. If you get them wrong you may or may not here the tiny pop of the receiver blowing out. After that it will never work again. I was using this IR receiver.

First watch this video as you will want to get software Serial working so you can see what IR signals are coming in.

NOTE: In the video he uses this link to add ATTINY 85 to the boards manager:
https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json

I am not sure that it is still available. I used this link in my boards manager:
http://www.leonardomiliani.com/repository/package_leonardomiliani.com_index.json

Other people said you could use the adafruit trinket for the board, but I didn't try it.

In order to get the ATTINY 85 to receive the IR code from a remote you need to burn the bootloader at internal 16MHz. I guess that's the speed the remote is sending the signals at?

Then upload this code to the ATTINY 85. It will print out the IR values received using a neat little bit of code. The IR value is stored in byteVal. The advantage of using this code over including the IR library is that the IR library takes up most of the memory space on the ATTINY and this code does not.

#include <SoftwareSerial.h>
int pinData= 0;
unsigned long lengthHeader;
unsigned long bit;
int byteValue;
SoftwareSerial mySerial(3,4);

void setup()
{
Serial.begin(9600);
pinMode(pinData, INPUT);

}

void loop()
{

lengthHeader = pulseIn(pinData, LOW);

if(lengthHeader > 1500)
{


for(int i = 1; i <= 32; i++)
{
bit = pulseIn(pinData, HIGH);


if (i > 16 && i <= 24)
if(bit > 1000)
byteValue = byteValue + (1 << (i - 17)); 

}
}
Serial.println(byteValue);

byteValue=0;

delay(250);
}

I was trouble shooting this for a long time. Hopefully this helps someone else get through it faster. Here is a video that proves it can be done.

grif0210 said "In order to get the ATTINY 85 to receive the IR code from a remote you need to burn the bootloader at internal 16MHz. I guess that's the speed the remote is sending the signals at?"

How did you burn the bootloader? I'm just starting with ATtiny85, and I also, have a camera remote that works with uno or nano, but not the attiny85.

Also: https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json Worked on my machine just a week or so ago.

Joe

Here is a lightweight IR library for remote control devices which use the NEC protocol (quite common for cheap devices). It can work on an ATtiny at 8MHz (I tested it with an ATtiny841) and leaves some resources for the sketch. It does not use a hardware timer.

https://forum.arduino.cc/index.php?topic=619622.0

@grif0210

I noticed the "working" code example you posted above has a tiny error preventing it from uploading to ATTiny85. At the top, you declare the variable mySerial, which is perfectly fine, but then invoke Serial.begin(9600). Serial.begin(9600) should be mySerial.begin(9600).

Also, I couldn't successfully print out IR signal values with this code. It uploads, then prints zero (0) ad infinitum, with presses on my Sony remote momentarily increasing the frequency of printed zeros.

I've successfully created a "universal" remote a few years ago as well as an IR decoder, but cannot
remember how the heck I did it.

I'm going to keep trying--will post update.

Cheers