Introduction: Smart Lamp (TCfD) - Rainbow + Music Visualizer

This project is done for the course Technology for Concept Design at the TUDelft

The Final product is an ESP-32 base LED lamp and is connected to the server. For the prototype, the lamp has two functions; a rainbow effect that emits a soothing color shifting glow towards its surroundings and secondly sound visualizer where the LED pixels “dance” according to sound levels. The system is connected to wifi and the user is able to choose what effect they want from the lamp via WIFI.

The cheap ESP-32 microchip provides us with powerful processors, inbuilt hall sensor, temperature sensor, touch sensor and also wifi and bluetooth capability. With this, Whilst only two effects were chosen for this project, The implication of this “smart” lamp is limitless. It would be used to indicate the weather to the user, or the temperature of the room, the lamp itself can act as an alarm trigger or it can give a calming sunlight glow next to your bed simulating sunrise for a nice wakeup experience.

Step 1: Material Needed

Arduino esp32

Sound sensor

Four way Bi-Directional Logic Level converter

Neopixel led 2m 60 led/m

Jumper wires

Micro USB cable with adapter

Internet connection

Step 2: Circuit Diagram

A circuit diagram was drawn and circuit was made accordingly as given in

the diagram below.

Step 3: Arduino Code

Here, firstly visualizer code was made. Then, two example code

;“neoplxel RGBW starndtest”; and “simpleWebServerWifi” was modified and integrated within the visualizer code. Although the code is still buggy at times (random led’s light up time to time). Next iteration of the code (once we get enough time) will be updated.

#include

#ifdef __AVR__

#include

#endif

const int numReadings = 5;

int readings[numReadings];

int readIndex = 0;

int total = 0;

int average = 0;

int micPin = 33;

#define PIN 4

#define NUM_LEDS 120

#define BRIGHTNESS 100

Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRBW + NEO_KHZ800);

byte neopix_gamma[] = {

0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,

0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,

1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2,

2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5,

5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10,

10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16,

17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 24, 24, 25,

25, 26, 27, 27, 28, 29, 29, 30, 31, 32, 32, 33, 34, 35, 35, 36,

37, 38, 39, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 50,

51, 52, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 66, 67, 68,

69, 70, 72, 73, 74, 75, 77, 78, 79, 81, 82, 83, 85, 86, 87, 89,

90, 92, 93, 95, 96, 98, 99,101,102,104,105,107,109,110,112,114,

115,117,119,120,122,124,126,127,129,131,133,135,137,138,140,142,

144,146,148,150,152,154,156,158,160,162,164,167,169,171,173,175,

177,180,182,184,186,189,191,193,196,198,200,203,205,208,210,213,

215,218,220,223,225,228,231,233,236,239,241,244,247,249,252,255 };

#include

#include

char ssid[] = "yourNetwork"; // your network SSID (name)

char pass[] = "secretPassword"; // your network password

int keyIndex = 0; // your network key Index number (needed only for WEP)

int status = WL_IDLE_STATUS;

WiFiServer server(80);

void setup()

{

Serial.begin(9600); // initialize serial communication

pinMode(9, OUTPUT); // set the LED pin mode

// check for the presence of the shield:

if (WiFi.status() == WL_NO_SHIELD) {

Serial.println("WiFi shield not present");

while (true); // don't continue

}

String fv = WiFi.firmwareVersion();

if (fv != "1.1.0") {

Serial.println("Please upgrade the firmware");

}

// attempt to connect to Wifi network:

while (status != WL_CONNECTED) {

Serial.print("Attempting to connect to Network named: ");

Serial.println(ssid); // print the network name (SSID);

// Connect to WPA/WPA2 network. Change this line if using open or WEP network:

status = WiFi.begin(ssid, pass);

// wait 10 seconds for connection:

delay(10000);

}

server.begin(); // start the web server on port 80

printWifiStatus(); // you're connected now, so print out the status

}

{

Serial.begin(9600);

strip.setBrightness(BRIGHTNESS);

strip.begin();

strip.show(); // Initialize all pixels to 'off'

pinMode(micPin, INPUT);

for (int thisReading = 0; thisReading < numReadings; thisReading++) {

readings[thisReading] = 0;

}

}

void rainbow(uint8_t wait) {

uint16_t i, j;

for(j=0; j<256; j++) {

for(i=0; i

strip.setPixelColor(i, Wheel((i+j) & 255));

}

strip.show();

delay(wait);

}

}

void visualizer(){

total = total - readings[readIndex];

readings[readIndex] = analogRead(micPin);

total = total + readings[readIndex];

readIndex = readIndex + 1;

if (readIndex >= numReadings) {

readIndex = 0;

}

average = total / numReadings;

delay(1);

int micpixel = (average-100)/5;

Serial.println(micpixel);

if (micpixel > 0){

{

for(int j=0; j<=micpixel; j++)

strip.setPixelColor(j,(micpixel*2),0,(90-micpixel),0);

for(int j=micpixel; j<=NUM_LEDS; j++)

strip.setPixelColor(j,0,0,0,0);

strip.show();

}

}

if (micpixel < 0) {

for(int j=0; j<=20; j++)

strip.setPixelColor(j,0,0,50,0);

strip.show();

}

}

void loop() {

{

WiFiClient client = server.available(); // listen for incoming clients

if (client) { // if you get a client,

Serial.println("new client"); // print a message out the serial port

String currentLine = ""; // make a String to hold incoming data from the client

while (client.connected()) { // loop while the client's connected

if (client.available()) { // if there's bytes to read from the client,

char c = client.read(); // read a byte, then

Serial.write(c); // print it out the serial monitor

if (c == '\n') { // if the byte is a newline character

// if the current line is blank, you got two newline characters in a row.

// that's the end of the client HTTP request, so send a response:

if (currentLine.length() == 0) {

// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)

// and a content-type so the client knows what's coming, then a blank line:

client.println("HTTP/1.1 200 OK");

client.println("Content-type:text/html");

client.println();

// the content of the HTTP response follows the header:

client.print("Click here Turn on Rainbow effect
");

client.print("Click here Turn on Visualizer
");

// The HTTP response ends with another blank line:

client.println();

// break out of the while loop:

break;

} else { // if you got a newline, then clear currentLine:

currentLine = "";

}

} else if (c != '\r') { // if you got anything else but a carriage return character,

currentLine += c; // add it to the end of the currentLine

}

// Check to see if the client request was "GET /H" or "GET /L":

if (currentLine.endsWith("GET /R")) {

Rainbow(10); // Rainbow effect turned on

}

if (currentLine.endsWith("GET /V")) {

Visualizer(); // Visualizer is turned on

}

}

}

// close the connection:

client.stop();

Serial.println("client disonnected");

}

}

void printWifiStatus() {

// print the SSID of the network you're attached to:

Serial.print("SSID: ");

Serial.println(WiFi.SSID());

// print your WiFi shield's IP address:

IPAddress ip = WiFi.localIP();

Serial.print("IP Address: ");

Serial.println(ip);

// print the received signal strength:

long rssi = WiFi.RSSI();

Serial.print("signal strength (RSSI):");

Serial.print(rssi);

Serial.println(" dBm");

// print where to go in a browser:

Serial.print("To see this page in action, open a browser to http://");

Serial.println(ip);

}

}

uint32_t Wheel(byte WheelPos) {

WheelPos = 255 - WheelPos;

if(WheelPos < 85) {

return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3,0);

}

if(WheelPos < 170) {

WheelPos -= 85;

return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3,0);

}

WheelPos -= 170;

return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0,0);

}

uint8_t red(uint32_t c) {

return (c >> 16);

}

uint8_t green(uint32_t c) {

return (c >> 8);

}

uint8_t blue(uint32_t c) {

return (c);

}

}

//Serial.println(micpixel);

}

Step 4: 3d Printing the Base of the Lamp

A 3d model of the lamp base was measured, designed and printed with dimensions big enough to fit all the electric components inside the base compartment.

Step 5: Led Attachment

Led’s were winded in cardboard roll and attached using double sided tape, a hole was drilled in the bottom part to pass the wire through

Step 6: Lamp Enclosure

An enclosure was made by finding a transparent bottle with similar width as lamp base and height as the LED attachment. This was then covered with thick paper for better diffusion of light. Alternatively, it is possible to use frosted glass or translucent plastic tubes as lamp enclosure.

Step 7: Setup

Everything was glued together and assembled. And the lamp was ready for some testing!.

Arduino Contest 2017

Participated in the
Arduino Contest 2017

LED Contest 2017

Participated in the
LED Contest 2017