Arduino Multi-Sensor Simulator
LAB08: Hands-on Sensor Programming Without Hardware
Overview
This interactive Wokwi simulation lets you experiment with multiple sensors connected to an Arduino, exactly as covered in LAB08. No hardware required!
- Click “Play” to start the simulation
- Interact with sensors (click potentiometer, adjust temperature slider)
- View sensor readings in the Serial Monitor
- Modify the code to experiment with different configurations
Multi-Sensor Data Logger
This simulation includes:
- Potentiometer (analog input) - simulates light/soil moisture sensors
- DHT22 - temperature and humidity sensor
- PIR Motion Sensor - digital motion detection
- LED indicators - visual feedback for thresholds
The embedded simulator opens a blank Arduino Uno project. Copy the code below to create the multi-sensor setup.
Starter Code
Copy this code into the Wokwi editor above:
// LAB08: Multi-Sensor Data Logger
// Edge Analytics Lab Book
// Pin definitions
const int POT_PIN = A0; // Potentiometer (analog)
const int PIR_PIN = 2; // PIR motion sensor (digital)
const int LED_GREEN = 8; // Status LED
const int LED_RED = 9; // Alert LED
// DHT22 would need library - using simulated values here
float temperature = 22.5;
float humidity = 45.0;
// Thresholds
const int LIGHT_THRESHOLD = 512;
const float TEMP_HIGH = 30.0;
void setup() {
Serial.begin(115200);
pinMode(POT_PIN, INPUT);
pinMode(PIR_PIN, INPUT);
pinMode(LED_GREEN, OUTPUT);
pinMode(LED_RED, OUTPUT);
Serial.println("=== Multi-Sensor Data Logger ===");
Serial.println("Timestamp,Light,Temperature,Humidity,Motion");
}
void loop() {
// Read sensors
int lightValue = analogRead(POT_PIN);
int motionDetected = digitalRead(PIR_PIN);
// Simulate temperature drift
temperature += random(-10, 11) / 100.0;
humidity += random(-5, 6) / 10.0;
humidity = constrain(humidity, 20, 80);
// Print CSV format for data analysis
unsigned long timestamp = millis();
Serial.print(timestamp);
Serial.print(",");
Serial.print(lightValue);
Serial.print(",");
Serial.print(temperature, 1);
Serial.print(",");
Serial.print(humidity, 1);
Serial.print(",");
Serial.println(motionDetected);
// LED indicators
if (lightValue > LIGHT_THRESHOLD) {
digitalWrite(LED_GREEN, HIGH);
} else {
digitalWrite(LED_GREEN, LOW);
}
if (temperature > TEMP_HIGH || motionDetected) {
digitalWrite(LED_RED, HIGH);
} else {
digitalWrite(LED_RED, LOW);
}
delay(1000); // Sample every second
}Wiring Diagram
Add these components in Wokwi:
| Component | Arduino Pin | Notes |
|---|---|---|
| Potentiometer | A0 | Simulates analog sensor |
| PIR Sensor | D2 | Motion detection |
| Green LED | D8 | With 220Ω resistor |
| Red LED | D9 | With 220Ω resistor |
Exercises
Exercise 1: Sensor Calibration
Modify the LIGHT_THRESHOLD value and observe when the green LED turns on/off. What range of potentiometer values correspond to “low light” vs “bright”?
Exercise 2: Sampling Rate
Change delay(1000) to delay(100). What happens to:
- Serial Monitor output rate?
- Data file size (if you were logging)?
- Power consumption (in a real device)?
Exercise 3: Data Windowing
Add rolling average calculation:
// Add at top of file
const int WINDOW_SIZE = 5;
int lightBuffer[WINDOW_SIZE];
int bufferIndex = 0;
// In loop(), before printing
lightBuffer[bufferIndex] = lightValue;
bufferIndex = (bufferIndex + 1) % WINDOW_SIZE;
int smoothedLight = 0;
for (int i = 0; i < WINDOW_SIZE; i++) {
smoothedLight += lightBuffer[i];
}
smoothedLight /= WINDOW_SIZE;How does windowing affect noise in the readings?
Next Steps
After completing this simulation:
- Level 3: Build the physical circuit with real sensors
- LAB12: Stream this data to a Raspberry Pi for processing
- LAB13: Store readings in a database
Wokwi is a free online simulator for Arduino, ESP32, and other embedded platforms. It runs entirely in your browser with no installation required.