My 1st Project -- Light Sensing IR Remote Control

Studied computer in silicon valley back to 2 decades again and dropped out for another major. 20 years later, picked up an Arduino board and influenced by friends and wanted to start my first project in life. Got stuck somewhere, wish to receive help to complete this project…

Project is simple:

  1. If light is turned on, IR emitter gives beam to turn on fan.
  2. If light is turned off, IR emitter gives beam to turn off fan.
  3. Light level is checked ever second. IR emitter won’t give beam to if status is current.


  1. All beam signal is RAW, valid, working without function.
  2. Photocell working fine. Reading is stable.

I used nested (If/ else if) function to decide if

  • Light level is on/ off to turn fan on/ off
  • Check status of the fan to avoid sending the beam identical to fan status.
  • If a light level check sensing the light is on (above ‘PresetLightLevel’) and I try to change a variable named (PrevState) after or before firing a beam, the Photocell does not give more reading in the next loop until the light is turn off (below ‘PresetLightLevel’).

Any help is appreciated :smiley:

IRTRANS20_test.ino (5.77 KB)

What is the code doing? The if/else if/else if block looks ok at first glance and setting the PrevState in the functions looks ok.