nfarrier
Published © GPL3+

Android Phone Control of NeoPixel Display

Use an Android device to control the color of a NeoPixel via a Bluetooth connection.

BeginnerFull instructions provided7,333
Android Phone Control of NeoPixel Display

Things used in this project

Story

Read more

Schematics

Bluetooth NeoPixel Schematic

Fritzing schematic

Code

Bluetooth_NeoPixel_Control

Scheme
MIT App Inventor 2 aia file to control an Arduino NeoPixel via Andriod phone with Bluetooth connection
No preview (download only).

Bluetooth_NeoPixel_Control

Arduino
Allows control of Arduino NeoPixel via Android phone Bluetooth connection
/*
* Bluetooh Basic: NeoPixel color changer
* Coder - Mayoogh Girish; Modified by Lucas W
* Website - http://bit.do/Avishkar
* Download the App : https://github.com/Mayoogh/Arduino-Bluetooth-Basic
* This program lets you to control a NeoPixel display on pin 6 of Arduino using a bluetooth module
*/
  #include <Adafruit_NeoPixel.h>

#define PIN 6
#define NumOfLEDs 1

Adafruit_NeoPixel strip = Adafruit_NeoPixel(NumOfLEDs, PIN, NEO_GRB + NEO_KHZ800);

char data = 0;            //Variable for storing received data

void setup()
{
    strip.begin();
    strip.show();         // Initialize all pixels to 'off'
    Serial.begin(9600);   //Sets the baud for serial data transmission                               
    pinMode(12, OUTPUT);  //Sets digital pin 13 as output pin
}
void loop()
{
   if(Serial.available() > 0)      // Send data only when you receive data:
   {
      data = Serial.read();        //Read the incoming data & store into data
      Serial.print(data);          //Print Value inside data in Serial monitor
      Serial.print("\n");        
      if(data == '0')  {           //  Checks whether value of data is equal to 0 or black
         strip.setPixelColor(0, strip.Color(0, 0, 0)); //off
         strip.show();     // This sends the updated pixel color to the hardware.
      }
      if(data == '1')  {       // Red
         strip.setPixelColor(0, strip.Color(255, 0, 0));//red
         strip.show();     
      }
      if(data == '2')  {       // Pink
         strip.setPixelColor(0, strip.Color(255, 0, 255)); //pink
         strip.show(); 
      }
      if(data == '3')  {       //  Orange
         strip.setPixelColor(0, strip.Color(255, 136, 0)); //orange
         strip.show(); 
      }
      if(data == '4')  {       //  Yellow
         strip.setPixelColor(0, strip.Color(255, 255, 0));  // yellow
         strip.show(); 
          }
      if(data == '5')  {       //  Green
         strip.setPixelColor(0, strip.Color(0, 255, 0));  //green
         strip.show(); 
          }
      if(data == '6')  {       //  Blue
         strip.setPixelColor(0, strip.Color(0, 0, 255)); // blue
         strip.show(); 
          }
      if(data == '7')  {       //  Teal
         strip.setPixelColor(0, strip.Color(0, 255, 255));  // teal
         strip.show(); 
      }
      if(data == '8')  {       //  Purple
         strip.setPixelColor(0, strip.Color(70, 5, 184)); // purple
         strip.show(); 
      }
      if(data == '9')  {       //  White
         strip.setPixelColor(0, strip.Color(255, 255, 255));  // white
         strip.show(); 
      }
      if(data == 'R')  {       //  Checks whether value of data is equal to 0
          rainbowCycle(4); 
      }
   }
}

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

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

// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
    for(i=0; i< strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
    }
    strip.show();
    delay(wait);
  }
}

Credits

Bryce K and Lucas W

Posted by nfarrier

Comments