Raspberry Pi Project for Smart Mirror: Setup and Code Example
A smart mirror project with
Raspberry Pi involves connecting a monitor behind a two-way mirror and running software like MagicMirror² on the Pi. You install the OS, set up the MagicMirror software, and customize modules to display time, weather, news, and more on the mirror surface.Syntax
To set up a smart mirror on Raspberry Pi, you use commands to install the operating system, dependencies, and the MagicMirror software. The main commands include:
sudo apt update- updates package listssudo apt install -y nodejs npm- installs Node.js and npm for running JavaScript appsgit clone https://github.com/MichMich/MagicMirror- downloads the MagicMirror softwarenpm install- installs MagicMirror dependenciesnpm start- runs the MagicMirror app
Each command prepares the Raspberry Pi to run the smart mirror software and display information on the screen behind the mirror.
bash
sudo apt update
sudo apt install -y nodejs npm
cd ~
git clone https://github.com/MichMich/MagicMirror
cd MagicMirror
npm install
npm startExample
This example shows how to start the MagicMirror app on Raspberry Pi and customize the config file to show time and weather.
After installing MagicMirror, edit config/config.js to add modules like clock and weather.
javascript
/* config/config.js snippet */ { module: "clock", position: "top_left" }, { module: "weather", position: "top_right", config: { weatherProvider: "openweathermap", type: "current", location: "New York", apiKey: "YOUR_API_KEY" } }
Output
The smart mirror screen shows the current time on the top left and weather info on the top right.
Common Pitfalls
Common mistakes include:
- Not installing Node.js and npm correctly, causing MagicMirror to fail.
- Forgetting to get an API key for weather modules, so weather data won't show.
- Running MagicMirror without a monitor connected, making it hard to debug.
- Not setting the Raspberry Pi to auto-start MagicMirror on boot.
Always test each step and check logs for errors.
bash
/* Wrong: Missing npm install */ npm start /* Right: Install dependencies first */ npm install npm start
Quick Reference
| Step | Command / Action | Purpose |
|---|---|---|
| 1 | sudo apt update | Update package lists |
| 2 | sudo apt install -y nodejs npm | Install Node.js and npm |
| 3 | git clone https://github.com/MichMich/MagicMirror | Download MagicMirror software |
| 4 | cd MagicMirror && npm install | Install MagicMirror dependencies |
| 5 | npm start | Run the MagicMirror app |
| 6 | Edit config/config.js | Customize modules like clock and weather |
| 7 | Set up auto-start script | Launch MagicMirror on boot |
Key Takeaways
Install Node.js and npm before running MagicMirror on Raspberry Pi.
Customize the config file to add useful modules like clock and weather.
Get API keys for weather modules to display live data.
Test the setup with a connected monitor before final assembly.
Set MagicMirror to auto-start for a seamless smart mirror experience.