is my ir sensor stuck?

Hi there.I am just a newbie trying to learn arduino and IR communication. I was trying to build a laser tag for a start but i think my sensor got stuck. sometimes when it detects signal it keeps reducing health even after i dont send signals. I couldnt find a solution. I guess there is a problem with my codes. Here it is:
quick edit: my IR sensor is TSOP4836

sil.ino (1.13 KB)

More members will see your code if you post it in accordance with the forum guidelines.

Why don't You use code tags so all helpers can reda the code? Upper left symbol in this window.
"Your sensor".... is what?

im sorry as i said im new to this forum. here is my code:

#include <IRremote.h>
#include <LCD5110_Basic.h>
LCD5110 myGLCD(8,9,10,11,12);
extern uint8_t SmallFont[];
extern uint8_t MediumNumbers[];
extern uint8_t BigNumbers[];
IRrecv irrecv(4);
#define HIT 16761405

int health=100;
decode_results results;

void setup() {
pinMode(13, OUTPUT);
irrecv.enableIRIn();
pinMode(7, OUTPUT);
digitalWrite(7,HIGH);
myGLCD.InitLCD();
myGLCD.setContrast(60);
myGLCD.clrScr();
Serial.begin(9600);
}

void loop() {
if (health >>0){
myGLCD.setFont(SmallFont);
myGLCD.print("KALAN CANINIZ:",5,1);
myGLCD.setFont(BigNumbers);
myGLCD.printNumI(health,25,20);
}
else if (health == 0){
   myGLCD.setFont(SmallFont);
  myGLCD.print("YENILDIN",5,1);  
   myGLCD.setFont(SmallFont);
  myGLCD.print("CANIN 0",25,20);  
}
if (irrecv.decode(&results))
{
  Serial.println(results.value);
    Serial.println(health);
  irrecv.resume();
 }
if (results.value== HIT){
health--;
delay(400);
}
if (health <0)
 myGLCD.enableSleep();
if (health<0)
 digitalWrite(13, HIGH);
}
void loop() {
if (health >>0){

Why the shift?

Please remember to use code tags when posting code.

Shift? I'm sorry my english is not good that much is there a problam in this piece of code:

void loop() {
if (health >>0){
[code]

is a right-shift operator, but in this case isn't doing anything useful because you're shifting zero places.

Did you mean simply > ?

I tried but nothing changed. I couldnt find what is the problem...

What if you change this code snippet in your code as follows. What do you see?

if (results.value== HIT){
   Serial.println(results.value); // NEW LINE HERE
   health--;
   delay(400);
}

No it doesnt change anything :frowning: . I found a thing but couldnt understand its logic. when i send ir signals from infrared LED it stuck but when i use a remote control and push the button hard it doesnt stuck. Got confused actually.. :frowning:

It looks like Your IR transmitting diode is not working. Using a remote tells that the receiver looks like okey.
Attach the wiring diagram.

Well the thing is that transmitting diode works perfect(according to serial port). I am getting same problems with remote too. If I push the button on remote rough my health decreases one by one but if I push that button with less power(i mean just pushing it) health decreases continiously... I know i am just a newbie but i think there is a problem with code :frowning:

Can You attache the wiring for the IR transmitter'? it's good that Serial shows action but does any IR radiate?

I'm a newbie myself, so take what I say with a grain of salt - and it might be wrong. But what I was getting at in my earlier post is this...

aren't you just endlessly looping on this

if (results.value== HIT){
    health--;
    delay(400);
}

after the first transmit?

What if you placed your check and decrement inside the preceding if statement, like this:

if (irrecv.decode(&results))
{
   Serial.println(results.value);
   Serial.println(health);
   if (results.value== HIT){
     health--;
     delay(400);
     }
   irrecv.resume();
}

Dear Steve20016 thank you for your advice it worked. :slight_smile:

Bingo! Cheers!

lokum096:
Dear Steve20016 thank you for your advice it worked. :slight_smile:

You're welcome! My first "solve" on the forum... glad I can pay it forward after learning so much from everyone's responses throughout the forum.

(Your question has actually inspired me to think about adding an IR control feature to a project I'm currently working on!)

@steve20016
Congratulations! I feel the same in those moments.