Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Table of Contents

Task 1

Modify your blinky program such that it blinks faster when the LDR is covered, and slower when it is exposed to light.

...

Check whether the sensorValue is greater than say, 512 (approx. half of the maximum, which is 1023) using an if condition.

  • The threshold can be set to 512 (approx. half of the maximum, which is 1023) if you chose Option 2 in the Connecting LDR

    ]] ></ac:plain-text-link-body></ac:link> section.</li><li>If

    section.

  • If you chose Option 1, you might need to find the threshold experimentally (though 512 should work in most cases). Use the program in the

    <a href="https://wiki.nus.edu.sg/display/Arduino/Serial+Communication#SerialCommunication-analogRead()SerialExample">analogRead()&nbsp;Serial Example</a>&nbsp;section

    analogRead() Serial Example section to print the reading 1) when the LDR is fully exposed to light and 2) when the LDR is fully covered. The mean of the two can be used as the threshold.

    </li></ul><h3>Task 2</h3><p>Modify

Task 2

Modify your program such

...

that

  • When the switch is

    off<ul><li>The

    off

    • The message OFF is printed

    repeatedly&nbsp;via
    • repeatedly via Serial once every second, and the LED remains fully turned off.

    </li></ul></li><li>When
  • When the switch is

    on<ul><li>The

    on

    • The LED will gradually turn on and off repeatedly at a fast rate when LDR is covered, and at a slower rate when it is exposed to light.

    </li><li>The
    • The message ON is printed repeatedly via Serial every time the LED brightness is maximum (i.e., one message every on-off cycle of the LED).

    </li></ul></li></ul>