Arduino ultrasonic sensor with an IR emitter - coding question

I’m having a hard time figuring out why my project ain’t working properly, so i hope some of you could help me out.

I am trying to make an IR led send any signal (random or specific, doesn’t matter), when the ultrasonic sensor senses something nearby (fx > 20), however for some reason the IR reciever on the other part of the project does not register the IR signal.

The reciever does however react to the IR signal from your standard tv remote, and i know that the ultrasonic sensor is working (i tested it by making a normal led light up when somethings is within 20 cm to the sensor), so i assume it is the signal i am trying to send via the IR led, that is faulty.

I am using the IRremote library on an Arduino Uno

These are my codes:

IR reciever:

#include <IRremote.h>

int RECV_PIN = 2;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
Serial.begin(9600);
irrecv.enableIRIn();
pinMode(13,OUTPUT);
}

void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
irrecv.resume();

digitalWrite(13,HIGH);
}
}

IR emitter + ultrasonic sensor:

#include <IRremote.h>
#define ECHOPIN 2
#define TRIGPIN 3

IRsend irsend;

void setup()
{
Serial.begin(9600);
pinMode(ECHOPIN, INPUT);
pinMode(TRIGPIN, OUTPUT);
}

void loop()
{
digitalWrite(TRIGPIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIGPIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIGPIN, LOW);
int distance = pulseIn(ECHOPIN, HIGH);
distance= distance/58;
Serial.println(distance);
delay(100);

if (distance < 20)
{
irsend.sendSony(0xa90, 12);
delay(100);
}
}

Any help is appreciated

Look at the IR emitter though the view finder of a camera to see if it is being lit.

It does not seem to emit anything (looking through my camera)

Then it is either wired up the wrong way round or it is faulty. What resistor value are you using with it..

I believe i have wired it properly (just tested by switching the pins). I am using a 220 ohms resistor on the IR led (since i do not own the recommend 200 ohm)

Nikolaj11:
It does not seem to emit anything (looking through my camera)

Can you confirm your camera is not a DSLR?

That resistor is fine. So if a visible LED works and the IR does not then it s faulty.

I just tried to set the IR led HIGH when something is close to the ultrasonic sensor, which worked as i looked through the same camera

The problem has been solved, the coding was fine but i was the idiot who hadn't defined the pins correctly