InduinoX User Guide - Interfacing with the ENC28J60 Ethernet Module

The ENC28J60 Module



The ENC28J60 Ethernet Module is a low-cost ethernet module that offers ethernet connectivity over SPI. This module is different from the ENC28J60 Ethernet Shield only in its form factor and the fact that there is no SD card slot. This module can be interfaced with any microcontroller over SPI.  We will see how to use this module with Arduino. 

Its been use with the arduino for sometime and there are a number of libraries available to work with the module.
You can download the following zip file and extract its contents to the libraries folder of your arduino installation.
There are 2 folders in this library - etherShield and ETHER_28j60. The etherShield is a base library and the ETHER_28j60 is a wrapper around this based library that simplifies the functionalities of the etherShield library for the beginner. You can program your Ethernet Shield directly using the etherShield Library however, this library requires you have a finer understanding of networking and how it works. We suggest you stick to the ETHER_28J60. You can find documentation on this here.

Module Overview

There are 10 Pins on the Module that bring out SPI interface and additional functionalities of the ENC28J60 IC. The Module is to be powered from 3.3Volts supply.

Connections Overview
Connect the pins of the module to pins of your Arduino as in the table
MODULEInduinoX / Arduino UNO (ATMEGA328) Arduino MEGA
VCC3.3V Pin3.3V Pin
GNDGNDGND
CSSS - PIN 10SS - PIN 53
SIMOSI - PIN 11MOSI - PIN 51
SCKSCK - PIN 13SCK - PIN 52
WOLPIN 5PIN 5
SOMISO - PIN 12MISO - PIN 50
INTInterrupt 0 - PIN 2Interrupt 0 - PIN 2



A Simple Test Program
Once you install the libraries, you can try the 'HelloWorld' program from ETHER_28j60 library. Upload the program, disconnect the board (make it standalone powered externally!), open your browser and type in the ip address of the board. (http://192.168.1.15).. Voila! now your arduino is on the network!
Controlling the InduinoX
The 'HelloWorld' is a simple program now to try the 'WebRemote' example. This will let you control the 6th pin on the InduinoX. You can modify this to achieve your web control needs.

InduinoX User Guide - Interfacing with the ENC28J60 Ethernet Shield

The ENC28J60 Ethernet Shield for Arduino



The ENC28J60 Ethernet Shield is a low-cost ethernet shield for the Arduino. It is based on the microchip ENC28J60 ethernet controller. 

Its been use with the arduino for sometime and there are a number of libraries available to work with this shield. 

You can download the following zip file and extract its contents to the libraries folder of your arduino installation. 

There are 2 folders in this library - etherShield and ETHER_28j60. The etherShield is a base library and the ETHER_28j60 is a wrapper around this based library that simplifies the functionalities of the etherShield library for the beginner. You can program your Ethernet Shield directly using the etherShield Library however, this library requires you have a finer understanding of networking and how it works. We suggest you stick to the ETHER_28J60. You can find documentation on this here.


Shield Overview

The Shield uses 6 pins on the Arduino. It works over SPI - 4 Pins(digital 10,11,12,13) & it uses 2 additional pins - 1 for interrupt (digital 2) and 1 for the WOL pin of ENC28J60 (digital 5). In addition the Shield also provides a SD card Slot that can be controlled using SPI. 

Chip Select Overview

To address cases where one needs to access both the SD card and the Ethernet Controller Over SPI, Chip Select Pin for the Ethernet Controller is provided with a jumper. This 3-Pin Jumper lets you choose between Digital Pins 8 & 10 of the Arduino to be used as the CS Pin. By default the Jumper Position is set to use the Digital Pin10 as CS. The SD card reader uses PIN 9 for CS. We suggest you leave the CS pin for the Ethernet Controller as 10 and modify the CS pin number in the SD example in arduino to get both working together. 

The Connections

Put the jumpers for PINS 2,5,10,11,12&13 in the off position. Place the Shield on top of your InduinoX Board. Connect an external Power supply to the board. The Ethernet Shield Requires more power than can be provided by your USB so an External Power Supply is required. Connect one end of your network cable to the Ethernet Shield and the other end to a Switch / Router (the same to which your computer / mobile is connected).

A Simple Test Program

Once you install the libraries, you can try the 'HelloWorld' program from ETHER_28j60 library. Upload the program, disconnect the board (make it standalone powered externally!), open your browser and type in the ip address of the board. (http://192.168.1.15).. Voila! now your arduino is on the network!

Controlling the InduinoX

The 'HelloWorld' is a simple program now to try the 'WebRemote' example. This will let you control the 6th pin on the InduinoX. You can modify this to achieve your web control needs. 

Serving a Webpage from the SD Card

We have created a custom example for this. Check out the 'SD_Webpage' example from the ETHER_28j60 library. Copy the web.txt file to the root directory of your SD card for this example to work.


Heres a demo video...




InduinoX User Guide - Interfacing with the Simple Labs' Servo Shield

The Simple Labs' Servo Shield is a custom designed Shield to drive Servo Motors. The Shield Can drive upto 10 servo motors at a time. It was originally designed for our Quadbot Robot Kit (8 Servos) + Mini Pan and Tilt Kit (2 Servos). In addition to this, the servo shield has suitable pin outs to be able to Connect the Compound Eye IR Sensor.




Servo Motors - What are they?


Servo motors are dc motors with a servo mechanism that lets us control the precise position of the Shaft.

A servo mechanism is a error correction mechanism that senses the negative error and applies a correction accordingly.

There are many types of Servo Motors available - depending upon applications.
They are used in areas requiring position control. While the basic working of all the servo motors is almost similar, for the scope of this tutorial we shall stick to discussing RC Servo Motors or the type of Servo motors used in Robotics / Radio Control Projects.


A Servo motor constitutes of 4 parts - a DC motor, a Gear system, A Potentiometer(for sensing feedback) and a Control Circuit. Here the Control Circuit and the Potentiometer together form the Servo Mechanism.





So How do Servo Motors Work?

The Control Circuitry on the Servo motor drives the DC motor based on input signals it receives, The output shaft of the DC motor is connected to the gear assembly and the gear assembly is such that it moves the potentiometer when it rotates. The Control Circuitry gets feedback from this potentiometer and spins the DC motor to achieve the desired angle between 0 & 180 degrees. The range of movement of the potentiometer is mechanically restrained.

And How do we Control these Servo Motors?

To Control a servo we need to give it a pulse once every 20 milliseconds. The Duration of this pulse will determine the Servo Angle which we need to achieve. For most Servo's a Pulse duration of 1millisecond will set the shaft position to 0 degrees and a pulse duration of 2 milliseconds will set the shaft position to 180 degrees. 



Controlling Servos with an Arduino

Arduino provides us with a servo control library that lets us control servos with ease. The library provides us with an option of writing both microseconds value and angle values. You can find more information on the library here - > Arduino Servo Library

Overview of the Servo Shield

The Servo Shield has clear pin mappings and polarity mappings for the Servos. It has a screw terminal for connecting an external power supply for the Servos. Servos require 4.8-6Volts and consume around 300-500milliamps. The Servo shield requires to be powered from an External Source for it to drive your servos.



The servo shield has Servo control pins on Arduino Digital Pins D2, D3, D4, D5, D6, D9, D10, D11, D12 & D13. Refer to the TOP Legend on the board "D + - " for the Orientation of the Servo Connector Connection.

Connect a Servo to D9 and an external Supply to the Battery Connector as Shown a 4xAA Battery Connector is used here in the image. The Servo shown in the image is part of the Quadbot Kit. If you are looking for a servo, you can check out the Tower Pro SG-5010



The Program

With the above setup you can load the 'Sweep' Program from within the Examples. This program is located at

File -> Examples -> Servo -> Sweep (Inside the Arduino IDE!)


InduinoX User Guide - Working with NEC Remotes

The Simple Labs InduinoX Arduino Learners' Kit comes with a small remote, the kind of remote you would find with a MP3 Player / Audio Players. Owing to their size these remotes have spread fast and hence this tutorial on how to decode these manually without using the library. If you want to use the library, check out our previous post on this

These small remotes use the NEC protocol which is a 32-bit protocol and much different from the SIRC Protocol we saw earlier. Here's the signal train of the NEC protocol

The Start Bit is a 9 ms long pulse followed by 4.5 ms space. This is  followed by a burst of 32-bit data. The 32-bit data consists of 8-bits of command and 8-bits of address which are transmitted twice for reliability. The first transmission of 8 bits is inverted when it is being transmitted the next time for increased reliability.


Heres the Pulse Modulation of the NEC Protocol

The Logical '1' is represented by a 560us long 38khz pulse (MARK) followed by a 1690us long LOW signal (SPACE). The Total Duration for the Logical '1' is 2.25us.

The Logical '0' is represented by a 560us long 38khz pulse (MARK) followed by a 560us long LOW signal (SPACE). The Total Duration for the Logical '1' is 1.12us.

So How do we read this?

For our purpose, we can read this as a 16-bit data (8-bit address & 8-bit command)


To read this signal here are the things we need to do
  • Wait till be get the start bit
  • Read the time duration for the subsequent 32bits
  • Sort through the time duration in 4 parts of 8-bits each
  • Calculate 2 values, one from the bits 0-7 and 16-23 and one from bits 8-15 & 24-31
  • Check if these values are equal. If so take the value as valid. if not ignore the value.
Here's the code for a function to read NEC remotes. This function works for the InduinoX board.


int remote()
{
  int val1=0,val2=0, dur[32], i=0, j=0;
  if(pulseIn(15,LOW)>8000)
  {
    for(i=0; i<32;i++)
    {
      dur[i]=pulseIn(15,HIGH);
    }
    
//Value Calculation

    for(i=0,j=0;i<24;i++,j++)
    {
      if(i==8)
         i=16;
      if(dur[i]>1000)
          val1 = val1+ (1<<j);
           
    }
    for(i=8,j=0;i<32;i++,j++)
    {
      if(i==16)
        i=24;
      if(dur[i]<1000)
        val2 = val2+ (1<<j);    
     }
     Serial.println(val1);
     Serial.println(val2);
     if(val1==val2)
       return val1;
     else
       return 0;
  }
  
  return 0;
}




InduinoX User Guide - Interfacing with the Wireless Shield / BTBee

Bluetooth control seems to be the In-Thing! hook up your InduinoX with your Android phone over Bluetooth and zap you go... With a little bit of Android Expertise, you can double the potential of your Arduino Projects.



So How does one hook up the InduinoX over Bluetooth?

For this, we are going to use and Xbee shield and a Bluetooth Module - BTBee

The Xbee shield is a low cost arduino shield for plugging in any device with the XBee foot print. The shield offers the flexibility of using any of the digital pins for Rx/Tx through a jumper setting mechanism. In our case, we will stick to use the default Rx/Tx pins of the InduinoX. For those of you willing to explore further, check out Software Serial using arduino.

The BTBee is a low cost serial bluetooth module with the same footprint as an Xbee. The BTBee has 2 LEDS a Red led for Power and a Green led for status indication. The Green led will be constantly blinking till the device is paired. Beware! the BTBee has a lot of dummy pins just to match the XBee footprint. In effect, it uses only 5 pins


Pin  Description
1 VCC  Power supply
2 TX  Data output
3 RX  Data input
5 Reset reset
10 GND  Ground

Place the BTBee on the Xbee shield as shown in the video. Upload the following test program onto the InduinoX and then place the shield on top of the InduinoX board. Remember place the Xbee shield only after uploading the program as otherwise you might face an error. (Since we use serial communication for programming, if there are other devices attached to the default serial port, programming the microcontroller will throw up an error.)

The test program expects a serial character 'A' to turn ON the led on the 13th pin and another character 'B' to turn it OFF.

Next Download the following App for your android phone BlueTerm

The BlueTerm App is a terminal app for Android that can simulate a Serial Terminal over Bluetooth.

Power your InduinoX (you can use USB power), turn on Bluetooth on your phone and scan for devices. If this is the first time you are pairing with the BTBee module you will see a set of numbers (the device id) try to pair with this using the code '1234' once it is paired, it will show up as 'linvor'. Now open the app and connect to linvor. Once connected, the app will show a message as connected and the Green led on the BTBee will stop blinking and remain stable (ON) Now type in the characters and get control of the LED on the InduinoX!

Here's the sample code. Make fun with Bluetooth!

 void setup()  
 {  
  Serial.begin(9600);  
  pinMode(13,OUTPUT);  
 }  
 void loop()  
 {  
  if(Serial.available())  
  {  
   int val = Serial.read();  
   if(val == 65)  
   digitalWrite(13,HIGH);  
   if(val==66)  
   digitalWrite(13,LOW);  
   Serial.println(val);  
  }  
 }  

InduinoX User Guide - Interfacing with the LCD Shield

The LCD Shield eases the process of interfacing a LCD display with the Arduino. The shield fits on top of any Arduino and takes power from the Arduino. 


How to place the Shield on top of an Arduino?
The shield has one of set 8 pins and 1 set of 6 Pins. The trimpot on the shield is on the top left side. Now place the shield onto your arduino such that the eight pins are placed on top of pins 8,9,10,11,12,13,gnd & aref and the six pins are placed on top of pins Vin, gnd, gnd, +5V, +3.3V & reset


The LCD shield is designed to work with 16 pin LCDs with the following pin configuration.





LCD Pin Mappings for the Shield
The LCD shields provides a 4-bit mode interface to the Arduino. The Pins are connected as follows.
RS => 8
E => 9
D4 =>10
D5 =>11
D6 =>12
D7 =>13

You can run the Hello World Example under File->Examples->LiquidCrystal->Hello World, with the following changes
replace this line
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
with
LiquidCrystal lcd(8,9,10,11,12,13);



Character LCD - A Quick Overview
Here's an interesting Write up to get you understanding the working of the LCD
http://joshuagalloway.com/lcd.html

InduinoX - Getting Started Guide


-->
InduinoX Getting Started – For Windows XP / Windows 7
--> -->

  1. Download the latest version of Arduino for Windows from here => http://arduino.cc/en/Main/Software
  2. Unzip the downloaded file and remember its location
  3. Connect the InduinoX board to your PC using the usb cable provided. You should see the power (red) led go on on the InduinoX board.
  4. Windows will detect a new usb device. Ignore any options to install drivers and Do not let windows install any drivers automatically.
  5. Open windows device manager
You can open windows device manager by right clicking on 'My Computer' and choosing Properties. In the new Window, Click on Device Manager [In Windows XP, this can be found under 'Hardware Tab' of the Properties Window]
  1. Now Scroll Down the List of Devices in the Device Manager till you come to a Device 'FT232R USB UART'. You should see a warning icon next to it as the drives have not been installed. Right Click on this Device and Choose 'Update Driver Software...' option.
  1. Now, Windows will provide you two options, Choose the one that says “Locate and install drivers manually from a specific Location.”
  1. In the next screen, you will see a browse button, click on the button and browse to the location of the drivers folder[You will find the drivers folder inside the unzipped arduino folder] and then click 'OK'. Then Click 'Next'
  1. Now, Windows might throw a Security  warning, ignore it and click on next.
  1. The Device will be installed as a USB Serial Converter
  1. Now Windows will detect a USB Serial Port and ask you for drivers. Follow the exact same process as we did earlier, choosing the same driver location as earlier.
In case Windows doesn't ask you, scroll through the Device manager and find the listing called 'USB Serial Port' and follow the above steps.
  1. Once everything is finished, You should be able to see a new device 'USB Serial Port (COMXX)'. Make a note of this Number.

  2. Now go the unzipped Arduino folder and run the arduino.exe file
  3. The Arduino IDE will open up
  4. In the Arduino IDE open the blink example program by clicking on it from under File -> Examples -> Basics
  5. Now select the board by going to Tools -> Boards -> and selecting 'Arduino Diecimila or Arduino Duemilanove w/ Atmega168' ARDUINO UNO
    If you have one our recent board InduinoX with ATmega328, Select Arduino UNO as the board

  6. Now select the Serial Port by going to Tools -> Serial Port -> and selecting the 'COM port that was earlier shown in the device manager'

  7. Now Click on the Upload button. In a moment, you should see 2 LEDs Rx & Tx blink on your InduinoX indicating the program being uploaded. Once the program is uploaded, you will see the White LED[13th Pin] on the InduinoX Blink
Thats it! We are Done!

InduinoX User Guide - Working with the IR LED

The IR Led is a unique idea we had when designing the InduinoX board. We thought if we can put bot the IR LED and TSOP side by side and make 2 boards face each other, we can build a simple basic IR based 2 way wireless communication system. In this edition, we will see how to generate sony signals on the IR led

The IR led is connected to PIN 14 (analog 0) of the InduinoX.

Understanding Frequency
The Sony SIRC protocol works at 40Khz...most remote controls work at their specific frequencies. TV remotes in India are generally between 32- 40Khz frequecny.

So whats this frequency all about?
40KHz means 40,000 Cycles in 1 second. Each Cycle represents a ON signal followed by a OFF signal. The signals could be of equal duration.

Heres another image of the Sony signals









If you look at the image, you can see the the 1.2ms high of the Logical '1' has further black lines with spaces in between. These correspond to the ON/OFF cycles. The space between these is what is called the frequency. The frequency of occurrence of a ON/OFF cycle is what it means.

So How do we generate it?
Lets do some calculation,
40,000 Cycles in 1 Sec or 1000 millisec or 1000 x 1000 microseconds
so each cycle if for a duration of 25microseconds.

We can produce this frequency if we can make a pin go high for 13 microseconds followed by low for 12 microseconds.

If we can do this for 2.4 milliseconds then we can generate a Startbit, if we can do this for 1.2 milliseconds then we can generate a Logical '1', and for 0.6 milliseconds, we can generate a Logical '0'.

Now that we know that each cycle will take 25 microseconds lets calcualte the number of cycles required for generating the 2.4 milliseconds start bit
2.4 milliseconds / 25microseconds => 2400 microseconds / 25microseconds => 96 cycles
1.2 milliseconds / 25microseconds => 1200 microseconds / 25microseconds => 48 cycles
0.6 milliseconds / 25microseconds => 600 microseconds / 25microseconds => 24 cycles

the delayMicroseconds() function of arduino can help us required delay in microseconds. So lets first create a pulse function.
 void pulseData(int no_of_cycles)  
 {  
  for(int i=0;i<no_of_cycles;i++)      
  {  
   digitalWrite(14,HIGH);  
   delayMicroseconds(13);  
   digitalWrite(14,LOW);  
   delayMicroseconds(12);  
  }  
  digitalWrite(14,LOW);  
  delayMicroseconds(600);// This delay is for the space between the signals 0.6 millseconds  
 }  
Now we have a function that can generate 40Khz signal cycles for a specified number of cycles.

Next we need a function that will convert a decimal value to binary, evaluate each bit and then call signal generation function accordingly.

Heres a function that takes any decimal value (upto 12 bits), converts it to binary and transmits the same.
 void dec_to_bin_transmit(int val)  
 {  
  int cnt = 0;  
  pulseData(96); // Sending the Startbit  
  while(cnt<12) // Execute this 12 times to send 12 bits of data  
  {  
  if(val>0) // Checking if the decimal value is non-zero  
  {  
   if(val%2 == 0) // Binary reminder check, if reminder is 1 then we need to send a logical '1'  
   {  
    pulseData(24);  
   }  
   else// Binary reminder check, if reminder is not 1 then we need to send a logical '0'  
   {  
    pulseData(48);  
   }  
   val = val / 2;  
  }  
  else // when the decimal value becomes zero, start sending zeroes for the remaining bits  
  {  
   pulseData(24);  
  }  
  cnt++;  
  }  
 }  
Note: This function is not optimal ;) there might be data loss. We will leave it to you to figure out how to optimise it.

Here's a simple program where the IR led transmits values from 0 to 1023. It transmits each value thrice.

 void setup()  
 {  
  pinMode(14,OUTPUT);  
 }  
 void loop()  
 {  
  for(int count=0; count<1023; count++)  
  {  
   for( int j=0;j<3;j++)  
   {  
   dec_to_bin_transmit(count);  
   delay(50);  
   }  
   delay(500);  
  }  
 }  
 void dec_to_bin_transmit(int val)  
 {  
  int cnt = 0;  
  pulseData(96); // Sending the Startbit  
  while(cnt<12) // Execute this 12 times to send 12 bits of data  
  {  
  if(val>0) // Checking if the decimal value is non-zero  
  {  
   if(val%2 == 0) // Binary reminder check, if reminder is 1 then we need to send a logical '1'  
   {  
    pulseData(24);  
   }  
   else// Binary reminder check, if reminder is not 1 then we need to send a logical '0'  
   {  
    pulseData(48);  
   }  
   val = val / 2;  
  }  
  else // when the decimal value becomes zero, start sending zeroes for the remaining bits  
  {  
   pulseData(24);  
  }  
  cnt++;  
  }  
 }  
 void pulseData(int no_of_cycles)  
 {  
  for(int i=0;i<no_of_cycles;i++)      
  {  
   digitalWrite(14,HIGH);  
   delayMicroseconds(13);  
   digitalWrite(14,LOW);  
   delayMicroseconds(12);  
  }  
  digitalWrite(14,LOW);  
  delayMicroseconds(600);// This delay is for the space between the signals 0.6 millseconds  
 }  

InduinoX User Guide - Working with TSOP IR Receiver - Part 2

We hope you had success with the first part of this write-up. If you have not read it, we suggest you go through it before reading ahead. InduinoX User Guide - Working with TSOP IR Receiver - Part 1

Now that we've used the library successfully, we will see how to code manually to receive from a Sony Remote. Later in the next part, we will see how to generate Sony Signals. Its advised that you read this and try this out completely before moving onto signal generation

Lets take a look at the sony signal train









Now Here's how we are going to go ahead with decoding
  1. Keep checking the TSOP pin (Pin 15) for a LOW pulse of duration in excess of 2ms, the moment you get such a signal proceed on to step 2
  2. Run a 'for' loop for 12 counts, during each iteration of the loop, get the current pulse duration using the pulseIn function. Check if the duration is greater than 1000ms (means its a '1') else its a '0'
  3. As soon as you detect a '1' or '0' add it to an appropriate binary to decimal conversion logic.


Here's the code, You can plug in the remote function into any of your programs, just remember to declare pin 15 as INPUT.
 void setup()  
 {  
  pinMode(15,INPUT); // TSOP is connected on the 15ht pin  
  Serial.begin(9600);  
 }  
 void loop()  
 {  
  int remote_val = remote();  
  if(remote_val>0)  
  {  
   Serial.println(remote_val);  
   delay(150); // A remote press will normally generate 3 signal trains. This is to avoid reading duplicates  
  }  
 }  
 int remote()  
 {  
  int value = 0;  
  int time = pulseIn(15,LOW);  
  if(time>2000) // Checking if the Start Bit has been received. Start Bit Duration is 2.4ms  
  {  
   for(int counter1=0;counter1<12;counter1++) // A loop to receive the next 12 bits  
   {  
    if(pulseIn(15,LOW)>1000) // checking the duration of each pulse, if it is a '1' then we use it in our binary to decimal conversion, '0's can be ignored.  
    {  
     value = value + (1<< counter1);// binary to decimail conversion. 1<< i is nothing but 2 raised to the power of i  
    }  
   }  
  }  
  return value;  
 }  

InduinoX User Guide - Working with TSOP IR Receiver

The TSOP SM0038 is an IR receiver on the InduinoX. The TSOP will help you to interface your TV remote with the InduinoX and in the Process learn the basics of Wireless Communication. The TSOP is connected to pin digital 15(Analog 1).

The TSOP outputs a constant HIGH signal when idle and as it receives data, it tends to invert the data. i.e when an IR LED is transmitting data onto the TSOP, everytime the IR led goes high, the TSOP will go LOW and vice versa. Remote control signals are often bytes of data that is encoded and transmitted by pulsing(switching ON & OFF the IR LED at a specific frequency) Most TV remote controls work at 32-40 Khz frequency and most receivers can receive this range. 

Heres a link to a nice write up on different remote control protocols. lets first take a look how the Sony Remote Control Protocol Works. We stick to Sony as it is the easiest one to get started with. Read this before proceeding 

Here's a basic outline of how the data is sent. Every time you press a button on a Sony remote control, it sends out a 13Bit data. The first bit is a start bit indicating there are 12 bits of data following it. The next 7 bits are the command bit which will vary depending upon the keys being pressed. The last 5 bits are the address bits which will the same for all buttons but vary for remote controls of different devices.

The black bars in the following image correspond to high signals (called marks) and the white spaces in between correspond to low signals (called spaces). The duration of the 'marks' varies according to the bit being transmitted. It is 2.4ms for the start bit, 1.2ms for HIGH bit and 0.6ms for LOW bit. The duration of the 'spaces' is a constant 0.6ms. Every mark is followed by a space. Any data can be converted to binary format and transmitted in this manner. In fact this is the basic form of all types of serial communication.


Technique to decode this signal train, would be to constantly monitor the TSOP pin[Digital 15] for its normal state and the moment it produces a low signal, measure the duration of the low signal. If the measured duration of the low signal is around 2ms then measure and store the duration for the next 12 bits of the incoming data. After storing the data, evaluate the duration and based on the duration convert the data to decimal / hexadecimal and use it in your application.

The duration of a signal on an input pin of the arduino can be measured using the pulseIn function. Read more about this function here

There is an interesting IR remote library that can help you read different remotes without any difficulty. It can also generate different remote signals. However currently it can generate these signals only on the 3rd pin of the Arduino / InduinoX (PWM pin). Incase you want to use this library to generate remote control signals, we advise that you put the jumpers of the RGB LED OFF and connect a wire between the 3rd pin and the Analog 0 of the InduinoX. The IR LED on the InduinoX is connected to Analog 0(a.k.a digital 14)

You can download the IR remote library and other libraries, sample codes for the InduinoX here -> Click Here to Download InduinoX Sample Codes & Required Libraries[Right Click & use Save As]


How to use Libraries in Arduino - An Overview
To use any library you download, unzip the downloaded file and copy its contents to the libraries folder inside your arduino directory. You can check the library by opening the arduino ide and going to Sketch -> Import Library Option, if your library is in the proper location, it will show up here. Next if there is an example provided with the library (it will be inside a folder called example inside the base folder of the library) it will show up under the libraries name in the File->Examples Menu. You should reopen Arduino for the library to show up.


Once you install the IRremote, You can try the example program, IRrecvDemo. This program will give you a serial output of the HEX code for each value corresponding to each button on a remote. We will be using the decimal value in our next program. To get the decimal value, just do the following modification

replace this line
Serial.println(results.value, HEX);
with
Serial.println(results.value);

Ensure the TSOP jumper is ON!

Here's a video of a simple project - A remote control interface for our Binary Counter.


Here's the source code for the same
 /*   
  This sketch increases a 3 bit number every time '+' button is pressed and decreases the value when '-' button is pressed on the remote.It shows the output on 3 LEDs in Binary Format   
  */  
 #include <IRremote.h>  
 int RECV_PIN = 15;  
 IRrecv irrecv(RECV_PIN);  
 decode_results results;  
 int i = 0;  
 void setup()  
 {  
  pinMode(11,OUTPUT);   // declare LED pins as output pins  
  pinMode(12,OUTPUT);  
  pinMode(13,OUTPUT);  
  pinMode(7,INPUT);// Declare the 7th pin as a input pin. We will use the button on the 7th pin  
  digitalWrite(7,HIGH);  
  irrecv.enableIRIn(); // Start the Remote receiver  
  Serial.begin(9600);  
 }  
 void loop()  
 {  
  if (irrecv.decode(&results)) {  
   Serial.println(results.value);  
   switch(results.value)  // if the '+' button is pressed  
   {  
   case 2320:   
    i=0;   
    break;// 2320 is the value for '0'  
   case 16:   
    i=1;   
    break;// 16 is the value for '1'  
   case 2064:   
    i=2;   
    break;// 2064 is the value for '2'  
   case 1040:   
    i=3;   
    break;// 1040 is the value for '3'  
   case 3088:   
    i=4;   
    break;// 3088 is the value for '4'  
   case 528:   
    i=5;   
    break;// 528 is the value for '5'  
   case 2576:   
    i=6;   
    break;// 2576 is the value for '6'  
   case 1552:   
    i=7;   
    break;// 1552 is the value for '7'  
   case 1168: // this is the value for the increment button  
    if(i<7)        // if counter value is less than 7 or 3 bits  
     i++;        // increment counter value  
    else           
     i=0;  
    break;  
   case 3216: // this is the value for the decrement button  
    if(i>0)        // if counter value is greater than 0 or 3 bits  
     i--;        // decrement counter value  
    else           
     i=7;        // reset counter to 7  
     break;  
   }  
   int a=i%2;      // calculate LSB   
   int b=i/2 %2;     // calculate middle bit  
   int c=i/4 %2;     // calculate MSB   
   digitalWrite(11,c);  // write MSB  
   digitalWrite(12,b);  // write middle bit  
   digitalWrite(13,a);  // write LSB  
   while(digitalRead(7)==0);  // wait till button is released to avoid incrementing the counter again  
   delay(300);         // small delay to avoid debounce  
   irrecv.resume(); // Receive the next value  
  }  
 }