Simple tilt sensor using Arduino and RPI-1031

1
2486

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.

WATCH THE VIDEO

SEE ALL THE PHOTOS ON FACEBOOK

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);
   Serial.begin(9600);
  }

void loop(){
  int position = getTiltPos();
  Serial.println(position);
  delay(10); //only here to slow down the serial output
  if(position==2)
  {
    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);
   Serial.println(s2);

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

WATCH THE VIDEO:

BuildCircuit proudly recommends EasyEDA for circuit and PCB design

EasyEDA: A Powerful Free Circuit, Simulation & PCB Design Tool

Register now to use it for free. No Need to download. Lots of resources and Step by step tutorials

 

SHARE

1 COMMENT

LEAVE A REPLY