Hit enter after type your search item
Home / Arduino / Simple tilt sensor using Arduino and RPI-1031

Simple tilt sensor using Arduino and RPI-1031

The RPI-1031(from sparkfun.com) tilt sensor is capable of sensing a change in orientation in four different directions: forward, back, left or right.

The RPI-1031 employs the principle of ROHM’s advanced photo interrupter technology through the integration of one IR LED and two IR photo transistors. It allows identifying the gravity direction in equipment turning up, down, left and right. One application example is the fully automatic picture format change in digital camera systems, when turning the camera by 90 degrees.

In this project, we are going to use RPI-1031 tilt sensor module with Arduino and switch on two LEDs by tilting the sensor in two directions.

Here we have connected two pins of tilt sensor to pin number 2 and 3 of digital pins and the remaining two pins of tilt sensor to ground and 5 volts. Two led pins are connected to digital pin number 11 and 10 of digital pins.



Arduino Sketch

int tilt_s1 = 2;
int tilt_s2 = 3;
const int ledPin1 =  11; 
const int ledPin2 = 10;
void setup(){
   // initialize the LED pin as an output:
   pinMode(ledPin1, OUTPUT);
   pinMode(ledPin2, OUTPUT);  
   pinMode(tilt_s1, INPUT);
   pinMode(tilt_s2, INPUT);

void loop(){
  int position = getTiltPos();
  delay(10); //only here to slow down the serial output
    digitalWrite(ledPin1, HIGH);  
    digitalWrite(ledPin2, LOW);  


  else if (position==1)
    digitalWrite(ledPin2, HIGH);
    digitalWrite(ledPin1, LOW);

   else {
    // turn LED off:
    digitalWrite(ledPin1, LOW);
    digitalWrite(ledPin2, LOW);


int getTiltPos(){
   int s1 = digitalRead(tilt_s1);
   int s2 = digitalRead(tilt_s2);

   return (s1 << 1) | s2; //bitwise math to combine the values


  • Facebook
  • Twitter
  • Linkedin
  • Pinterest


Leave a Reply to hithesh Cancel reply

Your email address will not be published. Required fields are marked *

fifty two − = 42

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This div height required for enabling the sticky sidebar
Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views : Ad Clicks : Ad Views :

Please Subscribe

Thank you!