Saturday, November 3, 2012

Arduino IR Receiver - Part 2

I have been successful in programming my Arduino to identify sets of digits transmitted from my Samsung remote. I used the excellent library at http://www.arcfn.com/2009/08/multi-protocol-infrared-remote-library.html as a starting point. I stripped out everything that wasn't a raw number, and started logging what numbers came across the serial monitor as I pressed buttons.

I then created a Switch/Case statement that turns on (and off) particular LED's when the appropriate button on the remote is pressed.

Not sure what sensor was in my VCR, but a TSOP4838 should work as well.

This can now be easily used to control motors, lights and other equipment (optically isolated SSR). I've uploaded a video to youtube showing how it all works.

Code and schematics are available at https://docs.google.com/folder/d/0ByRIq5k2wjcSd2FWa3FfQzBib1k/edit





As always comments here and detailed discussion at https://groups.yahoo.com/neo/groups/arduinohome/info is encouraged.

We are reading:
Arduino Robotics, by John-David Warren, Josh Adams, & Harald Molle




/*
 * IRremote: IRrecvDump - dump details of IR codes with IRrecv
 * An IR detector/demodulator must be connected to the input RECV_PIN.
 * Version 0.1 July, 2009
 * Copyright 2009 Ken Shirriff
 * http://arcfn.com
 * JVC and Panasonic protocol added by Kristian Lauszus (Thanks to zenwheel and other people at the original blog post)
 * Heavily modified by Steve Spence, http://arduinotronics.blogspot.com
 */

#include <IRremote.h>

int RECV_PIN = 19;

int reversePin = 4;                 // LED connected to digital pin 13
int forwardPin = 5;                 // LED connected to digital pin 13
int playPin = 6;                 // LED connected to digital pin 13
int pausePin = 7;                 // LED connected to digital pin 13

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  pinMode(reversePin, OUTPUT);      // sets the digital pin as output
  pinMode(forwardPin, OUTPUT);      // sets the digital pin as output
  pinMode(playPin, OUTPUT);      // sets the digital pin as output
  pinMode(pausePin, OUTPUT);      // sets the digital pin as output
}

void loop() {
  if (irrecv.decode(&results)) {
   
    long int decCode = results.value;
    Serial.println(decCode);
    switch (results.value) {
      case 1431986946:
        Serial.println("Forward");
        digitalWrite(forwardPin, HIGH);   // sets the LED on
        break;
      case -11780576:
        Serial.println("Reverse");
        digitalWrite(reversePin, HIGH);   // sets the LED on
        break;
      case -873913272:
        Serial.println("Play");
        digitalWrite(playPin, HIGH);   // sets the LED on
        break;
      case -1025287420:
        Serial.println("Pause");
        digitalWrite(pausePin, HIGH);   // sets the LED on
        break; 
      case 1791365666:
        Serial.println("Stop");
        digitalWrite(forwardPin, LOW);   // sets the LED off
        digitalWrite(reversePin, LOW);   // sets the LED off
        digitalWrite(playPin, LOW);   // sets the LED off
        digitalWrite(pausePin, LOW);   // sets the LED off
        break; 
      default:
        Serial.println("Waiting ...");
    }

    irrecv.resume(); // Receive the next value
  }
}



Wednesday, October 31, 2012

Arduino IR Receiver

I recycled a InfraRed receiver module from an old VCR tonight. I connected it to my Arduino 2560, and I'm displaying raw data in the serial monitor whenever I press a key on the remote. I'm attempting to do something useful with this data, like turn lights on and off, or adjust my thermostat. Will post more as the project develops.





int IRsignal[] = {
// ON, OFF (in 10's of microseconds)
    34, 1896,
    444, 440,
    52, 164,
    56, 164,
    54, 164,
    54, 54,
    56, 54,
    56, 54,
    54, 56,
    54, 54,
    56, 166,
    52, 164,
    54, 164,
    56, 54,
    54, 56,
    54, 58,
    52, 54,
    56, 56,
    52, 58,
    52, 58,
    52, 164,
    54, 54,
    56, 54,
    56, 56,
    52, 54,
    56, 54,
    56, 166,
    52, 164,
    54, 56,
    54, 164,
    54, 164,
    56, 162,
    56, 164,
    54, 164,
    54, 4526,
    442, 434,
    56, 164,
    54, 164,
    54, 164,
    56, 54,
    54, 56,
    54, 54,
    56, 54,
    56, 54,
    54, 164,
    54, 164,
    56, 164,
    54, 54,
    56, 54,
    56, 54,
    54, 56,
    54, 58,
    52, 54,
    54, 56,
    52, 166,
    54, 60,
    50, 54,
    56, 56,
    54, 56,
    54, 56,
    52, 166,
    52, 164,
    56, 54,
    54, 166,
    54, 162,
    56, 164,
    54, 164,
    54, 164,
    56, 4524,
    444, 434,
    54, 162,
    56, 162,
    58, 162,
    56, 52,
    58, 52,
    58, 54,
    54, 56,
    54, 54,
    56, 164,
    54, 164,
    54, 162,
    56, 164,
    54, 162,
    56, 0};

Sunday, October 28, 2012

Morse "Paddle" Keyer

Building on our previous "simple" piezo beep sketch, I now introduce a Morse "Paddle" Keyer. It contains two buttons, one timed for a 60ms dot, the other for a 180ms dash. It uses the tone() command to activate the Piezo, which is a pwm output.




/*
 Piezo

This example shows a morse "paddle" keyer.
One button is timed for a dot, the other
for a dash (3 * dot). I'm using a 60ms
duration for a dot, so a dash = 180ms.


 */

int outPin = 9;
unsigned int frequency = 700;
unsigned long dotDuration = 60;
unsigned long dashDuration = dotDuration * 3;
int dotPin = 7;   // pushbutton connected to digital pin 7
int dashPin = 8;   // pushbutton connected to digital pin 8


void setup()  {
pinMode(dotPin, INPUT);      // sets the digital pin 7 as input
pinMode(dashPin, INPUT);      // sets the digital pin 8 as input
}

void loop()  {
  int dotVal=LOW;
  int dashVal=LOW;

  dotVal = digitalRead(dotPin);
  dashVal = digitalRead(dashPin);
 
  if (dotVal==HIGH)
{
  tone(outPin, frequency, dotDuration);
}
 
  if (dashVal==HIGH)
{
  tone(outPin, frequency, dashDuration);
}
}


What we are reading this week:

Fun with Piezo's

I've created a simple beeping alarm with a Piezo transducer. Connect the Piezo + to pin 9, and the Piezo - to Gnd. Run the following sketch. Next version will be using the tone() command to build a Morse Code trainer.

/*
 Piezo
 
 This example shows how to run a Piezo Buzzer on pin 9
 using the analogWrite() function.
 
 It beeps 3 times fast at startup, waits a second then beeps continuously
 at a slower pace
 
 */

void setup()  { 
  // declare pin 9 to be an output:
  pinMode(9, OUTPUT);
  beep(50);
  beep(50);
  beep(50);
  delay(1000);
} 

void loop()  { 
  beep(200); 
}

void beep(unsigned char delayms){
  analogWrite(9, 20);      // Almost any value can be used except 0 and 255
                           // experiment to get the best tone
  delay(delayms);          // wait for a delayms ms
  analogWrite(9, 0);       // 0 turns it off
  delay(delayms);          // wait for a delayms ms