Skip to product information
1 of 2

Blue PCB Electronics

2C90009 Magic Light Cup modules KY-027

2C90009 Magic Light Cup modules KY-027

Regular price Dhs. 12.00
Regular price Sale price Dhs. 12.00
Sale Sold out
View full details

Description

Magic Light Cup Module is a board which has a led and a mercury tilt switch. Using PWM to drive the LEDs on the module user can achieve the effect of light being “magically” transferred from one module to the other when tilting them. In short, it’s 2 components combined, a mercury tilt switch and a led. On tilting the module mercury inside small tube connect the switching point and make switch ON while tilting it to other side move the mercury and it disconnects the circuit and switch get OFF. The module operates on 5V DC supply.
 
So the magic in the name of this module is because when you tilt the switch, the led will turn on and off. It is also possible to connect it to the NodeMCU.
 

Overview 

  • Operating voltage: 3.3V to 5.5V
  • Compatible with Arduino compatible boards & NodeMCU
  • When you tilt the switch, the led will turn on and off

Features

  • Compatible with Arduino & NodeMCU
  • When you tilt the switch, the led will turn on and off
 

Specifications

  • Operating voltage: 3.3V to 5.5V
  • Dimension: 1.5cm x 3.6cm
  • Weight: 10 g

Connection Diagram

Connect each module using the following diagram.

KY-027 (A) Arduino
G GND
+ +5V
S 8
L 9


KY-027 (B) Arduino
G GND
+ +5V
S 7
L 6

KY-027 Code

In this Arduino sketch we’ll use both modules to create the magic light cup effect. The mercury switches in each module provide a digital signal that is used to regulate the brightness of the LEDs using using PWM.

Place the modules so the mercury switches on each other are facing in the opposite directions. Tilting the modules will decrease the brightness on one module while increasing it on the other one, creating the illusion of light magically passing from one module to the other.


int ledPinA = 9;
int switchPinA = 8;
int switchStateA = 0;
int ledPinB = 6;
int switchPinB = 7;
int switchStateB = 0;
int brightness   = 0;

void setup() 
{
  pinMode(ledPinA, OUTPUT); 
  pinMode(ledPinB, OUTPUT);  
  pinMode(switchPinA, INPUT); 
  pinMode(switchPinB, INPUT);
}

void loop() 
{
  switchStateA = digitalRead(switchPinA);
  if (switchStateA == HIGH && brightness != 255)
  { 
   brightness ++;
  } 
  switchStateB = digitalRead(switchPinB);
  if (switchStateB == HIGH && brightness != 0)
  { 
   brightness --;
  } 
  analogWrite(ledPinA, brightness);  //  A slow fade out
  analogWrite(ledPinB, 255 - brightness);  // B slow bright up
  delay(20);
}