How to program an Arduino using a HC-06 Bluetooth

I have a WS2812 LED strip that runs off on an Arduino Uno. I have a HC-06 bluetooth module hooked up to the arduino and I have it paired with a linux computer. I want to be able to program the arduino through the bluetooth on my laptop. How would I write the code to do that? Say for instance I wanted to program this code, wirelessly through the bluetooth module. Or what would be better is if I could use the HC-06 module as a switch to turn the led strip on and off?

Anyone have any idea how to do this or maybe link me to someone who did something similar. Thank you

#include "FastLED.h"

#define NUM_LEDS 30
#define DATA_PIN 4
//#define CLOCK_PIN 2

CRGB leds[NUM_LEDS];

void setup()
  {
     
    FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
  }

void loop()

  {
    
    static uint8_t hue = 0;
    for (int px = NUM_LEDS - 1; px > 0; px--)
      {
        leds[px] = leds[px - 1];
      }
    leds[0] = CHSV(hue++, 255, 255);
    FastLED.show();
    delay(10);
  }

How would I write the code to do that?

If you have to ask, the answer is that you can't. You'd need to start with rewriting the bootloader.

Thanks PaulS, I'll look into that.

I found a code and program that I can use to turn on/off the led tied to pin 1. It will turn on or off depending on whether I send a 1 or a 0. How could I change this code so that when I send a 1 to the arduino, instead of turning on pin 13, it runs the code to from my first post to turn on my led strip. Then turns off when I send a zero.

Here is the code I've been trying to alter with no luck.

int ledPin = 13; 
int state = 0;
int flag = 0; 
 
void setup() {
 pinMode(ledPin, OUTPUT);
 digitalWrite(ledPin, LOW);
 
 Serial.begin(9600); // Default connection rate for my BT module
}
 
void loop() {

 if(Serial.available() > 0){
 state = Serial.read();
 flag=0;
 }

 if (state == '0') {
 digitalWrite(ledPin, LOW);
 if(flag == 0){
 Serial.println("LED: off");
 flag = 1;
 }
 }

 else if (state == '1') {
 digitalWrite(ledPin, HIGH);
 if(flag == 0){
 Serial.println("LED: on");
 flag = 1;
 }
 }
}

It may be possible to program your arduino with the HC-06, but it’s much easier to do it with the HC-05, which also have some additional outputs that you can set with the command AT+PIO=X,Y

Where X is the PIO number (available PIO are 0, 1, 2, 3, 4, 5, 6, 7, 10), as in this picture:

And Y is either 1 or 0 (HIGH or LOW)

See this manual for more infos.

For wireless programming, see this.

1jovan2:
Say for instance I wanted to program this code, wirelessly through the bluetooth module. Or what would be better is if I could use the HC-06 module as a switch to turn the led strip on and off?

This is a very strange set of alternatives.
It is trivially easy to send data to an Arduino using bluetooth so why would you even consider trying to upload code if sending data is what you really want?

...R

This all started as a project for school. I basically just have to show that I can wire, program, and use a bluetooth. Which I can already do with the program above that makes pin 13 blink. Since I already have this LED strip light I was hoping that I could use bluetooth to operate it somehow since it would look more impressive than a tiny led on the board. Either by using it as a switch to turn the LED program on or off, or by changing the LED strip show by bluetooth. That is why I'm asking for a strange set of alternatives.
What I want to do most is alternate between different LED programs using either my android or computer, I realize that I may have got the wrong bluetooth now, so I'm just trying to make anything work.

If I have my LED strip running on pin 4 would it be possible to turn that pin off using the HC-06 bluetooth module?

You can send the same data using Bluetooth as you can send with the USB connection and then your Arduino program can do whatever you want with the data it receives - including changing Pin4 from HIGH to LOW or vice versa. (Always assuming the Bluetooth device is not using Pin4)

...R

I think I have figured out how the code should look. Now my problem is my laptop won't connect to my HC-06. My laptop shows that they are paired, but it also says there is no connection between them. I have bluetooth on my laptop, and I've tried a dongle. Still no connection.

When I go to choose the serial port I don't see any option that says bluetooth. When the dongle is in I choose the COM 3 port. This is the usb port the dongle is inserted into.

I've tries hooking RX to RX and TX to TX. Also RX to TX and TX to RX. Still no connection. I can connect the HC 06 to my android phone using the arduDroid app. I make sure this connection is off when trying to connect my laptop

Anybody have any ideas on what's going on here?

1jovan2:
When the dongle is in I choose the COM 3 port.

I thought you said you are using Linux?

Your description is very vague.

Are you saying that you can communicate from your phone to your Arduino, but not from your PC?
If so why are you fiddling with the Rx and Tx connections? If it works, don't fix it.
What software are you using on your PC?

...R

I want to try to introduce android app to programming Arduino Uno via bluetooth, simply by adding Bluino_Shield to your Arduino Uno. This link app https://play.google.com/store/apps/details?id=com.bluino.bluinoloader

mansurkamsur:
I want to try to introduce android app to programming Arduino Uno via bluetooth,

I will be interested to hear how you get on.

...R