0
0
Arduinoprogramming~5 mins

Multiple sensor fusion in Arduino

Choose your learning style9 modes available
Introduction

Multiple sensor fusion helps combine data from different sensors to get better and more accurate information.

When you want to measure temperature and humidity together for better weather data.
When you use a light sensor and a motion sensor to control room lighting smartly.
When you combine accelerometer and gyroscope data to track device movement precisely.
When you want to improve robot navigation by using distance sensors and compass data.
Syntax
Arduino
// Read data from sensor1
int sensor1Value = analogRead(sensor1Pin);

// Read data from sensor2
int sensor2Value = analogRead(sensor2Pin);

// Combine or process sensor data
int fusedValue = (sensor1Value + sensor2Value) / 2;

Use analogRead() or digitalRead() to get sensor values.

Combine sensor data by averaging or using simple math to get fused results.

Examples
This example reads two sensors and averages their values.
Arduino
// Read temperature and humidity sensors
int tempValue = analogRead(tempPin);
int humidityValue = analogRead(humidityPin);

// Simple fusion by averaging
int averageValue = (tempValue + humidityValue) / 2;
This example uses motion sensor to decide if light sensor data should be used.
Arduino
// Read light and motion sensors
int lightValue = analogRead(lightPin);
int motionValue = digitalRead(motionPin);

// Use motion sensor to decide if light sensor data matters
int fusedValue = motionValue == HIGH ? lightValue : 0;
Sample Program

This program reads two sensors connected to analog pins A0 and A1, averages their values, and prints all readings to the serial monitor every second.

Arduino
#define tempPin A0
#define humidityPin A1

void setup() {
  Serial.begin(9600);
}

void loop() {
  int tempValue = analogRead(tempPin);
  int humidityValue = analogRead(humidityPin);

  int fusedValue = (tempValue + humidityValue) / 2;

  Serial.print("Temperature sensor: ");
  Serial.println(tempValue);
  Serial.print("Humidity sensor: ");
  Serial.println(humidityValue);
  Serial.print("Fused value (average): ");
  Serial.println(fusedValue);

  delay(1000);
}
OutputSuccess
Important Notes

Sensor values depend on your hardware and environment, so numbers will vary.

Fusion can be more complex, but averaging is a simple start.

Always check sensor datasheets for correct reading methods.

Summary

Multiple sensor fusion combines data from different sensors to improve accuracy.

Use simple math like averaging to fuse sensor values.

Arduino reads sensors using analogRead() or digitalRead().