A WiFi-enabled Arduino web server that exposes a JSON API for controlling digital pins over HTTP. Originally built for remote control of a door buzzer.
- Arduino board with WiFi Shield 101
- ArduinoJson library (v5)
- WiFi101 library
- Open
arduino-json-api.inoin the Arduino IDE - Update
ssidandpasswith your WiFi credentials - Adjust
validPins[]if needed (some pins are reserved for the WiFi shield) - Upload to your board
The serial monitor (9600 baud) will display the board's IP address once connected.
All endpoints use HTTP GET and return JSON responses.
Read the current state of a pin.
GET /STATE/2
{"status":"ok","action":"STATE","data":[{"pin":2,"value":0}]}Read the state of all valid pins.
GET /STATE
{"status":"ok","action":"STATE","data":[{"pin":1,"value":0},{"pin":2,"value":1},...]}Set a pin HIGH.
GET /ON/2
{"status":"ok","action":"ON","data":[{"pin":2,"value":1}]}Set a pin LOW.
GET /OFF/2
{"status":"ok","action":"OFF","data":[{"pin":2,"value":0}]}Set a pin HIGH for 5 seconds, then automatically turn it LOW. The response is returned immediately (non-blocking).
GET /BUZZ/2
{"status":"ok","action":"BUZZ","data":[{"pin":2,"value":1}]}Invalid actions, missing pins, or disallowed pins return a 400 status:
{"status":"error"}By default, pins 1, 2, 3, 4, 6, 8, 9, 10, 11, 12, 13 are available. Pins 0, 5, and 7 are reserved for the WiFi shield. Edit validPins[] to change this.