IR from scratch

I’m one of those programmers who needs to know how everything works in a code to learn. I don’t like using code designed by someone else, besides just learning from it. Now, to the point…

Is it possible for me to just put the IR sensor on a digital input on the default code? I’ve been trying the sensor on a dig i/o. I told it to print the value to the terminal IFI loader screen, but it only equals 1, even when the sensor is not in. Am I doing something wrong?

The sensor goes from high to low many times a second with the beacon working properly. You need to “measure” the low times in order to find out which beacon it is. This will also allow you to search for it.

How do you “measure” the values?

One way of doing it is putting it on an interrupt. The robot controller just does not poll digital inputs fast enough to pick up the signal. Another way would require you to design an external circuit with a memory chip on it that would store several bits before being read (and cleared) by the RC. This would be quite complicated to do properly in 3 weeks :slight_smile: so just go with the interrupts.

Start with the FAQ and then get a copy of the code and start with receiver.c. Once you understand what’s going on there, start working on understanding the code in tracker.c. The interface between the two pieces of code is the structure “Sensor_Stats”. Once you’ve mastered that, move on to navigate.c.


Even on a polled digital input you should be able to see 0’s mixed in with the 1’s even pointing most IR rmote controls at the sensor. However, as others have noted you won’t be able to use this on a competition robot, because you cannot poll it fast enough to follow the beacon sequence of IR flashes.

All I get when I print the command to the screen are 1’s.

Are you using your beacon to generate the IR or something else?
I have encountered IR remote controls that aren’t broadcasting at the 40kHz of the IR sensor, and so don’t get detected.

Double check your IR sensor hookup. Looking at the from of the IR sensor:
pin 1 (on the left) should be your white or signal wire,
pin 2 (middle) should be your black or ground wire,
pin 3 (on right) should be your red or 5v wire.

Try a different IR sensor in case it’s bad.

Have you verified the operation of your beacon?

Here’s some code to double check your setup. This code runs everything (beacon included) on the FRC. See the ReadMe for what’s connected to what. I setup digital IO pin 6 to do what you’re attempting with the IR sensor. You can use this to see if the problem is with the sensor or beacon before you go too crazy.

Oops. I mistyped rc_dig_in06. You’ll see it when you build. Sorry about that chief. (60.7 KB) (60.7 KB)