Go Down

Topic: Ws2812 not responding to input received from bluetooth (Read 137 times) previous topic - next topic

TheAwakened99

Hello,

I'm working on a project which requires me to switch on only particular LEDs via Bluetooth using an app, for this to work as I want it to the LEDs need to be turned off at the start and only switch on when a particular input is received from the app.
When I connect my phone to the Bluetooth and press the respective buttons responsible for sending data to the Arduino the LEDs do not respond to the data received

Here is my code
Code: [Select]

#include <FastLED.h>
#define NUM_LEDS 5    //no of leds
#define DATA_PIN 7
#define BRIGHTNESS 90             

//#define ledPin 7               //pin to which led is connected on arduino
int state = 0;                 //variable to store data coming from phone

CRGB leds[NUM_LEDS];

void setup()
{
  FastLED.addLeds<WS2812, DATA_PIN, GRB>(leds, NUM_LEDS);                          //setup led strip
  pinMode(DATA_PIN, OUTPUT);                //set led pin as op for bluetooth
  //digitalWrite(ledPin, LOW);               //setting op as low
  Serial.begin(38400);                // Default communication rate of the Bluetooth module
  FastLED.setBrightness(BRIGHTNESS);
  /*for(int i=0;i<NUM_LEDS;i++)
  {
    leds[i] = CRGB::Black;
    FastLED.show();
  }*/
 }
void loop()
{
    if(Serial.available() > 0)            // Checks whether data is comming from the serial port
    {
      state = Serial.read();          // Reads the data from the serial port
      if(state=='1')
      {
        leds[0] = CRGB::Red;
        FastLED.show(); 
      }
      if(state=='2')
      {
        leds[1] = CRGB::Red;
        FastLED.show();   
      }
      if(state=='3')
      {
        leds[2] = CRGB::Red;
        FastLED.show();
      }
      if(state=='4')
      {
        leds[3] = CRGB::Red;
        FastLED.show();
       }
      if(state=='5')
      {
        leds[4] = CRGB::Red;
        FastLED.show();
      }
    }
}

Grumpy_Mike

#1
May 10, 2019, 09:51 am Last Edit: May 10, 2019, 09:51 am by Grumpy_Mike
First check your led code works by opening up the serial monitor and setting it to the same speed as you do in the code. Then use your keyboard to input the numbers. They should work like you want. Do that before trying with Bluetooth.

You should not have started a new thread but continued your old one.

Go Up