Steve
Published © GPL3+

Developing an IR Remote and Software Controller

We develop a replacement IR Remote for Speakers & Projectors in this article. The IR remote is controlled by a .NET application.

BeginnerFull instructions provided1 hour25,249
Developing an IR Remote and Software Controller

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Adafruit Infrared LED 940nm
×1
Resistor 330 ohm
Resistor 330 ohm
×1

Software apps and online services

Visual Studio 2015
Microsoft Visual Studio 2015

Hand tools and fabrication machines

Laser cutter (generic)
Laser cutter (generic)

Story

Read more

Custom parts and enclosures

Enclosure

2D Design File. Case Enclosure.

Code

Code snippet #1

Plain text
/*
 * IRremote: AV_Controller
 * An IR LED must be connected to Arduino PWM pin 3.
 * Version 0.1 01/04/16
 */

#include 

IRsend irsend;
byte byteRead;

void(* resetFunc) (void) = 0; //declare reset function @ address 0

void setup() {
  Serial.begin(9600);
  Serial.println("***********************");
  Serial.println("**   AV-CONTROLLER   **");
  Serial.println("***********************");
  Serial.println("Waiting for commands...");
}

void loop() {
  if (Serial.available()) {
    byteRead = Serial.read();
    processResponse(byteRead);
  }
}

void processResponse(byte byteInput) {
  switch (byteInput) {
   case '4':
      Serial.println("Sending Command: TEST 4"); 
       // irsend.sendNEC(0x827DD827, 32);
        delay(40);
      return;
      break;         
   case 'a':
      Serial.println("Sending Command: RESET");
      irsend.sendNEC(0x827D58A7, 32);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;
    case 'b':
      Serial.println("Sending Command: MUTE");
      irsend.sendNEC(0x827DD827, 32);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;
    case 'c':
      Serial.println("Sending Command: INPUT1");
      irsend.sendNEC(0x827D708F, 32);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;
    case 'd':
      Serial.println("Sending Command: INPUT2");
      irsend.sendNEC(0x827D48B7, 32);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;
    case 'e':
      Serial.println("Sending Command: TREBLE UP");
      irsend.sendNEC(0x827DF20D, 32);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;
    case 'f':
      Serial.println("Sending Command: TREBLE DOWN");
      irsend.sendNEC(0x827DCA35, 32);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;
    case 'g':
      Serial.println("Sending Command: BASS UP");
      irsend.sendNEC(0x827DF00F, 32);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;
    case 'h':
      Serial.println("Sending Command: BASS DOWN");
      irsend.sendNEC(0x827DC837, 32);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;
    case 'i':
      Serial.println("Sending Command: VOLUME DOWN");
      irsend.sendNEC(0x827D40BF, 32);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;
    case 'j':
      Serial.println("Sending Command: VOLUME UP");
      irsend.sendNEC(0x827DC03F, 32);
      delay(40);
      Serial.println("Command Sent.");
      return;
      break;
    case 'x':
      Serial.println("Resetting System...");
      resetFunc();
      return;
      break;

      break;
    case 't':
      Serial.println("OK");
      return;
      break;

      break;
    default: 

    break;
  }
  Serial.println("Unknown command.");
}

Code snippet #2

Plain text
 Sub sendCommand(data As String)
        PictureBox2.BackColor = Color.Green
        If connected = True Then
            If data <> "" Then
                Try
                    Using com As IO.Ports.SerialPort =
                   My.Computer.Ports.OpenSerialPort(comPort)
                        com.WriteLine(data)
                        com.Close()
                    End Using
                Catch ex As Exception
                    MessageBox.Show(ex.Message)
                End Try
            End If
        End If
        PictureBox2.BackColor = Color.White
    End Sub

Code snippet #3

Plain text
Imports System.Threading

Public Class Form1
    Dim connected As Boolean
    Dim comPort As String

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        portConfig()
    End Sub

    Sub portConfig()
        For Each p As String In My.Computer.Ports.SerialPortNames
            Try
                Using com As IO.Ports.SerialPort =
               My.Computer.Ports.OpenSerialPort(p)
                    com.ReadTimeout = 1000
                    com.WriteLine("t")
                    Dim data As String = com.ReadLine()
                    If InStr(data, "OK") Then
                        lblConnection.Text = "Connected to " & p
                        comPort = p
                        connected = True
                    End If
                    com.Close()
                End Using
            Catch ex As Exception

            End Try
        Next
    End Sub

    Sub sendCommand(data As String)
        PictureBox2.BackColor = Color.Green
        If connected = True Then
            If data <> "" Then
                Try
                    Using com As IO.Ports.SerialPort =
                   My.Computer.Ports.OpenSerialPort(comPort)
                        com.WriteLine(data)
                        com.Close()
                    End Using
                Catch ex As Exception
                    MessageBox.Show(ex.Message)
                End Try
            End If
        End If
        PictureBox2.BackColor = Color.White
    End Sub

    Private Sub ConnectToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ConnectToolStripMenuItem.Click
        portConfig()
    End Sub

    Private Sub ResetDeviceToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ResetDeviceToolStripMenuItem.Click
        sendCommand("x")
    End Sub

    Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ExitToolStripMenuItem.Click
        Application.Exit()
        End
    End Sub

    Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
        Label1.Parent = PictureBox1
        Label1.BackColor = Color.Transparent

        Label2.Parent = PictureBox1
        Label2.BackColor = Color.Transparent

        Label3.Parent = PictureBox1
        Label3.BackColor = Color.Transparent

        Label4.Parent = PictureBox1
        Label4.BackColor = Color.Transparent

        Label5.Parent = PictureBox1
        Label5.BackColor = Color.Transparent

        Label6.Parent = PictureBox1
        Label6.BackColor = Color.Transparent

        Label7.Parent = PictureBox1
        Label7.BackColor = Color.Transparent

        Label8.Parent = PictureBox1
        Label8.BackColor = Color.Transparent

        Label9.Parent = PictureBox1
        Label9.BackColor = Color.Transparent

        Label10.Parent = PictureBox1
        Label10.BackColor = Color.Transparent
    End Sub

    Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click
        sendCommand("a")
    End Sub

    Private Sub Label2_Click(sender As Object, e As EventArgs) Handles Label2.Click
        sendCommand("b")
    End Sub

    Private Sub Label3_Click(sender As Object, e As EventArgs) Handles Label3.Click
        sendCommand("c")
    End Sub

    Private Sub Label4_Click(sender As Object, e As EventArgs) Handles Label4.Click
        sendCommand("d")
    End Sub

    Private Sub Label5_Click(sender As Object, e As EventArgs) Handles Label5.Click
        sendCommand("e")
    End Sub

    Private Sub Label6_Click(sender As Object, e As EventArgs) Handles Label6.Click
        sendCommand("f")
    End Sub

    Private Sub Label7_Click(sender As Object, e As EventArgs) Handles Label7.Click
        sendCommand("g")
    End Sub

    Private Sub Label8_Click(sender As Object, e As EventArgs) Handles Label8.Click
        sendCommand("h")
    End Sub

    Private Sub Label9_Click(sender As Object, e As EventArgs) Handles Label9.Click
        sendCommand("j")
    End Sub

    Private Sub Label10_Click(sender As Object, e As EventArgs) Handles Label10.Click
        sendCommand("i")
    End Sub

    Private Sub Form1_Resize(sender As Object, e As EventArgs) Handles Me.Resize
        If Me.WindowState = FormWindowState.Minimized Then
            NotifyIcon1.Visible = True
            NotifyIcon1.Icon = SystemIcons.Application
            NotifyIcon1.BalloonTipIcon = ToolTipIcon.Info
            NotifyIcon1.BalloonTipTitle = "AV Controller"
            NotifyIcon1.BalloonTipText = "Controller is minimized. Click the icon in the tray to open."
            NotifyIcon1.ShowBalloonTip(50000)
            ShowInTaskbar = False
        End If
    End Sub

    Private Sub NotifyIcon1_MouseDoubleClick(sender As Object, e As MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick
        ShowInTaskbar = True
        Me.WindowState = FormWindowState.Normal
        NotifyIcon1.Visible = False
    End Sub
End Class

Github

https://github.com/z3t0/Arduino-IRremote

Credits

Steve

Steve

1 project • 6 followers
Hobbyist maker, loving all things Arduino and electronic.

Comments