Interfacing the Arduino to the IRCF360 360 degree sensor

Arduino -> IRCF360 Interface

In this tutorial, we assume you're using an Arduino UnoArduino DuemilanoveNano, or Diecimila. If you have another board, read the corresponding page in your getting started guide to ensure you can upload sketches to your Arduino board.

1. Connect the Arduino to the IRCF360 as follows:

 Ensure all wires are connected to a connector underneath the IRCF360 PCB. 

 The digital pins 2 & 3 on the Ardunio UNO will become the 'soft' serial port for controlling the IRCF360. You may like to mount the IRCF360 on wooden stand (about 20cm-30cm high) using the 4 mouting holes on PCB. This will help to avoid noisy signals caused by ground reflections. 

2. Follow the "getting started" steps that came with you Ardunio. This is to ensure your Arduino UNO or other Arduino  is connected to your PC using the USB cable and you are able to upload sketches without any problems. 

3. Copy and paste and upload the Arduino-IRCF360 sketch in the next section on this page.  

The sketch uses the soft serial port developed by Tom Igoe.

4. Read how to interface Processing sketch to Arduino -> here

5. Download and Run the associated IRCF360 sketch which interfaces with the Arduino (available here soon)

Arduino-IRCF360 Sketch

Copy and paste all code below this line to your Arduino environment. This example code is in the 
public domain. 

Update 24th July 2011
This version will echo any serial command sent from Processing directly via Arduino to the IRCF360

   Language: Arduino
   This Arduino UNO sketch interfaces the IRCF360 - 360 degree sensor from
   It uses a softserial port Serial Call and Response developed by Tom Igoe
   Processing sketch will need to send a corresponding ASCII character
   to it startup. Once started the IRCF360 will either continue on it's 
   own or stop after each command has been completed. This is 
   programmable feature. 
    The circuit:
   * Plug +5v and +0v to the IRCF360 power and GND pins respectively
   * Connect IRCF360 RX pin to soft TX pin on Arduino
   * Connect IRCF360 TX pin to soft RX pin on Arduino  
   Created:   24 July. 2011
   by:        Colin Bacon
   This example code is in the public domain.
  #include <NewSoftSerial.h>
  NewSoftSerial mySerial(2, 3);
  int StartByteReceived = false;
  int serialCommand[5]; //The IRCF360 expects 4 bytes of data (0-3)|| for each command and 1 byte for the acknowledgement received from the IRCF360
  int serialCount=0;
  byte inByte =0;
  void setup()  
  //if serialCommmand = 3
  // set the data rate for the Arduino RS232 port (also USB port)
  Serial.println("IRCF360 Interface for");
  // Turn off serial communication echo
  // Turn on serial communication startbit to facilitate handshaking
   delay (100);      
   mySerial.print(18, BYTE);    
  //Run  the 360 degree sensing command as default
   delay (100);     
   mySerial.print(30, BYTE);    
  void loop()                          // run over and over again
  //---serial communication with Processing --------- 
   if (Serial.available() > 0 ) //Check if a byte has arrived on USB port from processing Sketch. If not then keep looping
      // Read the serial messages comming in from Processing
      inByte =;                            
      serialCommand[serialCount]=inByte; //Store the bytes into an array
      serialCount++;                     //Keep count of the array postiion 
      if (serialCount>3 )                //Note that softserial does strange things if you use = rather than > here
          mySerial.print(serialCommand[0] ,BYTE );    //The commmand
          mySerial.print(serialCommand[1] ,BYTE);    // The value related to command  
          mySerial.print(serialCommand[2],BYTE );    // Output Configuration Byte (e.g. if ASCII or DEC output) 
          mySerial.print(serialCommand[3],BYTE );    // continuous or single shot
          serialCount=0; //reset counter
          Serial.flush(); // flush any rubbish
  //Echo whatever comes in from IRCF360 to the USB port/Processing
         if (mySerial.available()) 
           Serial.write( );

/* Corresponding Processing Code

void setup() {
  // Print a list of the serial ports, for debugging purposes:
  size(800, 800, P3D);
  pg = createGraphics(80, 80, P3D);

  // I know that the first port in the serial list on my mac
  // is always my  FTDI adaptor, so I open Serial.list()[0].
  // On Windows machines, this generally opens COM1.
  // Open whatever port is the one you're using.
  String portName = Serial.list()[0];
  myPort = new Serial(this, portName, 9600);



 void serialEvent(Serial myPort) {
     // read a byte from the serial port:
     int inByte =;
     println ("inByte " + inByte);
     if (inByte==255) startByte=true;
     if (startByte==true) {
         if (inByte !=255) {
           serialInArray[serialCount] = inByte ;  
            println ("inByte " + serialCount + " " + inByte);
           serialCount++;  //if its not the startbit then store this value
             // If we have 8 bytes:
                      if (serialCount > 7) {
                          N = serialInArray[0];
                          NE = serialInArray[1];
                          E = serialInArray[2];
                          SE = serialInArray[3];
                          S = serialInArray[4];
                          SW = serialInArray[5];
                           W = serialInArray[6];
                          NW = serialInArray[7];
                          // print the values (for debugging purposes only):
                          //println(N + "\t" + NE + "\t" + E + "\t" + SE + "\t" + S + "\t" + SW + "\t" + W + "\t" + NW);
                          // Reset serialCount:
                          serialCount = 0;
                          myPort.clear();          // clear the serial port buffer
                          startByte=false; //reset startbyte flag

void mousePressed()
 //if(circleOver) {
    //myPort.write(200);      //start the transmission)
   //delay (100);
   myPort.write(30);      // 
   //delay (100);
   myPort.write(10);      // 
    //delay (100);
    myPort.write(1);      // 
    //delay (100);
        myPort.write(255);      // |
    //delay (100);
//   }