I'm working on Arduino Kit book's Project 8: the digital hourglass. I've got the picture and the circuit diagram below.

picture of the circuit

diagram of the circuit

My question is a fundamental one, and I really don't know how others figured it out. The question is: How do I correctly tie a four-pin tilt sensor to the power and to the ground? I've been through a couple of datasheets for the RBS040100 and none of them were particularly helpful in determining which pin is responsible for what. The most helpful anything has got to be is this pdf sheet where the PCB layout diagram points out an index for every pin and how the pins within the sensor are related, yet it does not explain where the power goes and where the ground is connected.

I also ran into this Arduino SE page but nobody got close to actually explaining how to use (i.e., correctly integrate) the sensor into the circuit.

I know that if you plug a capacitor in the wrong way, it may explode. By the same token I do not want to screw up the sensor or the board, but what do I know. This is the only tilt sensor I've got.

Before my board goes live, I'd like to confirm whether I have the tilt sensor connected correctly.

picture of the tilt sensor currently plugged in

Any help would be appreciated. Let me know if you need anything else for further clarification. Thank you in advance.

Edit: Here's a picture of the four-pin tilt sensor:

picture of the tilt switch

  • the tilt sensor us most likely mechanical switch ... find two pins that open and close the circuit when the switch is moved ... connect it between a data pin and ground ... enable the pullup resistor on the data pin
    – jsotola
    Mar 16, 2023 at 5:39
  • @jsotola : This doesn't quite hit the core of the OP. At the crux of it is my ignorance of which pin is power and which is ground. Also, it is unclear to me whether there is a data pin, which is new information to me. According to the datasheet for the RBS040100, there is only a connection for the power and a connection for the ground. Nothing related to any kind of data. Mar 16, 2023 at 6:31
  • there is no power and ground connection... it's just two wires that get shorted together by a metal ball ... connect it same as a pushbutton switch ... there are many tutorials about connecting switches to an arduino
    – jsotola
    Mar 16, 2023 at 7:32
  • hold one wire in you left hand ... hold another wire in your right hand ... touch the ends of the wires together ... that is the exact same circuit as the tilt switch
    – jsotola
    Mar 16, 2023 at 7:38
  • @jsotola : Then how can any switch possibly yield an "on" signal without power and ground? No power and ground, no current. No switch output of 1 to be read, right? Mar 16, 2023 at 7:56

3 Answers 3


So I've asked this question on the Arduino.cc forum (just to get a safe answer quickly to hustle up on the project). If you look at the pins on the four-pin tilt switch with the notch facing down (as shown on the aforementioned RBS040100 datasheet's PCB layout diagram), you need to know that the connected pins 1 and 2 are to be tied to the power and the connected pins 3 and 4 are to be tied to the ground with a high-Ohm-value resistor (which will serve as a pull-down resistor, e.g. 10kOhm). That means that the "up" arrow on my pictures is indeed to face "east" (in relation to the breadboard) if northern pins are power and southern pins are grounded with a resistor. If for some reason you need it pointing "to the west", then the pins on the northern half are to be connected to ground with a good resistor and the pins to the south are to be connected to power.

updated power-ground schematic

Edit: Here are the results. Image 1 is for the first take and image 2 is for the second take after a tilt to the switch.

take one

take two

  • 1
    if you connect one pin to power and the other to ground, then you will short circuit the power supply when the switch closes
    – jsotola
    Mar 16, 2023 at 7:40
  • @jsotola : I'm not sure if a short circuit would be possible considering that I have a 10kOhm resistor channeling the tilt sensor to the ground. Mar 16, 2023 at 7:52
  • then that side of the switch is not connected to ground ... it's connected to an input pin and to a pulldown resistor on one side and to V+ on the other side
    – jsotola
    Mar 16, 2023 at 7:54
  • @jsotola : Then what is the 10kOhm resistor even for in the first place? Because my experiments guided by the book's instructions (see the images of the results in the edit section of my answer) show something different from what you are suggesting. Mar 16, 2023 at 8:12
  • 1
    an understanding that short-circuiting a power supply is a bad thing should supercede
    – jsotola
    Mar 16, 2023 at 15:46

Like any switch, this is a passive device. It doesn't require power to operate, in the usual sense - it has no active circuitry. Read it just like a push button. Wire one side to a pullup (or pulldown) and an input pin, and the other side to ground (or to +V). When the input is in it's non-passive state (opposite the state it is being pulled to), the device is tilted. The metal ball inside it just shorts two pins (or not).

The only thing that isn't clear from the data sheet is whether all four device pins are independent so the device could indicate one of four directions of tilt (and therefore needs four input pins); or the pins are internally connected in pairs, and only one direction of tilt can be indicated (with a single input pin). A quick experiment should resolve that.

A search for 'tilt sensor' yields a page on arduino.cc relating to tilt sensors and apparently refers to the latter type (one direction of tilt, one input pin). The remaining question is whether your sensor is of the same type.


A tilt switch is just a switch and doesn't need to be powered per se. You just need to detect when it is open or closed, like any other mechanical switch. I have a page about switches: http://www.gammon.com.au/switches

In brief, you can wire a switch with a pull-down resistor as you appear to have done in the end:

Pull-down resistor

In this configuration the input pin will be 0V (LOW) when the switch is open and 5V (HIGH) when it is closed.

Or, you can wire it with a pull-up resistor:

Pull-up resistor

In this configuration the input pin will be 5V (HIGH) when the switch is open and 0V (LOW) when it is closed.

Or, you can use the internal pull-up of the processor and wire it like this:

Internal pull-up

In this configuration the input pin will be 5V (HIGH) when the switch is open and 0V (LOW) when it is closed.

In this case your code might be:

const byte switchPin = 8;

void setup ()
  Serial.begin (115200);
  pinMode (switchPin, INPUT_PULLUP);
  }  // end of setup

void loop ()
  if (digitalRead (switchPin) == LOW)
     Serial.println ("Switch closed.");
     delay (1000); 
     } // end if switchState is LOW
  // other code here ...
  }  // end of loop

Your switch appears to have 4 pins rather than two. Maybe they work in different planes (eg. tilting left/right for one and up/down for the other) or maybe they work at different angles of tilt. A quick check with a multimeter should confirm that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.