This week, I learned how to read datasheets of different sensors. I also ordered some that I found quite interesting and may be useful in my later project, for example KY-027 Magic Light Cup Module.
Important takeaways:
1. serial
UART, SPI, I2C: has its own microcontroller to send data to other controller without using changing voltage method to allow another microcontroller to read the data.
2. datasheet
min, max work and safe voltage; min, max work and safe current; diagrams; pinout.
KY-027 Magic Light Cup Module
KY-027 ModulePinout | Meaning |
L | LED |
S | Signal |
+ | Positive |
– | GND |
This module typically includes a set of two boards, each one has a led and a mercury tilt switch. According to the inner circuit diagram of KY-07 above, the circuit will be open, and LED will not be illuminated while the state of the tilt switch is off and vice versa. It takes digital input and sends out digital outputs. But, by using PWM to drive the LEDs on two boards to fades off and light up, it is possible to create a light transfer from one light to another effect.
Practice: Fading LEDs
I take digital input of the state of the mercury tilt switch and send out a PWM signal to regulate the brightness of both LEDs, in which way the light looks like transferred from one LED to another with fading off effect.
Dim Version
Light Version
Arduino Code:
int ledPinA = 12;
int switchPinA = 11;
int switchStateA = 0;
int ledPinB = 3;
int switchPinB = 2;
int switchStateB = 0;
int brightness = 0;
// fade off effect
void setup() {
pinMode(ledPinA, OUTPUT);
pinMode(switchPinA, INPUT);
pinMode(ledPinB, OUTPUT);
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); // LED A slowly fade out
analogWrite(ledPinB, 255 - brightness); // LED B slowly bright up
delay(20);
}
Possible project ideas:
Considered the characteristic of this module, I come up with a few possible application
Light pipe
Embedding some sets of this module into a cylinder and using PWM to regulate the brightness of the light on both sides to make the light “flows” from one side to another when tilting the pipe.
Sunrise and sunset simulation
Controlling the rotation angle of a servo motor which attached a set of magic light cup modules on each side to regulate the brightness of LEDs. This simulation can be used as a small assistance device for storytelling.
Reference:
https://www.youtube.com/watch?v=pWUwky1QJ08