← If / else with sensors lesson New set →

Electronics Worksheet: If Else with Sensors

Electronics lesson 24: If / else with sensors · Set 789 · 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 > 28) { fan ON } else { fan OFF }
    The temperature sensor reads 29 °C. What happens?
    (a) fan OFF (b) fan ON
  2. 2.🤖 if (light < 300) { lamp ON } else { lamp OFF }
    The light sensor reads 295. What happens?
    (a) lamp ON (b) lamp OFF
  3. 3.🤖 if (temperature > 30) { show “Hot” } else if (temperature > 20) { show “Warm” } else { show “Cool” }
    The temperature is 32 °C. What is shown?
    (a) Hot (b) Warm (c) Cool
  4. 4.🤖 if (light < 500) { lamp ON } else { lamp OFF }
    The light sensor reads 570. What happens?
    (a) lamp OFF (b) lamp ON
  5. 5.🤖 if (light < 500) { lamp ON } else { lamp OFF }
    The light sensor reads 650. What happens?
    (a) lamp OFF (b) lamp ON
  6. 6.🤖 if (light < 300) { lamp ON } else { lamp OFF }
    The light sensor reads 179. What happens?
    (a) lamp OFF (b) lamp ON
  7. 7.🤖 if (temperature > 33) { show “Hot” } else if (temperature > 26) { show “Warm” } else { show “Cool” }
    The temperature is 16 °C. What is shown?
    (a) Hot (b) Warm (c) Cool
  8. 8.🤖 if (light < 500) { lamp ON } else { lamp OFF }
    The light sensor reads 401. What happens?
    (a) lamp OFF (b) lamp ON
  9. 9.🤖 “if (A AND B)” is true when … (a) both are false (b) only A is true (c) only B is true (d) both A and B are true
  10. 10.🤖 if (temperature > 31) { show “Hot” } else if (temperature > 22) { show “Warm” } else { show “Cool” }
    The temperature is 10 °C. What is shown?
    (a) Warm (b) Hot (c) Cool
  11. 11.🤖 if (distance < 10) { buzzer beeps } else { buzzer is silent }
    The distance sensor reads 2 cm. What happens?
    (a) buzzer beeps (b) buzzer is silent
  12. 12.🤖 if (moisture < 30) { pump ON } else { pump OFF }
    The soil moisture sensor reads 22 %. What happens?
    (a) pump ON (b) pump OFF
  13. 13.🤖 if (moisture < 30) { pump ON } else { pump OFF }
    The soil moisture sensor reads 41 %. What happens?
    (a) pump ON (b) pump OFF
  14. 14.🤖 if (sound > 60) { red LED ON } else { green LED ON }
    The sound sensor reads 71. What happens?
    (a) red LED ON (b) green LED ON
  15. 15.🤖 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
  16. 16.🤖 if (temperature > 34) { show “Hot” } else if (temperature > 23) { show “Warm” } else { show “Cool” }
    The temperature is 36 °C. What is shown?
    (a) Warm (b) Cool (c) Hot
  17. 17.🤖 if (moisture < 40) { pump ON } else { pump OFF }
    The soil moisture sensor reads 47 %. What happens?
    (a) pump ON (b) pump OFF
  18. 18.🤖 if (sound > 70) { red LED ON } else { green LED ON }
    The sound sensor reads 80. What happens?
    (a) red LED ON (b) green LED ON
  19. 19.🤖 if (temperature > 30) { show “Hot” } else if (temperature > 22) { show “Warm” } else { show “Cool” }
    The temperature is 28 °C. What is shown?
    (a) Warm (b) Hot (c) Cool
  20. 20.🤖 if (light < 400 OR motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 170 and motion is detected (true). What happens?
    (a) porch lamp ON (b) porch lamp OFF
  21. 21.🤖 if (light < 200 AND motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 220 and motion is detected (true). What happens?
    (a) porch lamp OFF (b) porch lamp ON
  22. 22.🤖 if (distance < 20) { buzzer beeps } else { buzzer is silent }
    The distance sensor reads 21 cm. What happens?
    (a) buzzer beeps (b) buzzer is silent
  23. 23.🤖 if (temperature > 31) { show “Hot” } else if (temperature > 26) { show “Warm” } else { show “Cool” }
    The temperature is 20 °C. What is shown?
    (a) Warm (b) Cool (c) Hot
  24. 24.🤖 if (temperature > 32) { show “Hot” } else if (temperature > 18) { show “Warm” } else { show “Cool” }
    The temperature is 37 °C. What is shown?
    (a) Warm (b) Cool (c) Hot
  25. 25.🤖 if (light < 400 AND 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
  26. 26.🤖 if (moisture < 30) { pump ON } else { pump OFF }
    The soil moisture sensor reads 15 %. What happens?
    (a) pump OFF (b) pump ON
  27. 27.🤖 if (light < 200 AND motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 650 and motion is detected (true). What happens?
    (a) porch lamp ON (b) porch lamp OFF
  28. 28.🤖 if (sound > 80) { red LED ON } else { green LED ON }
    The sound sensor reads 71. What happens?
    (a) red LED ON (b) green LED ON
  29. 29.🤖 if (temperature > 32) { fan ON } else { fan OFF }
    The temperature sensor reads 30 °C. What happens?
    (a) fan OFF (b) fan ON
  30. 30.🤖 if (light < 500) { lamp ON } else { lamp OFF }
    The light sensor reads 633. What happens?
    (a) lamp ON (b) lamp OFF
  31. 31.🤖 if (moisture < 50) { pump ON } else { pump OFF }
    The soil moisture sensor reads 70 %. What happens?
    (a) pump ON (b) pump OFF
  32. 32.🤖 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
  33. 33.🤖 if (light < 300 OR motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 640 and motion is not detected (false). What happens?
    (a) porch lamp OFF (b) porch lamp ON
  34. 34.🤖 if (temperature > 30) { show “Hot” } else if (temperature > 24) { show “Warm” } else { show “Cool” }
    The temperature is 19 °C. What is shown?
    (a) Warm (b) Cool (c) Hot
  35. 35.🤖 if (light < 500) { lamp ON } else { lamp OFF }
    The light sensor reads 362. What happens?
    (a) lamp OFF (b) lamp ON
  36. 36.🤖 if (distance < 20) { buzzer beeps } else { buzzer is silent }
    The distance sensor reads 13 cm. What happens?
    (a) buzzer beeps (b) buzzer is silent
  37. 37.🤖 if (light < 200 OR motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 570 and motion is detected (true). What happens?
    (a) porch lamp OFF (b) porch lamp ON
  38. 38.🤖 if (light < 200 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 OFF (b) porch lamp ON
  39. 39.🤖 if (temperature > 30) { show “Hot” } else if (temperature > 20) { show “Warm” } else { show “Cool” }
    The temperature is 40 °C. What is shown?
    (a) Warm (b) Hot (c) Cool
  40. 40.🤖 if (light < 200 OR motion) { porch lamp ON } else { porch lamp OFF }
    The light reading is 450 and motion is not detected (false). What happens?
    (a) porch lamp ON (b) porch lamp OFF

Answer key

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

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