The magic light cup module is generally credited to Keyes Electronics which is a specialized company in Arduino-compatible modules. So this module is invented normally to make a visual effect wherever light emerges to transfer flawlessly between two modules when tilted. It imitates the act of pouring fluid from one cup to another cup, providing a visually appealing & interactive element mainly for electronics projects. This module is used in interactive displays or toys because of its “magic” form when merged with programming to LED brightness control depending on the tilt sensor in the module. This article elaborates on the KY-027 module, its working, and its applications.
What is the KY-027 Mtiltodule?
The KY-027 is a magic light cup module with a set of two boards where each board includes an LED & a mercury tilt switch. By using the PWM technique to drive the LEDs on every module, you can attain the light effect being “magically” transmitted from one module to another whenever it is tilted. This module is well-matched with popular electronics platforms like Raspberry Pi, Arduino, ESP32, etc. The KY-027 module includes two HR0025 modules where every module has a tilt switch, a 10 K-Ohm resistor, an LED & 4 male pin headers that connect the switch, power, LED & GND.
How KY-027 Magic Light Cup Work?
The KY-027 magic light cup module works with a mercury tilt switch to notice whenever it is tilted, it triggers an LED to switch on (or) off. So it creates the “magic” effect of a light appearing (or) disappearing when this module is tilted. This module works like a simple tilt sensor with an incorporated LED that specifies the tilt change visually.
Generally, this module includes a mercury tilt switch and an LED. This tilt switch is a significant component made with a mercury-filled small glass tube. This tube works as a switch whenever the module is tilted and allows current supply throughout the circuit whenever the mercury gets in touch with the electrodes on one side of the tube.
Once the mercury switch is triggered by tilting, then it transmits a signal to the microcontroller. After that, it controls the LED on the light cup module to switch ON or OFF by forming the visual effect. By utilizing various magic light cup modules as one, you can create the visual effect of pouring fluid from one cup to another by programming the LEDs to modify the state or brightness based on the tilt of every module.
Pin Configuration:
The KY-027 magic light cup module pin configuration is shown below. This module includes four pins which are explained below.

KY-027 Module Pin Configuration
- Pin (GND): It is a ground pin of the magic light cup module.
- Pin (+/+5V): It is a voltage supply pin of the module that provides +5V supply to the module.
- Pin (S): It is a switch pin of the magic light cup module.
- Pin (L): It is an LED pin of the module.
Features & Specifications:
The features and specifications of the KY-027 magic light cup module include the following.
- KY-027 is a magic light-cup module.
- This module includes four pins.
- The operating voltage of this module ranges from 3.3V to 5.5V.
- This module’s dimensions are; 1.5cm x 3.6cm.
- It is compatible with NodeMCU and Arduino.
- Its weight is 10 grams.
- The type of sensor is LDR or light-dependent resistor.
- The output type is digital.
- The operating voltage is 5V DC.
- Sensitivity adjustment can be done through a potentiometer.
- Its temperature ranges from -40°C to +85°C.
KY-027 Magic Light Cup Module Schematic Diagram
The KY-027 magic light cup module schematic diagram is shown below. So this module includes a mercury tilt switch & LED but they are controlled independently. To make the KY-027 module function, you require a set of two boards wherever every board includes an LED & a mercury tilt switch.
Here PWM is used to drive the light-emitting diodes on every module you can attain the light effect which is being transferred magically from one to the other module whenever it is tilted. The module tilting will reduce the brightness of one module while increasing the brightness of the module, so creating the light illusion of magically transmitting from one cup module to the other module.

Schematic Diagram
The mercury tilt switch has a small amount of conductive mercury liquid within the glass housing. So the mercury roll ball makes (or) breaks contact through switch electrodes when the magic light cup module is tilted. So the output of the tilt switch is brought out to a pin on the cup module.
The tilt switch includes a 10K pull-up resistor that maintains the output very high until the mercury liquid grounds the link. Here ‘Vcc’ is connected to this cup module for this pull-up. So if the inside pull-up on the microcontroller is enabled, then the Vcc line does not require to be connected.
The LED on the cup module is controllable separately through an input pin on the light cup module. So the LED in this module will be turned ON through a HIGH logic input. It needs a series current limiting resistor of around 120 ohms (or) larger to avoid possible harm to the LED (or) the microcontroller for driving it.
KY-027 Magic Light Cup Module Interfacing with Arduino
The KY-027 magic light cup module interfacing with Arduino is shown below. The KY-027 module in this interfacing is a significant component where the mercury switch and an LED are available on a breakout board.
The required components to make this interfacing mainly include a KY-027 magic light cup module, an Arduino board, and jumper wires. The connections of this interfacing follow as;

KY-027 Magic Light Cup Module Interfacing with Arduino
- The ground (G) pin of the magic light cup module is connected to the GND pin of the Arduino board.
- The voltage supply pin of the magic light cup module is connected to the +5V pin of the Arduino board.
- The switch pin of the module is connected to pin 8 of the Arduino board.
- The LED pin of the module is connected to pin 9 of the Arduino board.
Code
The required code of this interfacing includes the following.
// Android and KY-027 module
int brightness = 255; // variable for LED brightness 0~255
void setup() {
pinMode(8, INPUT); // switch is connected to pin 8
pinMode(9, OUTPUT); // LED is connected to pin 9
}
void loop() {
if (digitalRead(8) == HIGH) {
if (brightness < 255) brightness++;
// increase brightness if mercury switch is On
}
else {
if (brightness > 0) brightness–;
// decrease brightness if mercury switch is Off (module tilted)
}
analogWrite(9, brightness); // set LED brightness
}
Working
When power supply is provided to your Arduino Uno board then tilt the module lowly. After that, the brightness of the LED will be dimmer. Return to upright the magic light cup module the LED will turn brighter slowly.
Precautions:
While using a KY-027 magic light cup module, the main safety measure to take is to hold it very carefully because of the occurrence of a mercury tilt switch. So it can be dangerous if broken down or exposed to severe environments. Always ensure correct disposal &avoid exposing the module to extreme vibrations or shock.
The following precautions must be taken while using the magic light cup module.
- Do not open the light cup module to access the inside components, because this could expose mercury vapor to you.
- If this module is broken and mercury is discharged, then take essential security measures like contacting relevant authorities & ventilating the area.
- Avoid applying excessive force or dropping the module.
- Whenever this module is connected to a circuit, make sure the proper polarity to avoid damage.
- Dispose of the module reliably according to the local regulations whenever it reaches the end of its lifetime.
Advantages & Disadvantages
The advantages of the KY-027 magic light cup module include the following.
- The KY-027 module can simulate a pouring liquid effect visually by switching LEDs depending on the tilt.
- The in-built LEDs indicate the tilt condition directly which provides instant visual feedback to the operator without requiring extra displays.
- It outputs a very clear digital signal depending on tilt which makes it simple to interface with a microcontroller without difficult programming.
- These are fairly cheaper than other tilt-sensing solutions.
- Its size is compact.
- A small form factor permits simple integration into a variety of designs.
The disadvantages of the KY-027 magic light cup module include the following.
- It is dependent on a mercury switch.
- It has a limited tilt detection angle.
- This module has the potential for mercury exposure if mismanaged.
- It is responsive to vibrations that might activate unintended activation.
- This module includes a toxic substance like mercury that is very injurious if released into the ingested or surroundings.
- It detects tilt in a specific range of angles, so that may not be enough for projects that need wider tilt detection.
- Sometimes vibrations can activate the switch which leads to sudden activation of the associated LED.
Applications
The light cup applications of the KY-027 magic cup module include the following.
- KY-027 magic cup module is perfect for applications wherever the response to vibration or movement is utilized like; toys, alarm systems, or interactive lights.
- Microcontrollers or systems can be used to detect vibrations by forwarding the trigger signal to the output signal and responding accordingly.
- It is perfect for creating engaging & interactive projects like novelty gadgets, artistic installations, light-up toys, etc.
- This module is used in hobbyist projects and STEM education to lecture fundamental electronics concepts like circuits, LEDs, switches, etc.
- It is used in art & design projects to make dynamic & responsive installations.
- It is perfect for demonstrating tilt sensors & lighting effects within educational environments.
- This sensor module is used in gaming setups or artistic installations wherever dynamic lighting is required.
- This module allows users to make engaging light effects with the least effort. So its unique design will make it a popular choice mainly for DIY electronics educators & enthusiasts.
Please refer to this link for the KY-027 Module Datasheet.
Thus, this is an overview of the KY-027 magic light cup module, its working, and its applications. This module uses a tilt switch & LED to make the pouring light illusion when it is tilted fundamentally simulating the liquid movement within a cup. So it is used frequently in DIY projects to attain interactive lighting effects wherever the light emerges to transmit between several modules whenever tilted. Thus this module is perfect for designing magic (or) visually captivating applications because of its exclusive visual effect. This module is incorporated with Raspberry Pi, ESP32, or Arduino microcontrollers with fundamental programming to LED brightness control & timing for preferred effects. Here is a question for you, the magic light cup module also known as?