← If / else with sensors lesson New set →

Electronics Worksheet: If Else with Sensors

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

Answer key

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

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