The project switches at the wrong time, or never

  • LDR
  • Soil sensor
  • Gas sensor
  • Sound sensor
  • IR

Why it happens

  • Each sensor and room gives different numbers.
  • Some modules give a low number when wet or dark, others a high one.

How to fix it

  1. Print the sensor's number in the Serial Monitor.
  2. Write down the number for dry and for wet (or dark and bright).
  3. Use a number halfway between in the code.
  4. If it works backwards, swap < and >.
  5. On modules with a blue screw, the screw sets only the digital (D0) output.

It worked if: It switches at the right moment three times in a row.

From how the part works. Explained from how the part works; not tried on a real circuit for this page.

Didn't help? Search another error or ask us.