Arduino Mercury Switch Breakout Module: Difference between revisions

From Geeetech Wiki
Jump to navigation Jump to search
Line 18: Line 18:


==Example code==
==Example code==
int ledPin = 13;                // Connect LED to pin 13  
int ledPin = 13;                // Connect LED to pin 13  
int switcher = 3;                // Connect Tilt sensor to Pin3  
int switcher = 3;                // Connect Tilt sensor to Pin3  
 
void setup()  
void setup()  
{  
{  
   pinMode(ledPin, OUTPUT);      // Set digital pin 13 to output mode  
   pinMode(ledPin, OUTPUT);      // Set digital pin 13 to output mode  
   pinMode(switcher, INPUT);      // Set digital pin 3 to input mode  
   pinMode(switcher, INPUT);      // Set digital pin 3 to input mode  
}  
}  
void loop()  
void loop()  
{  
{  
        
        
   if(digitalRead(switcher)==HIGH) //Read sensor value  
   if(digitalRead(switcher)==HIGH) //Read sensor value  
Line 37: Line 36:
         digitalWrite(ledPin, LOW);    // Turn off LED when the sensor is not triggered  
         digitalWrite(ledPin, LOW);    // Turn off LED when the sensor is not triggered  
     }  
     }  
}
}


==How to buy it==
==How to buy it==
Click here to buy [http://www.geeetech.com/arduino-mercury-switch-breakout-module-p-393.html Tilt sensor module]
Click here to buy [http://www.geeetech.com/arduino-mercury-switch-breakout-module-p-393.html Tilt sensor module]

Revision as of 09:50, 14 May 2012

introduction

The Tilt sensor is a digital mercury-based tilt sensor which allows you to detect orientation and inclination. It acts like a switch. When the tilt sensor is in horizontal position, it’s open. When tilt, the switch closed and pass current.

Note

Mercury is toxic substance, Please be careful to avoid breaking the case.

Features

They are small, inexpensive, low-power and easy to use. Their simplicity make them popular for toy , gadget and appliances and many other application.

Usage

VCC - 5V
GND - GND
S - Digital pin3

Example code

int ledPin = 13;                // Connect LED to pin 13 
int switcher = 3;                 // Connect Tilt sensor to Pin3 
void setup() 
{ 
 pinMode(ledPin, OUTPUT);      // Set digital pin 13 to output mode 
 pinMode(switcher, INPUT);       // Set digital pin 3 to input mode 
} 
void loop() 
{ 
     
  if(digitalRead(switcher)==HIGH) //Read sensor value 
    {  
       digitalWrite(ledPin, HIGH);   // Turn on LED when the sensor is tilted 
    } 
  else
    { 
       digitalWrite(ledPin, LOW);    // Turn off LED when the sensor is not triggered 
    } 
}

How to buy it

Click here to buy Tilt sensor module