Set up the Arduino IDE
- Install Arduino IDE 1.6.4 or newer.
- Enable the ESP8266 board:
- Add http://arduino.esp8266.com/stable/package_esp8266com_index.json to File, Preferences, Additional Boards Manager URLs.
- Open Tools, Board, Boards Manager and wait for it to refresh.
- Search for and install esp8266 by ESP8266 Community.
- Choose your ESP2866 module from Tools, Board, ESP2866 Modules. Using my Amazon purchase, this is NodeMCU 1.0 (ESP-12E Module).
- Install libraries:
- Open Sketch, Include Library, Manage Libraries...
- Search for and install PubSubClient by Nick O'Leary.
- Search for and install Ultrasonic by Erick Simões.
Wire it up
Connect the sensor to the microcontroller board according to my setup so you don't have to remap pins in code. I used prebuilt F2F wires to make it easier on myself.
- Connect the microcontroller to your computer using a microUSB cable.
- Download and open GarageDoorSensor.ino.
- Replace the values at the top of the file with your own WiFi network info, MQTT server config, etc. For the distance threshold, choose something a little bit (about 5 cm) higher than the distance between your ceiling and the garage door when it is open.
- If you want an easy way to make sure it works correctly from your computer, set DEBUG to 1 and open the Serial Monitor at 115200 baud. If you're ready to install it in its permanent location, set DEBUG to 0 in order to save some CPU cycles.
- Be sure you have the correct options specified in the Tools menu:
Board NodeMCU 1.0 (ESP-12E Module) if you're using the same board CPU Frequency 80 MHz Flash Size 4M (3M SPIFFS) Upload Speed 9600
- Press Upload and wait for it to flash. Don't worry if it's slow, it normally takes quite a bit longer than flashing a regular Arduino.
- Get 4 screws that will go into the ceiling of the garage.
- Open the garage door and mark the locations of the four screw holes of the housing so that the sensor is above the door.
- Close the door and mount the housing.