← If / else with sensors lesson New set →

Electronics Worksheet: If Else with Sensors

Electronics lesson 24: If / else with sensors · Set 501 · 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 > 31) { show “Hot” } else if (temperature > 20) { show “Warm” } else { show “Cool” }
    The temperature is 11 °C. What is shown?
    (a) Warm (b) Cool (c) Hot
  2. 2.🤖 “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
  3. 3.🤖 if (light < 300 AND motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 610 and motion is detected (true). What happens?
    (a) porch lamp OFF (b) porch lamp ON
  4. 4.🤖 if (light < 200 OR motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 470 and motion is not detected (false). What happens?
    (a) porch lamp ON (b) porch lamp OFF
  5. 5.🤖 if (temperature > 31) { show “Hot” } else if (temperature > 18) { show “Warm” } else { show “Cool” }
    The temperature is 14 °C. What is shown?
    (a) Cool (b) Hot (c) Warm
  6. 6.🤖 if (light < 500) { lamp ON } else { lamp OFF }
    The light sensor reads 569. What happens?
    (a) lamp ON (b) lamp OFF
  7. 7.🤖 if (distance < 30) { buzzer beeps } else { buzzer is silent }
    The distance sensor reads 21 cm. What happens?
    (a) buzzer beeps (b) buzzer is silent
  8. 8.🤖 if (distance < 10) { buzzer beeps } else { buzzer is silent }
    The distance sensor reads 19 cm. What happens?
    (a) buzzer beeps (b) buzzer is silent
  9. 9.🤖 if (temperature > 35) { show “Hot” } else if (temperature > 26) { show “Warm” } else { show “Cool” }
    The temperature is 34 °C. What is shown?
    (a) Cool (b) Hot (c) Warm
  10. 10.🤖 In “if (temp > 30)”, what runs when temp is exactly 30? (a) neither part (b) both parts (c) the if part (d) the else part
  11. 11.🤖 if (temperature > 31) { show “Hot” } else if (temperature > 20) { show “Warm” } else { show “Cool” }
    The temperature is 19 °C. What is shown?
    (a) Cool (b) Warm (c) Hot
  12. 12.🤖 if (temperature > 35) { show “Hot” } else if (temperature > 20) { show “Warm” } else { show “Cool” }
    The temperature is 18 °C. What is shown?
    (a) Cool (b) Warm (c) Hot
  13. 13.🤖 if (temperature > 28) { fan ON } else { fan OFF }
    The temperature sensor reads 21 °C. What happens?
    (a) fan ON (b) fan OFF
  14. 14.🤖 if (sound > 80) { red LED ON } else { green LED ON }
    The sound sensor reads 73. What happens?
    (a) red LED ON (b) green LED ON
  15. 15.🤖 if (sound > 70) { red LED ON } else { green LED ON }
    The sound sensor reads 57. What happens?
    (a) red LED ON (b) green LED ON
  16. 16.🤖 if (light < 200) { lamp ON } else { lamp OFF }
    The light sensor reads 221. What happens?
    (a) lamp OFF (b) lamp ON
  17. 17.🤖 if (light < 300 OR motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 140 and motion is not detected (false). What happens?
    (a) porch lamp ON (b) porch lamp OFF
  18. 18.🤖 if (light < 500) { lamp ON } else { lamp OFF }
    The light sensor reads 444. What happens?
    (a) lamp ON (b) lamp OFF
  19. 19.🤖 if (distance < 10) { buzzer beeps } else { buzzer is silent }
    The distance sensor reads 18 cm. What happens?
    (a) buzzer beeps (b) buzzer is silent
  20. 20.🤖 if (temperature > 38) { show “Hot” } else if (temperature > 18) { show “Warm” } else { show “Cool” }
    The temperature is 15 °C. What is shown?
    (a) Cool (b) Hot (c) Warm
  21. 21.🤖 if (temperature > 30) { show “Hot” } else if (temperature > 18) { show “Warm” } else { show “Cool” }
    The temperature is 22 °C. What is shown?
    (a) Warm (b) Hot (c) Cool
  22. 22.🤖 if (sound > 70) { red LED ON } else { green LED ON }
    The sound sensor reads 68. What happens?
    (a) green LED ON (b) red LED ON
  23. 23.🤖 if (light < 300) { lamp ON } else { lamp OFF }
    The light sensor reads 446. What happens?
    (a) lamp ON (b) lamp OFF
  24. 24.🤖 if (temperature > 30) { fan ON } else { fan OFF }
    The temperature sensor reads 32 °C. What happens?
    (a) fan OFF (b) fan ON
  25. 25.🤖 if (light < 200 OR motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 250 and motion is not detected (false). What happens?
    (a) porch lamp ON (b) porch lamp OFF
  26. 26.🤖 if (light < 300 AND motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 360 and motion is not detected (false). What happens?
    (a) porch lamp OFF (b) porch lamp ON
  27. 27.🤖 if (temperature > 31) { show “Hot” } else if (temperature > 18) { show “Warm” } else { show “Cool” }
    The temperature is 32 °C. What is shown?
    (a) Cool (b) Hot (c) Warm
  28. 28.🤖 if (temperature > 36) { show “Hot” } else if (temperature > 25) { show “Warm” } else { show “Cool” }
    The temperature is 16 °C. What is shown?
    (a) Hot (b) Warm (c) Cool
  29. 29.🤖 if (distance < 15) { buzzer beeps } else { buzzer is silent }
    The distance sensor reads 13 cm. What happens?
    (a) buzzer beeps (b) buzzer is silent
  30. 30.🤖 if (temperature > 32) { fan ON } else { fan OFF }
    The temperature sensor reads 32 °C. What happens?
    (a) fan ON (b) fan OFF
  31. 31.🤖 if (temperature > 32) { show “Hot” } else if (temperature > 20) { show “Warm” } else { show “Cool” }
    The temperature is 43 °C. What is shown?
    (a) Hot (b) Cool (c) Warm
  32. 32.🤖 if (light < 400 OR motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 90 and motion is detected (true). What happens?
    (a) porch lamp OFF (b) porch lamp ON
  33. 33.🤖 if (sound > 70) { red LED ON } else { green LED ON }
    The sound sensor reads 54. What happens?
    (a) green LED ON (b) red LED ON
  34. 34.🤖 if (temperature > 25) { fan ON } else { fan OFF }
    The temperature sensor reads 31 °C. What happens?
    (a) fan ON (b) fan OFF
  35. 35.🤖 if (light < 300 OR motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 640 and motion is detected (true). What happens?
    (a) porch lamp ON (b) porch lamp OFF
  36. 36.🤖 if (light < 200) { lamp ON } else { lamp OFF }
    The light sensor reads 292. What happens?
    (a) lamp OFF (b) lamp ON
  37. 37.🤖 if (light < 500) { lamp ON } else { lamp OFF }
    The light sensor reads 576. What happens?
    (a) lamp ON (b) lamp OFF
  38. 38.🤖 if (temperature > 35) { 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
  39. 39.🤖 if (distance < 30) { buzzer beeps } else { buzzer is silent }
    The distance sensor reads 25 cm. What happens?
    (a) buzzer is silent (b) buzzer beeps
  40. 40.🤖 if (temperature > 36) { show “Hot” } else if (temperature > 21) { show “Warm” } else { show “Cool” }
    The temperature is 40 °C. What is shown?
    (a) Warm (b) Cool (c) Hot

Answer key

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

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