← If / else with sensors lesson New set →

Electronics Worksheet: If Else with Sensors

Electronics lesson 24: If / else with sensors · Set 315 · 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 (light < 300) { lamp ON } else { lamp OFF }
    The light sensor reads 287. What happens?
    (a) lamp OFF (b) lamp ON
  2. 2.🤖 if (light < 200 AND motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 460 and motion is detected (true). What happens?
    (a) porch lamp ON (b) porch lamp OFF
  3. 3.🤖 if (light < 400 OR motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 380 and motion is detected (true). What happens?
    (a) porch lamp OFF (b) porch lamp ON
  4. 4.🤖 if (light < 200) { lamp ON } else { lamp OFF }
    The light sensor reads 51. What happens?
    (a) lamp ON (b) lamp OFF
  5. 5.🤖 “if (A AND B)” is true when … (a) only A is true (b) both A and B are true (c) only B is true (d) both are false
  6. 6.🤖 if (temperature > 35) { show “Hot” } else if (temperature > 22) { show “Warm” } else { show “Cool” }
    The temperature is 39 °C. What is shown?
    (a) Cool (b) Warm (c) Hot
  7. 7.🤖 if (temperature > 37) { show “Hot” } else if (temperature > 22) { show “Warm” } else { show “Cool” }
    The temperature is 18 °C. What is shown?
    (a) Warm (b) Cool (c) Hot
  8. 8.🤖 In “if (temp > 30)”, what runs when temp is exactly 30? (a) the if part (b) both parts (c) the else part (d) neither part
  9. 9.🤖 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
  10. 10.🤖 if (temperature > 30) { show “Hot” } else if (temperature > 22) { show “Warm” } else { show “Cool” }
    The temperature is 38 °C. What is shown?
    (a) Warm (b) Hot (c) Cool
  11. 11.🤖 if (light < 200) { lamp ON } else { lamp OFF }
    The light sensor reads 169. What happens?
    (a) lamp ON (b) lamp OFF
  12. 12.🤖 if (light < 500) { lamp ON } else { lamp OFF }
    The light sensor reads 374. What happens?
    (a) lamp ON (b) lamp OFF
  13. 13.🤖 if (moisture < 40) { pump ON } else { pump OFF }
    The soil moisture sensor reads 41 %. What happens?
    (a) pump ON (b) pump OFF
  14. 14.🤖 if (light < 200) { lamp ON } else { lamp OFF }
    The light sensor reads 187. What happens?
    (a) lamp OFF (b) lamp ON
  15. 15.🤖 if (temperature > 25) { fan ON } else { fan OFF }
    The temperature sensor reads 22 °C. What happens?
    (a) fan ON (b) fan OFF
  16. 16.🤖 if (temperature > 34) { show “Hot” } else if (temperature > 18) { show “Warm” } else { show “Cool” }
    The temperature is 35 °C. What is shown?
    (a) Cool (b) Hot (c) Warm
  17. 17.🤖 if (temperature > 34) { show “Hot” } else if (temperature > 25) { show “Warm” } else { show “Cool” }
    The temperature is 23 °C. What is shown?
    (a) Warm (b) Hot (c) Cool
  18. 18.🤖 if (temperature > 36) { show “Hot” } else if (temperature > 25) { show “Warm” } else { show “Cool” }
    The temperature is 32 °C. What is shown?
    (a) Warm (b) Cool (c) Hot
  19. 19.🤖 if (temperature > 36) { show “Hot” } else if (temperature > 26) { show “Warm” } else { show “Cool” }
    The temperature is 39 °C. What is shown?
    (a) Hot (b) Cool (c) Warm
  20. 20.🤖 if (temperature > 30) { show “Hot” } else if (temperature > 20) { show “Warm” } else { show “Cool” }
    The temperature is 34 °C. What is shown?
    (a) Warm (b) Hot (c) Cool
  21. 21.🤖 if (moisture < 40) { pump ON } else { pump OFF }
    The soil moisture sensor reads 25 %. What happens?
    (a) pump ON (b) pump OFF
  22. 22.🤖 if (temperature > 36) { show “Hot” } else if (temperature > 18) { show “Warm” } else { show “Cool” }
    The temperature is 28 °C. What is shown?
    (a) Hot (b) Cool (c) Warm
  23. 23.🤖 if (temperature > 32) { show “Hot” } else if (temperature > 26) { show “Warm” } else { show “Cool” }
    The temperature is 21 °C. What is shown?
    (a) Warm (b) Cool (c) Hot
  24. 24.🤖 if (light < 300 AND motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 110 and motion is detected (true). What happens?
    (a) porch lamp ON (b) porch lamp OFF
  25. 25.🤖 if (light < 300) { lamp ON } else { lamp OFF }
    The light sensor reads 163. What happens?
    (a) lamp OFF (b) lamp ON
  26. 26.🤖 if (light < 200 AND motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 540 and motion is not detected (false). What happens?
    (a) porch lamp OFF (b) porch lamp ON
  27. 27.🤖 if (light < 200 OR motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 290 and motion is detected (true). What happens?
    (a) porch lamp OFF (b) porch lamp ON
  28. 28.🤖 if (distance < 30) { buzzer beeps } else { buzzer is silent }
    The distance sensor reads 36 cm. What happens?
    (a) buzzer beeps (b) buzzer is silent
  29. 29.🤖 if (moisture < 50) { pump ON } else { pump OFF }
    The soil moisture sensor reads 38 %. What happens?
    (a) pump ON (b) pump OFF
  30. 30.🤖 if (light < 300 AND motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 260 and motion is detected (true). What happens?
    (a) porch lamp OFF (b) porch lamp ON
  31. 31.🤖 if (temperature > 32) { show “Hot” } else if (temperature > 26) { show “Warm” } else { show “Cool” }
    The temperature is 30 °C. What is shown?
    (a) Cool (b) Hot (c) Warm
  32. 32.🤖 if (light < 400 OR motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 620 and motion is not detected (false). What happens?
    (a) porch lamp ON (b) porch lamp OFF
  33. 33.🤖 if (distance < 15) { buzzer beeps } else { buzzer is silent }
    The distance sensor reads 7 cm. What happens?
    (a) buzzer is silent (b) buzzer beeps
  34. 34.🤖 if (temperature > 33) { show “Hot” } else if (temperature > 18) { show “Warm” } else { show “Cool” }
    The temperature is 38 °C. What is shown?
    (a) Cool (b) Hot (c) Warm
  35. 35.🤖 if (sound > 70) { red LED ON } else { green LED ON }
    The sound sensor reads 82. What happens?
    (a) red LED ON (b) green LED ON
  36. 36.🤖 if (temperature > 31) { show “Hot” } else if (temperature > 19) { show “Warm” } else { show “Cool” }
    The temperature is 20 °C. What is shown?
    (a) Cool (b) Warm (c) Hot
  37. 37.🤖 if (distance < 30) { buzzer beeps } else { buzzer is silent }
    The distance sensor reads 27 cm. What happens?
    (a) buzzer is silent (b) buzzer beeps
  38. 38.🤖 if (light < 200 AND motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 130 and motion is detected (true). What happens?
    (a) porch lamp OFF (b) porch lamp ON
  39. 39.🤖 if (light < 500) { lamp ON } else { lamp OFF }
    The light sensor reads 538. What happens?
    (a) lamp ON (b) lamp OFF
  40. 40.🤖 if (temperature > 25) { fan ON } else { fan OFF }
    The temperature sensor reads 26 °C. What happens?
    (a) fan ON (b) fan OFF

Answer key

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

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