Arduino Magic Light Cup Tutorial

by Utsource in Circuits > Arduino

862 Views, 0 Favorites, 0 Comments

Arduino Magic Light Cup Tutorial

Screenshot_20191121-195156__01.jpg
Hi guys in this instructables we will learn how to use Magic light Cup module with arduino.

Arduino 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.

Things You Need

Km5Zu-2RIncAUweU7uG7IhyWPySZ0SqIgAI0-vk9w7767_IkthCPCcsirj2GGmXF4IdQDg8UVpHVLVM6CXnzFsG1hnAdSkK7BIhIOtEldXoZiDsvzsPo-6o0rD6Mda7UyOE=w456-h323-nc.png
images(109).jpg

In this instructables we will need following things :

Arduino uno

Magic light cup tutorial

Jumper wires

Breadboard

Schmatics

20191122_083235.jpg
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

Please follow the shown schmatics and connect everything According to it.

Code

20191121_193959.jpg
Please copy the following code and upload it to the arduino Board :

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);
}

Magic Light Cup in Action

Screenshot_20191121-195156__01.jpg
Screenshot_20191121-195134__01.jpg
In this Arduino project we are using both the 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. 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.