Pages: [1]   Go Down
Author Topic: Infrared Communication  (Read 527 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
i am new to Arduino and MicroController and stuff like this.
But i wanted to make a extremly easy and stupid example of IR-Transmission to understand the basic, but something is wrong.
I get random input...nothing i understand. It should be <start>0001011

Reciever
Code:
const int irPin =  8;      // the number of the LED pin

void setup() {
  Serial.begin(9600);
  pinMode(irPin, INPUT);  
  
}

void loop(){
    
   unsigned long y = pulseIn(irPin, HIGH);
   Serial.print("High: ");
   Serial.println(y);
   y = pulseIn(irPin, LOW);
   Serial.print("Low: ");
   Serial.println(y)
}

Sender
Code:
const int ledPin = 13;

void setup() {
  Serial.begin(9600);
  pinMode(ledPin,OUTPUT);
}

void loop() {
  
  digitalWrite(ledPin, HIGH);
  delayMicroseconds(2000);
  digitalWrite(ledPin, LOW);
  delayMicroseconds(300);
  digitalWrite(ledPin, HIGH);
  delayMicroseconds(500);
  digitalWrite(ledPin, LOW);
  delayMicroseconds(300);
   digitalWrite(ledPin, HIGH);
  delayMicroseconds(500);;
  digitalWrite(ledPin, LOW);
  delayMicroseconds(300);
   digitalWrite(ledPin, HIGH);
  delayMicroseconds(500);
  digitalWrite(ledPin, LOW);
  delayMicroseconds(300);
   digitalWrite(ledPin, HIGH);
  delayMicroseconds(1000);
  digitalWrite(ledPin, LOW);
  delayMicroseconds(300);
   digitalWrite(ledPin, HIGH);
  delayMicroseconds(500);
  digitalWrite(ledPin, LOW);
  delayMicroseconds(300);
   digitalWrite(ledPin, HIGH);
  delayMicroseconds(1000);
  digitalWrite(ledPin, LOW);
  delayMicroseconds(300);
   digitalWrite(ledPin, HIGH);
  delayMicroseconds(1000);
  digitalWrite(ledPin, LOW);
  delay(3000);

}
https://dl.dropbox.com/u/6634904/A500_TSOP312SERIES_DATASHEET%20%281%29.pdf
https://dl.dropbox.com/u/6634904/X100_ld_274-3.pdf

Resistor= 100 Ohm
capacitor = 4,6 microF

What is wrong?

greetings,
bauerbyter


* simpleIR_Schaltplan.jpg (574.69 KB, 1998x3084 - viewed 16 times.)
« Last Edit: October 22, 2012, 03:15:43 pm by bauerbyter » Logged

Maine
Offline Offline
Sr. Member
****
Karma: 14
Posts: 417
Caution: Explosives in use.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't know much about this subject, but is it possible that your receiver is picking up IR from sources (the sun, house lights, etc.) other than your intended transmitter?
Logged

"Anyone who isn't confused really doesn't understand the situation."

Electronic props for Airsoft, paintball, and laser tag -> www.nightscapetech.com

Offline Offline
Sr. Member
****
Karma: 2
Posts: 260
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The Serial commands between the Pulse-In commands slows your code down, so it misses pulses.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you both, but there is no light, i tested it in a dark room.

Quote
The Serial commands between the Pulse-In commands slows your code down, so it misses pulses.


Thank you, i dont know that. I will test it.

Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have another question:
I turn the LED ON for example 1000microseconds and then off, in other IR-Codes they do it like this:

Code:
void oscillationWrite(int pin, int time) {
  for(int i = 0; i <= time/26; i++) {
    digitalWrite(pin, HIGH);
    delayMicroseconds(13);
    digitalWrite(pin, LOW);
    delayMicroseconds(13);
  }
}

int time is in my example = 1000.
I understand that this is because of 38kHz, but why do the toggle so often, not only on/off every 1000 microseconds like i do?

greetings
bauerbyter
(and again sorry for my bad english ^^)
Logged

Idaho, US
Offline Offline
God Member
*****
Karma: 19
Posts: 868
Special User
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

5mm LEDs are generally only rated for 20mA continuous, but can handle 100mA when pulsed. So by pulsing at 38kHz, you can run at 5 times the power which gives you more range and better signal/noise margin.

Were you using a simple phototransistor or photodiode, 38kHz should not be necessary for a simple experiment. However the datasheet for your receiver IC says "The TSOP314.. is optimized to suppress almost all spurious pulses from energy saving fluorescent lamps but will also suppress some data signals." which suggests it's going to reject anything without a modulated pulse. The datasheet lists several parts with filters for 30kHz through 56kHz. You'll need to match your transmitter modulation kHz to your receiver.
Logged

the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 159
Posts: 2916
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

@OP, the jpg file doesn't open properly for me, but you need a current limiting resistor in the
Led line, which I cannot see.

Also, you don't indicate which IR detector you are using, but I think the hookup is wrong. There should be no R in the connection to Vcc [connect directly to 5V], and you probably need a pullup-R [eg 4.7K] on the detector output pin.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 65
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@tylernt: thank you, now i understand!
@oric_dan: Pin13 has a buildin resistor, so far as i know. (Works for me ^^)
 as i mention in the first post, i use this reciever: https://dl.dropbox.com/u/6634904/A500_TSOP312SERIES_DATASHEET%20%281%29.pdf
38kHz.

There  is only a resistor in the connection to Vcc in the Datasheet (ApplicationCurcuit)
Do i also need a pullup?

Logged

Idaho, US
Offline Offline
God Member
*****
Karma: 19
Posts: 868
Special User
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There  is only a resistor in the connection to Vcc in the Datasheet (ApplicationCurcuit)
Do i also need a pullup?
If I read the datasheet right, "Output Active Low", then you should get a more reliable signal by using a pullup resistor.

Good news though, rather than physically wiring in a separate component, you can enable the Arduino's internal pullup resistor on the appropriate input pin. Simply change 'INPUT' in your pinMode command to INPUT_PULLUP.

EDIT: I should have looked more closely. The datasheet block diagram shows a 30k pullup resistor inside the receiver IC already. So a pullup on the Arduino would be unnecessary.
« Last Edit: October 23, 2012, 04:01:03 pm by tylernt » Logged

the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 159
Posts: 2916
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Oops, sorry I missed the reference to the pdf file. In that case, your ckt looks ok, and the part does have an internal pullup-R, so you should be getting something out without using an external pullup.

However, your first code example is wrong, as you turn on/off for 500/300 usec, which is only 1250 hz.

You have to pulse the Led at 38-khz as indicated in the other post. As the block diagram shows, those devices have an internal bandpass filter for specific frequencies. They use that to block out background illumination.

Also, you have to be sure the driving frequency matches the part you actually have, as they range over 30 to 56 Khz parts, per the datasheet.

Also, I'm not sure about the internal resistor on the output pin. I always use external current limiting Rs with Leds.
Logged

Pages: [1]   Go Up
Jump to: