Ks0025 keyestudio Digital Tilt Sensor: Difference between revisions
Jump to navigation
Jump to search
PDF
Keyestudio (talk | contribs) |
Keyestudio (talk | contribs) |
||
Line 14: | Line 14: | ||
==Sample Code == | ==Sample Code == | ||
<pre> | <pre> | ||
int ledPin = 13; | int ledPin = 13; // Connect LED to pin 13 | ||
int switcher = 3; | int switcher = 3; // Connect Tilt sensor to Pin3 | ||
void setup() | void setup() | ||
{ | { | ||
pinMode(ledPin, OUTPUT); // Set digital pin 13 to output mode | |||
pinMode(switcher, INPUT); // Set digital pin 3 to input mode | |||
} | } | ||
void loop() | 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 | |||
}</pre> | } | ||
} | |||
</pre> | |||
== Test == | == Test == |
Revision as of 16:44, 11 June 2018
Introduction
Tilt Sensor is a digital tilt switch,which can be used as a simple tilt sensor. Simply plug it to our IO/Sensor shield, it can be used to make amazing interactive projects. With dedicated sensor shield and Arduino, you can achieve interesting and interactive work.
Specification
- Supply Voltage: 3.3V to 5V
- Interface: Digital
- Size: 30*20mm
- Weight: 3g
Connection Diagram
Sample 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 } }
Test
Resources
Video
http://www.keyestudio.com/wp/ks0025/
https://drive.google.com/open?id=1Jh2n_0j4kI9847SeZXDK1xfWuhPjF3dn
Buy from
Official Website
http://www.keyestudio.com/keyestudio-digital-tilt-sensor.html