Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
WebGeeks
Published © GPL3+

Amazon Alexa-Powered Wireless Speakers

This project shows you how to build your own Amazon Alexa-powered wireless speakers. "Alexa, tell me a joke."

AdvancedFull instructions provided7,314
Amazon Alexa-Powered Wireless Speakers

Things used in this project

Story

Read more

Schematics

Circuit

Arduino NeoPixel Circuit

Code

wpa_supplicant.conf

SH
country=US
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
    ssid="your_real_wifi_ssid"
    scan_ssid=1
    psk="your_real_password"
    key_mgmt=WPA-PSK
}

Arduino NeoPixel Code

Arduino
#include <Adafruit_NeoPixel.h>
#define MIC_PIN A1 // Microphone Input
#define LED_PIN 5 
#define N_PIXELS 11 // Number of LEDs on the ring
#define N 200 
#define fadeDelay 10 
#define noiseLevel 2 
Adafruit_NeoPixel strip = Adafruit_NeoPixel(N_PIXELS, LED_PIN, NEO_GRB + NEO_KHZ800);
int samples[N]; 
int periodFactor = 0; 
int t1 = -1; 
int T; 
int slope; 
byte periodChanged = 0;
void setup() {
 strip.begin();
 ledsOff();
 delay(500);
 displayColor(Wheel(100));
 strip.show();
 delay(500);
}
void loop() {
 readSamples();
}
void readSamples() {
 for(int i=0; i<N; i++) {
   samples[i] = analogRead(0);
   if(i>0) {
     slope = samples[i] - samples[i-1];
   }
   else {
     slope = samples[i] - samples[N-1];
   }
   if(abs(slope) > noiseLevel) {
     if(slope < 0) {
       calculatePeriod(i);
       if(periodChanged == 1) {
         displayColor(getColor(T));
       }
     }
   }
   else {
     ledsOff();
   }
   periodFactor += 1;
   delay(1);
 }
}
void calculatePeriod(int i) {
 if(t1 == -1) {
   t1 = i;
 }
 else {
   int period = periodFactor*(i - t1);
   periodChanged = T==period ? 0 : 1;
   T = period;
   t1 = i;
   periodFactor = 0;
 }
}
uint32_t getColor(int period) {
 if(period == -1)
   return Wheel(0);
 else if(period > 400)
   return Wheel(5);
 else
   return Wheel(map(-1*period, -400, -1, 50, 255));
}
void fadeOut()
{
 for(int i=0; i<5; i++) {
   strip.setBrightness(110 - i*20);
   strip.show();
   delay(fadeDelay);
   periodFactor +=fadeDelay;
 }
}
void fadeIn() {
 strip.setBrightness(100);
 strip.show();
 // fade color in
 for(int i=0; i<5; i++) {
   delay(fadeDelay);
   periodFactor+=fadeDelay;
 }
}
void ledsOff() {
 fadeOut();
 for(int i=0; i<N_PIXELS; i++) {
   strip.setPixelColor(i, 0, 0, 0);
 }
}
void displayColor(uint32_t color) {
 for(int i=0; i<N_PIXELS; i++) {
   strip.setPixelColor(i, color);
 }
 fadeIn();
}
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);
 }
}

Credits

WebGeeks
2 projects • 6 followers
I love DIY projects and I make Machine Learning based projects.

Comments