📖 Scenario: You are building a simple Arduino project that reads data from two sensors: a temperature sensor and a light sensor. You want to combine their readings to decide if the environment is comfortable.
🎯 Goal: Create an Arduino program that reads values from a temperature sensor and a light sensor, then fuses these readings to determine if the environment is comfortable based on given thresholds.
📋 What You'll Learn
Create variables to store temperature and light sensor readings.
Set threshold values for temperature and light to define comfort.
Use an if-else statement to fuse sensor data and decide comfort.
Print the comfort status to the Serial Monitor.
💡 Why This Matters
🌍 Real World
Combining multiple sensor readings helps devices make better decisions, like smart thermostats or lighting systems.
💼 Career
Understanding sensor fusion is useful for embedded systems engineers and IoT developers working with hardware.
Progress0 / 4 steps
1
Setup sensor variables
Create two integer variables called temperature and light and set them to 25 and 300 respectively.
Arduino
Hint
Use int to declare integer variables and assign the exact values.
2
Set comfort thresholds
Create two integer variables called tempThreshold and lightThreshold and set them to 22 and 250 respectively.
Arduino
Hint
Thresholds help decide if the environment is comfortable.
3
Fuse sensor data with if-else
Write an if statement that checks if temperature is greater than tempThreshold and light is greater than lightThreshold. Inside the if, create a string variable status and set it to "Comfortable". Otherwise, set status to "Not Comfortable".
Arduino
Hint
Use && to combine conditions and assign status inside the if and else blocks.
4
Print the comfort status
Add Serial.begin(9600); in setup() and write Serial.println(status); inside loop() to print the comfort status.
Arduino
Hint
Use Serial.begin(9600); in setup() and Serial.println(status); in loop(). Add delay(1000); to slow printing.
Practice
(1/5)
1. What is the main purpose of multiple sensor fusion in Arduino projects?
easy
A. To make sensors work independently without Arduino
B. To combine data from different sensors for better accuracy
C. To reduce the power consumption of sensors
D. To increase the number of sensors connected to Arduino
Solution
Step 1: Understand sensor fusion concept
Multiple sensor fusion means combining data from different sensors to get more reliable results.
Step 2: Identify the main goal
The goal is to improve accuracy by using data from multiple sources.
Final Answer:
To combine data from different sensors for better accuracy -> Option B
Quick Check:
Sensor fusion = combine data for accuracy [OK]
Hint: Sensor fusion means combining sensor data for accuracy [OK]
Common Mistakes:
Thinking sensor fusion just adds more sensors
Confusing power saving with fusion
Assuming sensors work independently
2. Which Arduino function is commonly used to read analog sensor values for fusion?
easy
A. analogRead()
B. digitalRead()
C. sensorRead()
D. readAnalog()
Solution
Step 1: Recall Arduino sensor reading functions
Arduino uses digitalRead() for digital sensors and analogRead() for analog sensors.
Step 2: Identify correct function for analog sensors
analogRead() reads analog sensor values needed for fusion.
Final Answer:
analogRead() -> Option A
Quick Check:
Analog sensor read = analogRead() [OK]
Hint: Use analogRead() for analog sensors in Arduino [OK]
Common Mistakes:
Using digitalRead() for analog sensors
Choosing non-existent functions like sensorRead()
Confusing function names
3. What will be the output of this Arduino code snippet for sensor fusion?
int sensor1 = 400;
int sensor2 = 600;
int fusedValue = (sensor1 + sensor2) / 2;
Serial.println(fusedValue);
medium
A. 500
B. 400
C. 1000
D. 600
Solution
Step 1: Calculate sum of sensor values
sensor1 + sensor2 = 400 + 600 = 1000
Step 2: Calculate average for fusion
Average = 1000 / 2 = 500
Final Answer:
500 -> Option A
Quick Check:
(400+600)/2 = 500 [OK]
Hint: Average sensor values by adding and dividing by count [OK]
Common Mistakes:
Adding but forgetting to divide
Dividing by wrong number
Printing wrong variable
4. Identify the error in this Arduino code for fusing two sensor readings:
int sensor1 = analogRead(A0);
int sensor2 = analogRead(A1);
int fusedValue = sensor1 + sensor2 / 2;
Serial.println(fusedValue);
medium
A. analogRead() cannot be used on pins A0 and A1
B. Serial.println() cannot print integers
C. fusedValue should be a float, not int
D. The division operator has higher precedence, so sensor2 is divided by 2 before adding sensor1
Solution
Step 1: Analyze operator precedence in expression
Division (/) has higher precedence than addition (+), so sensor2 / 2 happens first.
Step 2: Understand the effect on fusedValue
Expression equals sensor1 + (sensor2 / 2), not (sensor1 + sensor2) / 2 as intended.
Final Answer:
The division operator has higher precedence, so sensor2 is divided by 2 before adding sensor1 -> Option D
Hint: Use parentheses to control math order in fusion calculations [OK]
Common Mistakes:
Ignoring operator precedence
Thinking analogRead() is invalid on A0/A1
Believing Serial.println() can't print ints
5. You have three sensors giving values: 300, 450, and 500. To fuse these readings and reduce noise, which Arduino code correctly calculates the average value?
hard
A. int fused = (300 + 450 + 500) * 3;
B. int fused = 300 + 450 + 500 / 3;
C. int fused = (300 + 450 + 500) / 3;
D. int fused = (300 + 450 + 500) / 2;
Solution
Step 1: Understand correct averaging formula
Average = sum of values divided by number of values, so (300+450+500)/3.
Step 2: Check each option's calculation
int fused = (300 + 450 + 500) / 3; correctly sums all and divides by 3. int fused = 300 + 450 + 500 / 3; divides only 500 by 3, wrong order. int fused = (300 + 450 + 500) * 3; multiplies sum by 3, wrong. int fused = (300 + 450 + 500) / 2; divides by 2, wrong count.
Final Answer:
int fused = (300 + 450 + 500) / 3; -> Option C
Quick Check:
Average = sum/3 = correct fusion [OK]
Hint: Sum all sensor values, then divide by count with parentheses [OK]
Common Mistakes:
Missing parentheses causing wrong math order
Dividing only last value
Multiplying instead of dividing
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.