← If / else with sensors lesson New set →

Electronics Worksheet: If Else with Sensors

Electronics lesson 24: If / else with sensors · Set 335 · 40 questions
TalentJR

Remember (Test, then choose): Put the reading into the condition: true → the if part, false → the else part. > means strictly more and < strictly less; an equal reading makes them false. AND: both true. OR: at least one true. In a chain, the first true condition wins.

NameDateTime takenScore ___ / 40
  1. 1.🤖 In “if (temp > 30)”, what runs when temp is exactly 30? (a) neither part (b) the else part (c) the if part (d) both parts
  2. 2.🤖 if (moisture < 30) { pump ON } else { pump OFF }
    The soil moisture sensor reads 46 %. What happens?
    (a) pump ON (b) pump OFF
  3. 3.🤖 if (temperature > 32) { fan ON } else { fan OFF }
    The temperature sensor reads 28 °C. What happens?
    (a) fan ON (b) fan OFF
  4. 4.🤖 if (light < 300 OR motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 190 and motion is not detected (false). What happens?
    (a) porch lamp OFF (b) porch lamp ON
  5. 5.🤖 if (light < 300 AND motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 500 and motion is detected (true). What happens?
    (a) porch lamp OFF (b) porch lamp ON
  6. 6.🤖 if (light < 300 AND motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 400 and motion is not detected (false). What happens?
    (a) porch lamp OFF (b) porch lamp ON
  7. 7.🤖 “if (A AND B)” is true when … (a) only A is true (b) both A and B are true (c) both are false (d) only B is true
  8. 8.🤖 if (distance < 10) { buzzer beeps } else { buzzer is silent }
    The distance sensor reads 5 cm. What happens?
    (a) buzzer is silent (b) buzzer beeps
  9. 9.🤖 if (distance < 20) { buzzer beeps } else { buzzer is silent }
    The distance sensor reads 15 cm. What happens?
    (a) buzzer is silent (b) buzzer beeps
  10. 10.🤖 if (sound > 70) { red LED ON } else { green LED ON }
    The sound sensor reads 80. What happens?
    (a) green LED ON (b) red LED ON
  11. 11.🤖 if (light < 300 OR motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 160 and motion is detected (true). What happens?
    (a) porch lamp OFF (b) porch lamp ON
  12. 12.🤖 if (light < 200 AND motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 340 and motion is not detected (false). What happens?
    (a) porch lamp OFF (b) porch lamp ON
  13. 13.🤖 if (sound > 70) { red LED ON } else { green LED ON }
    The sound sensor reads 55. What happens?
    (a) red LED ON (b) green LED ON
  14. 14.🤖 if (sound > 70) { red LED ON } else { green LED ON }
    The sound sensor reads 58. What happens?
    (a) green LED ON (b) red LED ON
  15. 15.🤖 if (temperature > 36) { show “Hot” } else if (temperature > 21) { show “Warm” } else { show “Cool” }
    The temperature is 16 °C. What is shown?
    (a) Hot (b) Cool (c) Warm
  16. 16.🤖 if (sound > 70) { red LED ON } else { green LED ON }
    The sound sensor reads 90. What happens?
    (a) red LED ON (b) green LED ON
  17. 17.🤖 if (sound > 70) { red LED ON } else { green LED ON }
    The sound sensor reads 72. What happens?
    (a) green LED ON (b) red LED ON
  18. 18.🤖 if (sound > 70) { red LED ON } else { green LED ON }
    The sound sensor reads 71. What happens?
    (a) red LED ON (b) green LED ON
  19. 19.🤖 if (sound > 80) { red LED ON } else { green LED ON }
    The sound sensor reads 75. What happens?
    (a) red LED ON (b) green LED ON
  20. 20.🤖 if (light < 200 OR motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 120 and motion is not detected (false). What happens?
    (a) porch lamp OFF (b) porch lamp ON
  21. 21.🤖 if (temperature > 34) { show “Hot” } else if (temperature > 19) { show “Warm” } else { show “Cool” }
    The temperature is 18 °C. What is shown?
    (a) Warm (b) Hot (c) Cool
  22. 22.🤖 if (temperature > 37) { show “Hot” } else if (temperature > 24) { show “Warm” } else { show “Cool” }
    The temperature is 38 °C. What is shown?
    (a) Cool (b) Hot (c) Warm
  23. 23.🤖 if (temperature > 32) { show “Hot” } else if (temperature > 19) { show “Warm” } else { show “Cool” }
    The temperature is 10 °C. What is shown?
    (a) Hot (b) Warm (c) Cool
  24. 24.🤖 if (light < 400 OR motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 190 and motion is not detected (false). What happens?
    (a) porch lamp ON (b) porch lamp OFF
  25. 25.🤖 if (moisture < 50) { pump ON } else { pump OFF }
    The soil moisture sensor reads 41 %. What happens?
    (a) pump OFF (b) pump ON
  26. 26.🤖 if (light < 200 AND motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 520 and motion is not detected (false). What happens?
    (a) porch lamp ON (b) porch lamp OFF
  27. 27.🤖 if (light < 400) { lamp ON } else { lamp OFF }
    The light sensor reads 259. What happens?
    (a) lamp ON (b) lamp OFF
  28. 28.🤖 if (moisture < 30) { pump ON } else { pump OFF }
    The soil moisture sensor reads 13 %. What happens?
    (a) pump ON (b) pump OFF
  29. 29.🤖 if (temperature > 31) { show “Hot” } else if (temperature > 26) { show “Warm” } else { show “Cool” }
    The temperature is 19 °C. What is shown?
    (a) Hot (b) Warm (c) Cool
  30. 30.🤖 if (temperature > 36) { show “Hot” } else if (temperature > 23) { show “Warm” } else { show “Cool” }
    The temperature is 37 °C. What is shown?
    (a) Hot (b) Cool (c) Warm
  31. 31.🤖 if (temperature > 36) { show “Hot” } else if (temperature > 26) { show “Warm” } else { show “Cool” }
    The temperature is 15 °C. What is shown?
    (a) Cool (b) Hot (c) Warm
  32. 32.🤖 if (temperature > 36) { show “Hot” } else if (temperature > 21) { show “Warm” } else { show “Cool” }
    The temperature is 11 °C. What is shown?
    (a) Hot (b) Warm (c) Cool
  33. 33.🤖 if (distance < 30) { buzzer beeps } else { buzzer is silent }
    The distance sensor reads 34 cm. What happens?
    (a) buzzer is silent (b) buzzer beeps
  34. 34.🤖 if (light < 400 AND motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 490 and motion is not detected (false). What happens?
    (a) porch lamp ON (b) porch lamp OFF
  35. 35.🤖 if (light < 200) { lamp ON } else { lamp OFF }
    The light sensor reads 90. What happens?
    (a) lamp OFF (b) lamp ON
  36. 36.🤖 if (sound > 80) { red LED ON } else { green LED ON }
    The sound sensor reads 63. What happens?
    (a) red LED ON (b) green LED ON
  37. 37.🤖 if (temperature > 38) { show “Hot” } else if (temperature > 21) { show “Warm” } else { show “Cool” }
    The temperature is 32 °C. What is shown?
    (a) Hot (b) Warm (c) Cool
  38. 38.🤖 if (light < 400 AND motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 320 and motion is not detected (false). What happens?
    (a) porch lamp ON (b) porch lamp OFF
  39. 39.🤖 if (light < 300 AND motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 460 and motion is not detected (false). What happens?
    (a) porch lamp ON (b) porch lamp OFF
  40. 40.🤖 if (sound > 60) { red LED ON } else { green LED ON }
    The sound sensor reads 57. What happens?
    (a) green LED ON (b) red LED ON

Answer key

  1. the else part
  2. pump OFF
  3. fan OFF
  4. porch lamp ON
  5. porch lamp OFF
  6. porch lamp OFF
  7. both A and B are true
  8. buzzer beeps
  9. buzzer beeps
  10. red LED ON
  11. porch lamp ON
  12. porch lamp OFF
  13. green LED ON
  14. green LED ON
  15. Cool
  16. red LED ON
  17. red LED ON
  18. red LED ON
  19. green LED ON
  20. porch lamp ON
  21. Cool
  22. Hot
  23. Cool
  24. porch lamp ON
  25. pump ON
  26. porch lamp OFF
  27. lamp ON
  28. pump ON
  29. Cool
  30. Hot
  31. Cool
  32. Cool
  33. buzzer is silent
  34. porch lamp OFF
  35. lamp ON
  36. green LED ON
  37. Warm
  38. porch lamp OFF
  39. porch lamp OFF
  40. green LED ON

Free electronics lessons, practice and worksheets at talentjr.in/electronics-for-kids