← If / else with sensors lesson New set →

Electronics Worksheet: If Else with Sensors

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

Answer key

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

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