Introduction: SW-520D Vibration Sensor Metal Ball Tilt Switch - Visuino
This SW-520D basic tilt switch can easily be used to detect orientation. Inside the can is a ball that make contact with the pins when the case is upright. Tilt the case over and the balls don’t touch, thus not making a connection.
The tilt sensor allows to detect orientation or inclination. It detects if the sensor is completely upright or if it is tilted, In this tutorial, we will learn how a Tilt Sensor works and how to use it with the Arduino Board for detecting motion.
We will use a piezo module to make a sound everytime the switch makes a contact.
Watch a demonstration video.
Step 1: What You Will Need
Arduino UNO (or any other Arduino)
SW-520D Tilt Sensor
Piezo module
RED LED
1K ohm resistor
Jumper wires
Breadboard
Visuino program: Download Visuino
Step 2: The Circuit
- Connect Piezo module pin [-] to Arduino pin [GND]
- Connect Piezo module pin [+] to Arduino pin [5V]
- Connect Piezo module pin [S] to Arduino digital pin [7]
- Connect Tilt sesnsor pin[1] to Arduino pin [5V]
- Connect Tilt sesnsor pin[1] to Arduino digital pin [8] and to resistor.
- Connect other side of the resistor to Arduino pin [GND]
- Connect LED positive pin to Arduino digital pin [7]
- Connect LED negative pin to Arduino pin [GND]
Step 3: Start Visuino, and Select the Arduino UNO Board Type
To start programming the Arduino, you will need to have the Arduino IDE installed from here: https://www.arduino.cc/.
Please be aware that there are some critical bugs in Arduino IDE 1.6.6. Make sure that you install 1.6.7 or higher, otherwise this Instructable will not work! If you have not done follow the steps in this Instructable to setup the Arduino IDE to program Arduino UNO! The Visuino: https://www.visuino.eu also needs to be installed. Start Visuino as shown in the first picture Click on the "Tools" button on the Arduino component (Picture 1) in Visuino When the dialog appears, select "Arduino UNO" as shown on Picture 2
Step 4: In Visuino Add and Connect Components
- Add "Digital (Boolean) Inverter (Not)" component
- Connect Arduino digital pin out [8] to "Inverter1" component pin [In]
- Connect "Inverter1" component pin [Out] to Arduino Digital pin [7]
Step 5: Generate, Compile, and Upload the Arduino Code
In Visuino, Press F9 or click on the button shown on Picture 1 to generate the Arduino code, and open the Arduino IDE
In the Arduino IDE, click on the Upload button, to compile and upload the code (Picture 2)
Step 6: Play
If you power the Arduino UNO module, and press the force sensor sensor you should see a changing number on the OLED display and a green LED should light but when you hit the limit the red LED should shine.
Congratulations! You have completed your project with Visuino. Also attached is the Visuino project, that I created for this Instructable, you can download it here
and open it in Visuino: https://www.visuino.eu