Electronics Worksheet: If Else with Sensors
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.🤖 if (temperature > 36) { show “Hot” } else if (temperature > 20) { show “Warm” } else { show “Cool” }
The temperature is 20 °C. What is shown? (a) Hot (b) Cool (c) Warm -
2.🤖 if (temperature > 35) { 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 -
3.🤖 if (temperature > 35) { show “Hot” } else if (temperature > 19) { show “Warm” } else { show “Cool” }
The temperature is 14 °C. What is shown? (a) Cool (b) Hot (c) Warm -
4.🤖 if (distance < 10) { buzzer beeps } else { buzzer is silent }
The distance sensor reads 11 cm. What happens? (a) buzzer is silent (b) buzzer beeps - 5.🤖 In “if (temp > 30)”, what runs when temp is exactly 30? (a) the if part (b) both parts (c) neither part (d) the else part
- 6.🤖 “if (A AND B)” is true when … (a) only A is true (b) both are false (c) only B is true (d) both A and B are true
-
7.🤖 if (temperature > 35) { show “Hot” } else if (temperature > 20) { show “Warm” } else { show “Cool” }
The temperature is 29 °C. What is shown? (a) Cool (b) Hot (c) Warm -
8.🤖 if (temperature > 31) { show “Hot” } else if (temperature > 26) { show “Warm” } else { show “Cool” }
The temperature is 22 °C. What is shown? (a) Cool (b) Hot (c) Warm -
9.🤖 if (temperature > 36) { show “Hot” } else if (temperature > 26) { show “Warm” } else { show “Cool” }
The temperature is 11 °C. What is shown? (a) Warm (b) Hot (c) Cool -
10.🤖 if (light < 300 OR motion) { porch lamp ON } else { porch lamp OFF }
The light reading is 310 and motion is not detected (false). What happens? (a) porch lamp ON (b) porch lamp OFF -
11.🤖 if (moisture < 30) { pump ON } else { pump OFF }
The soil moisture sensor reads 14 %. What happens? (a) pump ON (b) pump OFF -
12.🤖 if (sound > 60) { red LED ON } else { green LED ON }
The sound sensor reads 66. What happens? (a) green LED ON (b) red LED ON -
13.🤖 if (temperature > 37) { show “Hot” } else if (temperature > 23) { show “Warm” } else { show “Cool” }
The temperature is 44 °C. What is shown? (a) Warm (b) Cool (c) Hot -
14.🤖 if (distance < 20) { buzzer beeps } else { buzzer is silent }
The distance sensor reads 24 cm. What happens? (a) buzzer beeps (b) buzzer is silent -
15.🤖 if (light < 400) { lamp ON } else { lamp OFF }
The light sensor reads 373. What happens? (a) lamp ON (b) lamp OFF -
16.🤖 if (sound > 70) { red LED ON } else { green LED ON }
The sound sensor reads 63. What happens? (a) green LED ON (b) red LED ON -
17.🤖 if (moisture < 30) { pump ON } else { pump OFF }
The soil moisture sensor reads 11 %. What happens? (a) pump ON (b) pump OFF -
18.🤖 if (temperature > 32) { show “Hot” } else if (temperature > 20) { show “Warm” } else { show “Cool” }
The temperature is 29 °C. What is shown? (a) Cool (b) Warm (c) Hot -
19.🤖 if (temperature > 36) { show “Hot” } else if (temperature > 20) { show “Warm” } else { show “Cool” }
The temperature is 37 °C. What is shown? (a) Hot (b) Warm (c) Cool -
20.🤖 if (light < 400 AND motion) { porch lamp ON } else { porch lamp OFF }
The light reading is 260 and motion is not detected (false). What happens? (a) porch lamp ON (b) porch lamp OFF -
21.🤖 if (moisture < 40) { pump ON } else { pump OFF }
The soil moisture sensor reads 44 %. What happens? (a) pump OFF (b) pump ON -
22.🤖 if (temperature > 38) { show “Hot” } else if (temperature > 22) { show “Warm” } else { show “Cool” }
The temperature is 33 °C. What is shown? (a) Cool (b) Hot (c) Warm -
23.🤖 if (temperature > 32) { show “Hot” } else if (temperature > 24) { show “Warm” } else { show “Cool” }
The temperature is 20 °C. What is shown? (a) Hot (b) Warm (c) Cool -
24.🤖 if (sound > 60) { red LED ON } else { green LED ON }
The sound sensor reads 43. What happens? (a) red LED ON (b) green LED ON -
25.🤖 if (light < 200 OR motion) { porch lamp ON } else { porch lamp OFF }
The light reading is 390 and motion is detected (true). What happens? (a) porch lamp OFF (b) porch lamp ON -
26.🤖 if (light < 300 OR motion) { porch lamp ON } else { porch lamp OFF }
The light reading is 50 and motion is detected (true). What happens? (a) porch lamp ON (b) porch lamp OFF -
27.🤖 if (light < 500) { lamp ON } else { lamp OFF }
The light sensor reads 456. What happens? (a) lamp ON (b) lamp OFF -
28.🤖 if (sound > 80) { red LED ON } else { green LED ON }
The sound sensor reads 99. What happens? (a) green LED ON (b) red LED ON -
29.🤖 if (light < 200 AND motion) { porch lamp ON } else { porch lamp OFF }
The light reading is 580 and motion is detected (true). What happens? (a) porch lamp OFF (b) porch lamp ON -
30.🤖 if (temperature > 32) { fan ON } else { fan OFF }
The temperature sensor reads 36 °C. What happens? (a) fan ON (b) fan OFF -
31.🤖 if (temperature > 38) { show “Hot” } else if (temperature > 20) { show “Warm” } else { show “Cool” }
The temperature is 10 °C. What is shown? (a) Cool (b) Warm (c) Hot -
32.🤖 if (light < 300) { lamp ON } else { lamp OFF }
The light sensor reads 282. What happens? (a) lamp ON (b) lamp OFF -
33.🤖 if (moisture < 40) { pump ON } else { pump OFF }
The soil moisture sensor reads 38 %. What happens? (a) pump OFF (b) pump ON -
34.🤖 if (light < 400 OR 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 -
35.🤖 if (sound > 70) { red LED ON } else { green LED ON }
The sound sensor reads 90. What happens? (a) green LED ON (b) red LED ON -
36.🤖 if (temperature > 25) { fan ON } else { fan OFF }
The temperature sensor reads 23 °C. What happens? (a) fan OFF (b) fan ON -
37.🤖 if (temperature > 30) { show “Hot” } else if (temperature > 20) { show “Warm” } else { show “Cool” }
The temperature is 14 °C. What is shown? (a) Warm (b) Hot (c) Cool -
38.🤖 if (distance < 20) { buzzer beeps } else { buzzer is silent }
The distance sensor reads 18 cm. What happens? (a) buzzer is silent (b) buzzer beeps -
39.🤖 if (light < 400 OR motion) { porch lamp ON } else { porch lamp OFF }
The light reading is 370 and motion is not detected (false). What happens? (a) porch lamp ON (b) porch lamp OFF -
40.🤖 if (light < 200 OR motion) { porch lamp ON } else { porch lamp OFF }
The light reading is 80 and motion is detected (true). What happens? (a) porch lamp ON (b) porch lamp OFF
Answer key
- Cool
- Cool
- Cool
- buzzer is silent
- the else part
- both A and B are true
- Warm
- Cool
- Cool
- porch lamp OFF
- pump ON
- red LED ON
- Hot
- buzzer is silent
- lamp ON
- green LED ON
- pump ON
- Warm
- Hot
- porch lamp OFF
- pump OFF
- Warm
- Cool
- green LED ON
- porch lamp ON
- porch lamp ON
- lamp ON
- red LED ON
- porch lamp OFF
- fan ON
- Cool
- lamp ON
- pump ON
- porch lamp ON
- red LED ON
- fan OFF
- Cool
- buzzer beeps
- porch lamp ON
- porch lamp ON
Free electronics lessons, practice and worksheets at talentjr.in/electronics-for-kids