// Sensor test bench on the Arduino Uno (the board you already own).
// Use it to check every module ALONE before it goes into the robot or drone:
// scans I2C and names what it finds, and prints the analog inputs once a second.
// Wiring: module SDA -> A4, SCL -> A5, VCC -> 5V (or 3.3V for 3.3 V-only boards), GND -> GND.
// Analog sensors (LM35, MQ-3, MQ-4, water, LDR, phototransistor) -> A0..A3.
// Serial Monitor at 115200. Type 'b' to beep a buzzer on pin 8, 'r' to toggle a relay on pin 7.
#include <Wire.h>
struct Known {
uint8_t addr;
const char *name;
};
static const Known KNOWN[] = {
{0x20, "MCP23017"}, {0x29, "VL53L1X"}, {0x44, "SHT31"}, {0x48, "ADS1115 (ADDR=GND)"},
{0x49, "ADS1115 (ADDR=VDD)"}, {0x57, "MAX30102"}, {0x5A, "MLX90614"}, {0x62, "SCD40"},
{0x68, "MPU6050"}, {0x76, "BME680 (SDO=GND)"}, {0x77, "BME680 (SDO=VDD)"},
};
static void scan() {
Serial.println(F("--- I2C scan ---"));
int found = 0;
for (uint8_t a = 1; a < 127; a++) {
Wire.beginTransmission(a);
if (Wire.endTransmission() != 0) continue;
found++;
const char *name = "unknown";
for (const Known &k : KNOWN)
if (k.addr == a) name = k.name;
Serial.print(F("0x"));
if (a < 16) Serial.print('0');
Serial.print(a, HEX);
Serial.print(F(" "));
Serial.println(name);
}
if (!found) Serial.println(F("nothing found: check SDA/SCL, power and pull-ups"));
}
void setup() {
Serial.begin(115200);
Wire.begin();
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
scan();
}
void loop() {
static uint32_t at = 0;
if (millis() - at > 1000) {
at = millis();
for (int ch = 0; ch < 4; ch++) {
float v = analogRead(A0 + ch) * 5.0 / 1023.0;
Serial.print(F("A"));
Serial.print(ch);
Serial.print(F("="));
Serial.print(v, 2);
Serial.print(F("V "));
}
Serial.print(F("| LM35 on A0 = "));
Serial.print(analogRead(A0) * 500.0 / 1023.0, 1);
Serial.println(F(" C"));
}
if (Serial.available()) {
char c = Serial.read();
if (c == 'b') tone(8, 2000, 200);
if (c == 'r') digitalWrite(7, !digitalRead(7));
if (c == 's') scan();
}
}