← If / else with sensors lesson New set →

Electronics Worksheet: If Else with Sensors

Electronics lesson 24: If / else with sensors · Set 588 · 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.🤖 if (temperature > 34) { show “Hot” } else if (temperature > 25) { show “Warm” } else { show “Cool” }
    The temperature is 18 °C. What is shown?
    (a) Warm (b) Hot (c) Cool
  2. 2.🤖 if (temperature > 36) { show “Hot” } else if (temperature > 25) { show “Warm” } else { show “Cool” }
    The temperature is 21 °C. What is shown?
    (a) Hot (b) Warm (c) Cool
  3. 3.🤖 if (light < 200 AND motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 80 and motion is detected (true). What happens?
    (a) porch lamp ON (b) porch lamp OFF
  4. 4.🤖 if (light < 400 OR motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 250 and motion is detected (true). What happens?
    (a) porch lamp OFF (b) porch lamp ON
  5. 5.🤖 if (sound > 70) { red LED ON } else { green LED ON }
    The sound sensor reads 63. What happens?
    (a) green LED ON (b) red LED ON
  6. 6.🤖 if (temperature > 36) { show “Hot” } else if (temperature > 19) { show “Warm” } else { show “Cool” }
    The temperature is 44 °C. What is shown?
    (a) Hot (b) Cool (c) Warm
  7. 7.🤖 if (distance < 30) { buzzer beeps } else { buzzer is silent }
    The distance sensor reads 25 cm. What happens?
    (a) buzzer is silent (b) buzzer beeps
  8. 8.🤖 if (light < 200) { lamp ON } else { lamp OFF }
    The light sensor reads 157. What happens?
    (a) lamp OFF (b) lamp ON
  9. 9.🤖 if (sound > 60) { red LED ON } else { green LED ON }
    The sound sensor reads 56. What happens?
    (a) red LED ON (b) green LED ON
  10. 10.🤖 “if (A AND B)” is true when … (a) both are false (b) only B is true (c) only A is true (d) both A and B are true
  11. 11.🤖 if (sound > 70) { red LED ON } else { green LED ON }
    The sound sensor reads 69. What happens?
    (a) green LED ON (b) red LED ON
  12. 12.🤖 if (light < 300 OR motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 470 and motion is detected (true). What happens?
    (a) porch lamp ON (b) porch lamp OFF
  13. 13.🤖 In “if (temp > 30)”, what runs when temp is exactly 30? (a) the else part (b) neither part (c) the if part (d) both parts
  14. 14.🤖 if (light < 400 OR motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 370 and motion is detected (true). What happens?
    (a) porch lamp OFF (b) porch lamp ON
  15. 15.🤖 if (temperature > 31) { show “Hot” } else if (temperature > 19) { show “Warm” } else { show “Cool” }
    The temperature is 10 °C. What is shown?
    (a) Hot (b) Cool (c) Warm
  16. 16.🤖 if (moisture < 40) { pump ON } else { pump OFF }
    The soil moisture sensor reads 42 %. What happens?
    (a) pump OFF (b) pump ON
  17. 17.🤖 if (light < 200 AND motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 650 and motion is detected (true). What happens?
    (a) porch lamp ON (b) porch lamp OFF
  18. 18.🤖 if (temperature > 34) { show “Hot” } else if (temperature > 22) { show “Warm” } else { show “Cool” }
    The temperature is 15 °C. What is shown?
    (a) Cool (b) Warm (c) Hot
  19. 19.🤖 if (distance < 15) { buzzer beeps } else { buzzer is silent }
    The distance sensor reads 6 cm. What happens?
    (a) buzzer beeps (b) buzzer is silent
  20. 20.🤖 if (light < 200) { lamp ON } else { lamp OFF }
    The light sensor reads 344. What happens?
    (a) lamp ON (b) lamp OFF
  21. 21.🤖 if (moisture < 50) { pump ON } else { pump OFF }
    The soil moisture sensor reads 46 %. What happens?
    (a) pump OFF (b) pump ON
  22. 22.🤖 if (distance < 15) { buzzer beeps } else { buzzer is silent }
    The distance sensor reads 18 cm. What happens?
    (a) buzzer is silent (b) buzzer beeps
  23. 23.🤖 if (light < 400) { lamp ON } else { lamp OFF }
    The light sensor reads 263. What happens?
    (a) lamp OFF (b) lamp ON
  24. 24.🤖 if (light < 200 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 OFF (b) porch lamp ON
  25. 25.🤖 if (temperature > 28) { fan ON } else { fan OFF }
    The temperature sensor reads 23 °C. What happens?
    (a) fan ON (b) fan OFF
  26. 26.🤖 if (temperature > 34) { show “Hot” } else if (temperature > 23) { show “Warm” } else { show “Cool” }
    The temperature is 18 °C. What is shown?
    (a) Warm (b) Cool (c) Hot
  27. 27.🤖 if (temperature > 37) { show “Hot” } else if (temperature > 18) { show “Warm” } else { show “Cool” }
    The temperature is 16 °C. What is shown?
    (a) Warm (b) Hot (c) Cool
  28. 28.🤖 if (moisture < 50) { pump ON } else { pump OFF }
    The soil moisture sensor reads 30 %. What happens?
    (a) pump ON (b) pump OFF
  29. 29.🤖 if (temperature > 33) { show “Hot” } else if (temperature > 19) { show “Warm” } else { show “Cool” }
    The temperature is 39 °C. What is shown?
    (a) Cool (b) Warm (c) Hot
  30. 30.🤖 if (light < 200 AND motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 480 and motion is not detected (false). What happens?
    (a) porch lamp OFF (b) porch lamp ON
  31. 31.🤖 if (light < 300 OR motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 640 and motion is not detected (false). What happens?
    (a) porch lamp ON (b) porch lamp OFF
  32. 32.🤖 if (light < 400 OR motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 200 and motion is detected (true). What happens?
    (a) porch lamp ON (b) porch lamp OFF
  33. 33.🤖 if (sound > 60) { red LED ON } else { green LED ON }
    The sound sensor reads 74. What happens?
    (a) red LED ON (b) green LED ON
  34. 34.🤖 if (moisture < 40) { pump ON } else { pump OFF }
    The soil moisture sensor reads 50 %. What happens?
    (a) pump OFF (b) pump ON
  35. 35.🤖 if (light < 200 AND motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 530 and motion is not detected (false). What happens?
    (a) porch lamp OFF (b) porch lamp ON
  36. 36.🤖 if (light < 300 AND motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 120 and motion is detected (true). What happens?
    (a) porch lamp OFF (b) porch lamp ON
  37. 37.🤖 if (distance < 30) { buzzer beeps } else { buzzer is silent }
    The distance sensor reads 33 cm. What happens?
    (a) buzzer is silent (b) buzzer beeps
  38. 38.🤖 if (distance < 20) { buzzer beeps } else { buzzer is silent }
    The distance sensor reads 16 cm. What happens?
    (a) buzzer beeps (b) buzzer is silent
  39. 39.🤖 if (light < 200 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
  40. 40.🤖 if (sound > 60) { red LED ON } else { green LED ON }
    The sound sensor reads 55. What happens?
    (a) red LED ON (b) green LED ON

Answer key

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

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