← If / else with sensors lesson New set →

Electronics Worksheet: If Else with Sensors

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

Answer key

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

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