Foton is an RGB lightsaber equiped with a DHT22 Temperature/Humidity sensor, PIR movement sensor, MP3 shield and a Photon
Temperature and humidity are accessible from your Android smartphone, thanks to the Foton's app.
When a movement is detected, a notification is sent to the app, and the lightsaber simulates a real one, by playing sounds and lights.
Here is a demo of the app:
And here is a test of the lightsaber:
To make this project, I decorated two pipes in order to make them like a light saber, and then inserted an rbg stip inside. The rest of the electronics is on a board on the hilt.
For the "blade" I used a plexiglass pipe covered with a opaque paper. For the hilt instead, it's a gray pipe with a metallic paper on it.
For dht22 sensor, I used PietteTech_DHT library and NEOPIXEL library for the LED strip. Both can be added from the particle cloud IDE.
The MP3 module is controlled by sending commands through its serial interface.
Command set can be found here in the datasheet.
The PIR sensor is simply connected to a digital pin, which is set to high when a movement is detected.
To animate leds, I also used the rainbow function, that is inside the example of the neopixel library.
void rainbow(uint8_t wait)
{
uint16_t i, j;
for(j=0; j<256; j++)
{
for(i=0; i<strip.numPixels(); i++)
{
strip.setPixelColor(i, Wheel((i+j) & 255));
}
strip.show();
delay(wait);
}
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
if(WheelPos < 85) {
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}
To play the lightsaber sound effect, put this file into a fat16 or fat32 formatted microSD card, and insert it in the MP3 module.
The Android app consist of an activity and a service. The activity is started when you launch the app, and it let you see sensor values.
The service runs in background, comunicating with particle's cloud, and sends notification, when a movemen in detected.
If you uncheck the motion detection checkbox, you'll not receive a notification when a movement is detected, but when you open the app, you can see when the last movement detection event was.
In the file "FotonService.java" , on line 97 you have to replace your email and password, and your device ID on line 98:
.........................
sparkCloud.logIn("yourmail", "yourpassword");
device = sparkCloud.getDevice("1234567890987654321");
............................
Comments