In this tutorial, we will be using a light cup sensor or mercury tilt switch (KY-027). We are going to program our Surilli with a basic program so we can detect vibrations.
Light Cup Sensor (KY-027)The light cup is a device that when you move the mercury tilt switch the light will become dim light; it uses pulse width modulation (PWM) dimming principle. The mercury switch will provide a digital signal that triggers the PWM through the code program. The ideas comes from this module is for example if you to attach this module into the tree branch ones the wind push the brand the mercury switch also and along with the switch move the LED with dimming effect or any desired output. It can also be used for security purpose for e.g if someone opens your door, sensor will send you a signal. Compared to vibration sensor, the mercury switch is more sensitive because the valve itself has a liquid moving element to trigger. This module has two parts, an LED and a mercury tilt switch.
- pin 1 is connection to ground
- pin 2 is connected to 5v power
- pin 3 is a signal
- pin 4 is the board LED
If you wire the pin 1 and 2 to power, pin 3 the signal will alternate between 5v and 0v or HIGH and LOW as you tilt the module.
STEP 1: Set Up Arduino IDE for SurilliMake sure you have selected the right port, board and processor for the Surilli and it is programmable (compile and upload “Blink” from File>Examples>Digital>Blink onto your Surilli to check if everything is working fine).
STEP 2: The CircuitryThe circuitry is very simple. It's mostly the programming, follow the figure below to set up your hardware.
- Now you have completed setting up your hardware and Arduino IDE. Copy and paste the Arduino sketch given below into your Arduino IDE and hit upload.
- After it is uploaded, the sensor will start working.
int vibration_sensor =6;
int led =5;
void setup() {
pinMode(vibration_sensor, INPUT);
pinMode(led, OUTPUT);
Serial.begin(9600);
}
void loop() {
delay(500);
int Sensor = digitalRead(vibration_sensor);
if(Sensor == 1){
Serial.println("Value1");
digitalWrite(led, HIGH);
}
if(Sensor == 0){
Serial.println("Value2");
digitalWrite(led ,LOW);
}
}
Play with the program to see how it reacts to different values and logic. This will develop your understanding about light cup sensors so you can use them in your practical application.
If you make something fun and interesting, do share it with our community.
That’s all for now. If you have any queries, visit surilli.io or contact our support. Stay connected with Surilli family for more amazing stuff. :-)
Comments
Please log in or sign up to comment.