KY-027 Magic Light Cup Module

The KY-027 Magic Light Cup module is a set of two boards. Each one has a LED and a mercury tilt switch.

Using PWM to drive the LEDs on each module, you can achieve the effect of light being “magically” transferred from one module to the other when tilting them, similar to pouring water from one cup to the other, hence the name.

Compatible with Arduino, Raspberry Pi, ESP32 and other popular electronics platforms.

Arduino KY-027 Magic light cup module

KY-027 Specifications

This is a pair of modules. Each one consist of a mercury tilt switch, an LED, a 10 kΩ resistor and 4 male pin headers to connect the switch, LED, power and ground.

Operating Voltage3.3V ~ 5.5V
Board Dimensions1.5cm x 3.6cm [0.6in x 1.4in]

Connection Diagram

Connect each module using the following diagram.

KY-027 (A)Arduino
KY-027 (B)Arduino

KY-027 Arduino 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


Leave a Comment

2 thoughts on “KY-027 Magic Light Cup Module”

  1. Howdү! I jᥙst would like to give you a big thumbs up for
    your excellent info you hаve here on this ρost.
    I’ll be coming back to your websіte for more sⲟon.

  2. Can you tell me please! More about robotic sensors and how many types.