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