tilt sensor/How it works/06. VCC is your logic voltage
How it works · 06 of 10

VCC is your logic voltage

A closed switch joins SIGNAL straight to VCC, with no resistor in between. So VCC is the HIGH your board reads, and it has to be the voltage your board's pins run at: 3V3 on an ESP32, an ESP32-S3 or a Pico, 5V on an Uno. The block works on either; your pin does not.

What the pin sees

Open, SIGNAL is 0 V through the 10 kΩ. Closed, it is VCC, less a few millivolts across the balls. Nothing on the block changes that voltage: no regulator, no divider, no resistor in series. Whatever you wire to VCC is what arrives on your pin every time the left edge goes down.

VCC is your logic voltage
Your board
VCC wired to
SIGNAL closed
5 V
Reads
HIGH
ESP32-S3 runs at
3.3 V
Wire VCC to
3V3
Wrong. A closed switch puts 5 V straight onto a pin whose own supply is 3.3 V. It will read HIGH, and it is also more than the pin is rated for; there is no resistor in the way to limit it. Move VCC to 3V3.

Pick your board, then try both supplies. The green bar is what a closed switch puts on SIGNAL. The dashed line is the lowest level the pin is sure to call HIGH: 0.6 × VCC on the Uno's ATmega328P, 0.75 × VDD on an ESP32, 2.0 V on a Pico's RP2040. The red line is the pin's own supply.

Which pin, on which board

  • ESP32, ESP32-S3, Pico: VCC to 3V3. Their pins run at 3.3 V. The 5V pin (VBUS on a Pico) would put 5 V on a 3.3 V pin with nothing to stop it.
  • Arduino Uno: VCC to 5V. 3V3 is read as HIGH too, but with only 0.3 V to spare.

The switch itself does not care. Both makers rate it for 12 V, far more than any of these boards gives it.

When it does not work

I wired VCC to 5V on my ESP32 and it still reads fine.

It reads HIGH because 5 V is well above HIGH. It is also 5 V on a pin whose own supply is 3.3 V, every time the left edge goes down, with nothing to limit it. Move VCC to 3V3 before it costs a pin.

My Uno reads the switch with VCC on 3V3. Is that fine?

It works, with little to spare: the Uno reads HIGH from 3.0 V and 3V3 gives it 3.3. Move VCC to the Uno's 5V and the margin is the whole supply.

Does the switch mind 5 V?

No. Both makers rate the SW-520D for 12 V, and Shouhan for 10 mA; at 5 V the block puts about 3.5 mA through it. VCC is chosen for the pin that reads SIGNAL, not for the switch.

Alongside this page
Where this goes next

Three wires and a few lines of sketch.

The first read →

Edit this page — content/books/tilt-sensor/vcc-is-your-logic-voltage.mdx

Community

Questions about this product

See what other owners have asked, and read their solutions.

Ask a question ↗

Tilt Sensor

Loading discussions…

Discuss this article

Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.

Browse Modules and blocks on the forum →