Infrared LED

Learn about Sparki's Infrared LED

SparkiDuino
Easy

Lessons You Should Know

Sparki has an Infrared LED. It is used to send information to other Sparkis like a remote control by rapidly blinking invisible infrared light.

Top - Infrared LED

How It Works

Infrared remotes work by sending codes via flashing lights. These lights flash really fast; Sparki’s infrared LED flashes 38,000 times a second. By changing the amount of time between each flash, Sparki can send a burst that is meant to be a 1 or a 0, known as bits.

Signal Diagram

Sparki sends these flashes until an entire code has been sent. Specifically, Sparki uses the NEC infrared code protocol.

Using the Part

With the basic Sparki code in place, you can send infrared codes using this command:

sparki.sendIR(code);

Where code is an 8bit value. This can be a number from 0 to 255, or a character like ‘a’ or ‘D’. Sending a code like this will allow a Sparki nearby to receive it with the Infrared Remote Receiver 

SparkiDuino already has code examples for you to use:
File > Examples > Infrared LED

/*******************************************
 Infrared LED Send Code example

 Sparki has an infrared LED. You can use it
 to communicate with other Sparkis and other
 devices that use infrared remote controls.
 Other Sparkis can receive the code using
 sparki.readIR();

 This example has Sparki sending a code every
 second. The code increases each time by 1.
 When the code reaches 255, the biggest number
 it can send, it goes back to zero and starts
 all over again.
********************************************/
#include <Sparki.h> // include the sparki library

void setup()
{
}

int code = 0;
void loop()
{
  sparki.sendIR(code);
  code = code + 1; // increase code by 1

  // set code back to 0 if it goes over 255 - the highest number sendIR can send
  if(code = 255){ 
    code = 0;
  }

  delay(1000); // wait one second
}