I tested your code with the simulator and it worked OK.
Check if there are errors in your connection or if your sensor or transmitter has problems.
To test the transmitter you can use the camera of any cell phone.
Point the emitter at your cell phone and see if any light appears on your cell phone's camera screen.
If it doesn't appear, your transmitter has a problem.