Virtual Pins Reference
Virtual pins (V0–V255) are the data channels between your firmware and your dashboard widgets.
Sending data to the dashboard
Call virtualSend inside your loop() at whatever interval makes sense for your sensor:
// Send a float
Vwire.virtualSend(V0, temperature);
// Send an integer
Vwire.virtualSend(V1, humidity);
// Send a formatted string
Vwire.virtualSend(V2, String(speed, 1) + " km/h");
// Send multiple values (CSV) — used by MAP widget
Vwire.virtualSend(V3, String(lat, 6) + "," + String(lon, 6));
VWire will throttle extreme write rates. Sending data every 100–2000 ms is appropriate for most sensors.
Receiving commands from the dashboard
Register a handler for pins that widgets write back to (e.g. a Button or Switch):
VWIRE_RECEIVE(V5) {
int value = param.asInt();
digitalWrite(RELAY_PIN, value); // 1 = on, 0 = off
Vwire.virtualSend(V5, value); // echo back current state
}
VWIRE_RECEIVE(V6) {
int brightness = param.asInt();
analogWrite(LED_PIN, brightness); // 0–255 from a Slider
}
Reading pin state on connect
To restore state after a device reboots, sync the current server-side value in setup():
void setup() {
Vwire.begin(SSID, PASSWORD);
// Request current value from server
Vwire.syncVirtual(V5); // will trigger VWIRE_RECEIVE(V5) with current value
}
Data types
All values travel as strings over MQTT. The library provides helpers:
| Method | Returns |
|---|---|
param.asStr() | const char* |
param.asInt() | int |
param.asFloat() | float |
param.asDouble() | double |
Pin assignment tips
| Range | Suggested use |
|---|---|
V0–V9 | Primary sensor readings |
V10–V19 | Secondary / computed values |
V20–V29 | Control outputs (relays, PWM) |
V100–V109 | GPS / location data |
V200–V255 | Metadata (heap, RSSI, IP, etc.) |
Digital and analog pins (D / A prefix)
In addition to virtual pins, VWire supports addressing physical hardware pins directly using D-prefixed (digital) and A-prefixed (analog) pin names.
| Pin prefix | Example | Description |
|---|---|---|
D0–D99 | D2, D13 | Digital GPIO — reads or writes 0/1, or PWM (2–255) |
A0–A15 | A0, A1 | Analog ADC input — reads raw ADC value |
V0–V255 | V0, V5 | Virtual pin — arbitrary data, no hardware mapping |
Physical pin names map directly to the labels printed on your development board:
D4on an ESP8266/NodeMCU board refers to the pin labeled D4, which is hardware GPIO 2D4on an ESP32 board refers to GPIO 4
The library resolves these mappings automatically — you never need to look up GPIO numbers.
When to use virtual pins vs physical pins
| Scenario | Use |
|---|---|
| Sensor value (temperature, humidity, ADC) | V0–V255 (virtual) |
| Computed / formatted value | Virtual |
| Control a relay, LED, buzzer directly | D-pin via GPIO manager |
| Read a button or switch state directly | D-pin via GPIO manager |
| Read a potentiometer or analog sensor | A-pin via GPIO manager |
| Multiple values per update (CSV) | Virtual |
Physical pins are managed by the GPIO Pin Manager feature. See GPIO Pin Manager for setup and usage.