Smart bridge monitor: Arduino project with wiring and code
Watch a model bridge for danger. A potentiometer on A0 stands in for the load sensor and an MPU6050 measures vibration. When all is well the green LED on pin 4 is on and the buzzer on pin 8 is silent. If the load reading passes 700, sound 1000 Hz. If the vibration passes 0.25 g, sound 2000 Hz. If both happen, sound 1500 Hz. In any alarm the red LED on pin 5 is on and the green one is off.
You will learn: Combining two sensors, finding the peak of a vibrating signal, thresholds, and choosing between several alarm tones with if and else if.
Project 51 of 62 in the project gallery.
Parts you need
| Part | How many | What it does in this project |
|---|---|---|
| Arduino Uno | 1 | Runs your sketch and powers the circuit. |
| Accelerometer and gyroscope (MPU6050) | 1 | The vibration sensor. It measures how hard the bridge is shaking, in g. |
| Potentiometer | 1 | The load sensor stand-in. Turning it up is like putting more weight on the bridge. |
| Piezo buzzer | 1 | The alarm. Its pitch tells which problem was found: 1000 Hz overload, 2000 Hz vibration, 1500 Hz both. |
| LED (light-emitting diode) | 2 | The status lights. Green means safe; red means an alarm. |
| 220 Ω resistor | 2 | Limits the current so the part it protects is not damaged. |
| Breadboard and jumper wires | 1 | Hold the parts and join them without soldering. |
How to wire it
Put the parts on the breadboard, join the board's 5V and GND pins to the breadboard's power rails, then make these connections:
| Part | Connection |
|---|---|
| Accelerometer and gyroscope | I²C: SDA → A4, SCL → A5 |
| LED | pin 4 → LED → GND (220 Ω) |
| Potentiometer | wiper (middle leg) → A0 |
| LED | pin 5 → LED → GND (220 Ω) |
| Piezo buzzer | pin 8 → buzzer → GND |
In the Studio, the 💡 guide rings show where each wire goes, and the ✔ Check button tells you which connection is missing.
Starter code
Start from this sketch and write the missing lines. The comments say what each part has to do.
#include <Wire.h>
#include <MPU6050_light.h>
MPU6050 mpu(Wire);
const int BUZZER = 8, GREEN = 4, RED = 5;
// the largest sideways shake seen in the next 100 ms, in g
float vibration() {
float peak = 0;
for (int i = 0; i < 25; i++) {
mpu.update();
float a = abs(mpu.getAccX()) + abs(mpu.getAccY());
if (a > peak) peak = a;
delay(4);
}
return peak;
}
void setup() {
Serial.begin(9600);
Wire.begin();
mpu.begin();
pinMode(BUZZER, OUTPUT);
pinMode(GREEN, OUTPUT);
pinMode(RED, OUTPUT);
}
void loop() {
int load = analogRead(A0);
float shake = vibration();
Serial.print(load);
Serial.print(" ");
Serial.println(shake);
bool overload = load > 700;
bool shaking = shake > 0.25;
// 1. both: tone 1500 Hz 2. only shaking: 2000 Hz 3. only overload: 1000 Hz 4. neither: noTone
// 5. red LED on in any alarm, green LED on only when everything is fine
}
Build it step by step
- Open the project. Press Build it in the Studio. The parts are already in the tray.
- Place and wire the parts. Follow the wiring table above, or switch on the guide rings.
- Write the code. Complete the starter sketch in the Code panel, in text or with blocks.
- Run it. Press ▶ Run and use the part's slider, button or switch to test it. The Serial Monitor shows what your sketch prints.
- Check it. Press ✔ Check: the simulator tests the circuit and the code and tells you exactly what to fix.
Questions students ask
What does the Smart bridge monitor project do?
Watch a model bridge for danger. A potentiometer on A0 stands in for the load sensor and an MPU6050 measures vibration. When all is well the green LED on pin 4 is on and the buzzer on pin 8 is silent. If the load reading passes 700, sound 1000 Hz. If the vibration passes 0.25 g, sound 2000 Hz. If both happen, sound 1500 Hz. In any alarm the red LED on pin 5 is on and the green one is off.
What parts do I need for the Smart bridge monitor project?
An Arduino Uno, accelerometer and gyroscope, potentiometer, piezo buzzer, 2 × LED, 2 × 220 Ω resistor, a breadboard and jumper wires.
How do I wire the Smart bridge monitor project?
Accelerometer and gyroscope: I²C: SDA → A4, SCL → A5; LED: pin 4 → LED → GND (220 Ω); Potentiometer: wiper (middle leg) → A0; LED: pin 5 → LED → GND (220 Ω); Piezo buzzer: pin 8 → buzzer → GND. Power comes from the board's 5V (or 3.3V) and GND pins along the breadboard rails.
What will I learn from the Smart bridge monitor project?
Combining two sensors, finding the peak of a vibrating signal, thresholds, and choosing between several alarm tones with if and else if.
Can I build this without real hardware?
Yes. The project runs in the free Science Tinker microcontroller simulator in your browser: place the parts, wire them, write the sketch and press Run. The ✔ Check button tests your circuit and code and tells you what to fix. Nothing to install and no account needed.
Where is the finished code?
The page gives the starter sketch so that you write the important lines yourself. If you are stuck, the 💡 Solution button in the Studio shows a complete, working sketch that you can run and study.