← If / else with sensors lesson New set →

Electronics Worksheet: If Else with Sensors

Electronics lesson 24: If / else with sensors · Set 376 · 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 > 34) { show “Hot” } else if (temperature > 24) { show “Warm” } else { show “Cool” }
    The temperature is 18 °C. What is shown?
    (a) Warm (b) Hot (c) Cool
  2. 2.🤖 if (temperature > 28) { fan ON } else { fan OFF }
    The temperature sensor reads 29 °C. What happens?
    (a) fan OFF (b) fan ON
  3. 3.🤖 In “if (temp > 30)”, what runs when temp is exactly 30? (a) both parts (b) the if part (c) neither part (d) the else part
  4. 4.🤖 if (sound > 80) { red LED ON } else { green LED ON }
    The sound sensor reads 72. What happens?
    (a) red LED ON (b) green LED ON
  5. 5.🤖 if (light < 400 OR motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 270 and motion is detected (true). What happens?
    (a) porch lamp OFF (b) porch lamp ON
  6. 6.🤖 if (light < 300) { lamp ON } else { lamp OFF }
    The light sensor reads 215. What happens?
    (a) lamp OFF (b) lamp ON
  7. 7.🤖 if (distance < 30) { buzzer beeps } else { buzzer is silent }
    The distance sensor reads 27 cm. What happens?
    (a) buzzer is silent (b) buzzer beeps
  8. 8.🤖 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
  9. 9.🤖 “if (A AND B)” is true when … (a) both A and B are true (b) only B is true (c) only A is true (d) both are false
  10. 10.🤖 if (temperature > 34) { show “Hot” } else if (temperature > 25) { show “Warm” } else { show “Cool” }
    The temperature is 43 °C. What is shown?
    (a) Hot (b) Cool (c) Warm
  11. 11.🤖 if (light < 200 AND motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 340 and motion is not detected (false). What happens?
    (a) porch lamp OFF (b) porch lamp ON
  12. 12.🤖 if (temperature > 28) { fan ON } else { fan OFF }
    The temperature sensor reads 34 °C. What happens?
    (a) fan ON (b) fan OFF
  13. 13.🤖 if (light < 200 AND motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 590 and motion is detected (true). What happens?
    (a) porch lamp ON (b) porch lamp OFF
  14. 14.🤖 if (moisture < 40) { pump ON } else { pump OFF }
    The soil moisture sensor reads 41 %. What happens?
    (a) pump ON (b) pump OFF
  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 (temperature > 32) { fan ON } else { fan OFF }
    The temperature sensor reads 31 °C. What happens?
    (a) fan ON (b) fan OFF
  17. 17.🤖 if (sound > 60) { red LED ON } else { green LED ON }
    The sound sensor reads 61. What happens?
    (a) red LED ON (b) green LED ON
  18. 18.🤖 if (light < 300) { lamp ON } else { lamp OFF }
    The light sensor reads 367. What happens?
    (a) lamp ON (b) lamp OFF
  19. 19.🤖 if (sound > 70) { red LED ON } else { green LED ON }
    The sound sensor reads 58. What happens?
    (a) green LED ON (b) red LED ON
  20. 20.🤖 if (sound > 70) { red LED ON } else { green LED ON }
    The sound sensor reads 85. What happens?
    (a) green LED ON (b) red LED ON
  21. 21.🤖 if (light < 400 OR motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 560 and motion is not detected (false). What happens?
    (a) porch lamp OFF (b) porch lamp ON
  22. 22.🤖 if (light < 300 OR 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
  23. 23.🤖 if (temperature > 31) { show “Hot” } else if (temperature > 19) { show “Warm” } else { show “Cool” }
    The temperature is 18 °C. What is shown?
    (a) Hot (b) Cool (c) Warm
  24. 24.🤖 if (moisture < 40) { pump ON } else { pump OFF }
    The soil moisture sensor reads 29 %. What happens?
    (a) pump ON (b) pump OFF
  25. 25.🤖 if (temperature > 36) { show “Hot” } else if (temperature > 20) { show “Warm” } else { show “Cool” }
    The temperature is 23 °C. What is shown?
    (a) Warm (b) Hot (c) Cool
  26. 26.🤖 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
  27. 27.🤖 if (light < 400) { lamp ON } else { lamp OFF }
    The light sensor reads 501. What happens?
    (a) lamp OFF (b) lamp ON
  28. 28.🤖 if (light < 200 AND motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 650 and motion is not detected (false). What happens?
    (a) porch lamp OFF (b) porch lamp ON
  29. 29.🤖 if (moisture < 30) { pump ON } else { pump OFF }
    The soil moisture sensor reads 42 %. What happens?
    (a) pump OFF (b) pump ON
  30. 30.🤖 if (temperature > 33) { show “Hot” } else if (temperature > 25) { show “Warm” } else { show “Cool” }
    The temperature is 21 °C. What is shown?
    (a) Warm (b) Cool (c) Hot
  31. 31.🤖 if (moisture < 30) { pump ON } else { pump OFF }
    The soil moisture sensor reads 13 %. What happens?
    (a) pump ON (b) pump OFF
  32. 32.🤖 if (light < 300 AND motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 560 and motion is not detected (false). What happens?
    (a) porch lamp ON (b) porch lamp OFF
  33. 33.🤖 if (light < 200 AND motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 90 and motion is not detected (false). What happens?
    (a) porch lamp OFF (b) porch lamp ON
  34. 34.🤖 if (light < 400 OR motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 160 and motion is not detected (false). What happens?
    (a) porch lamp OFF (b) porch lamp ON
  35. 35.🤖 if (temperature > 30) { fan ON } else { fan OFF }
    The temperature sensor reads 31 °C. What happens?
    (a) fan OFF (b) fan ON
  36. 36.🤖 if (light < 300 AND motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 510 and motion is detected (true). What happens?
    (a) porch lamp OFF (b) porch lamp ON
  37. 37.🤖 if (distance < 10) { buzzer beeps } else { buzzer is silent }
    The distance sensor reads 13 cm. What happens?
    (a) buzzer beeps (b) buzzer is silent
  38. 38.🤖 if (light < 400 AND motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 140 and motion is detected (true). What happens?
    (a) porch lamp ON (b) porch lamp OFF
  39. 39.🤖 if (light < 400 AND motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 450 and motion is not detected (false). What happens?
    (a) porch lamp OFF (b) porch lamp ON
  40. 40.🤖 if (moisture < 30) { pump ON } else { pump OFF }
    The soil moisture sensor reads 14 %. What happens?
    (a) pump ON (b) pump OFF

Answer key

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

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