Page 1 of 1
Forum

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!




Switching between m...
 
Share:
Notifications
Clear all

[Solved] Switching between modes in a program using bluetooth

6 Posts
3 Users
0 Likes
2,178 Views
(@led-bloke)
New Member
Joined: 4 years ago
Posts: 2
Topic starter  

Hi everyone, this is my first post, i like playing with led's and i am slowly learning about Arduino's but i find it very hard with the programming so i am asking for a little help please.

I have made some garden lights and i want to be able to change between effects with my android phone via Bluetooth, i have found about 5 programs i would like to use as different effects, i can get them to run individually and continuously but i want to integrate them with Bluetooth and be able to select whatever light effect i want.

I have built an android app with app inventor (with the help of "Electronoobs" ) on YouTube and i can turn on individual leds with the app but i have tried in vain to get it to work with my program, i have looked at the program on here where all of the light displays are linked together, https://www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/.... i think that is the right link and using a button to switch between effects.

At last i thought, i can use a relay to replace the button and switch it with Bluetooth, simple i thought....... hmmmmmmmmmm not so easy, i have tried to comment out the effects i didn't want with // in the code but i keep getting it wrong, also the code is so long it takes seconds for the relay to switch sometimes.

I know you can put interrupts in but i have no idea how to and ware to put them, the code from the Bluetooth is...  

int rainbow=7;

int Meteor=8;

int colour t=9;

int white t=10;

int snow=11;

int rainbow_state=0;

int meteor_state =0;

int colour t_state = 0;

int white t_state = 0;

int snow_state = 0;

void setup(){

  

  Serial.begin(9600);

  pinMode(rainbow,OUTPUT);

  pinMode(meteor,OUTPUT);

  pinMode(couour t,OUTPUT);

  pinMode(white t,OUTPUT);

  pinMode(snow,OUTPUT);

}

void loop(){

 

 if(Serial.available()>0)

 { 

    Received = Serial.read();

    

 }

////////////////rainbow////////////////////

if (rainbow_state == 0 && Received == '1')

  {

    digitalWrite(rainbow,HIGH);

    rainbow_state=1;

    Received=0;  

  }

if (rainbow_state ==1 && Received == '1')

  {

    digitalWrite(rainbow,LOW);

    rainbow_state=0;

    Received=0;

  }

///////////////////////////////////////////

////////////////meteor/////////////////////

if (meteor_state == 0 && Received == 'a')

  {

    digitalWrite(meteor,HIGH);

    meteor_state=1;

    Received=0;  

  }

if (meteor_state ==1 && Received == 'a')

  {

    digitalWrite(,meteorLOW);

    meteor_state=0;

    Received=0;

  }

///////////////////////////////////////////

////////////////colour t/////////////////////

if (colour t_state == 0 && Received == '2')

  {

    digitalWrite(colour t,HIGH);

    colour t_state=1;

    Received=0;  

  }

if (colour t_state ==1 && Received == '2')

  {

    digitalWrite(colour t,LOW);

    colour t_state=0;

    Received=0;

  }

///////////////////////////////////////////

////////////////white t/////////////////////

if (white t_state == 0 && Received == '2')

  {

    digitalWrite(white t,HIGH);

    white t_state=1;

    Received=0;  

  }

if (white t_state ==1 && Received == '2')

  {

    digitalWrite(white t,LOW);

    white t_state=0;

    Received=0;

  }

///////////////////////////////////////////

  ////////////////snow/////////////////////

if (snow_state == 0 && Received == '2')

  {

    digitalWrite(snow,HIGH);

    snow_state=1;

    Received=0;  

  }

if (snow_state ==1 && Received == '2')

  {

    digitalWrite(snowLOW);

    snow_state=0;

    Received=0;

  }

///////////////////////////////////////////

 

}

I have added some buttons and renamed them but the code works fine with leds and my phone, i am using the "fast led framework" and adding my code in the reliant areas but if someone would be so kind as to show me the code to switch between displays with Bluetooth please i would be so great full.

Regards Martin (led bloke) 


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2660
 

Hi LED Bloke 

Apologies for the late response ...

The idea to use a relay isn't a bad one. But I'd imagine a second Arduino would control the relay then.
I have not yet played with Bluetooth so I cannot give much advise on that topic.
Well, except that BT has a limited rang. Depending on the BT implementation version

  • Class 1 up to 100 meters (or 300 feet) - As far as I know, not very common.
  • Class 2 up to 10 meters (or 30 feet) - the most commonly used BT, often for headsets.
  • Class 3 less than than 10 meters (or 30 feet) - commonly used for keyboards and mice.
On that note: I've seen others play with BT for the LED effect, you may want to checkout their code, for example this post https://www.tweaking4all.com/forums/topic/arduino-all-effects-with-ir-support/ .
I think the main challenge will be the "interrupt" of running code (for example an effect that is currently running). A BT module will (probably) not be able to trigger an interrupt, so we'd need some kind of multitasking/task switching to "read" what the BT is receiving.
I did order a BT module the other day, and would like to tinker with this as well, so hopefully I'll be able to post working code in the next few weeks.


   
ReplyQuote
(@led-bloke)
New Member
Joined: 4 years ago
Posts: 2
Topic starter  

Thank you, it never even crossed my mind to use a second arduino with the relay connected via BT , i am on my way to my shed now to try it........... i will keep you posted.

Thank you sooooo much.

Have a good day

Regards Martin. (led bloke)


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2660
 

I usually wouldn't think about that either - but since they are cheap and you'd solve the interrupt issue with that, this may work! 


   
ReplyQuote
(@reidbecker)
New Member
Joined: 4 years ago
Posts: 1
 

Hi... if u having trouble in making into AT mode of HC-05 (ZS-040)(especiall if one having en/wakeup up pin instead of key pin) and trouble in transfering data between two hc05 module . Follow they bellow procedure
Power off HC-05 module.
Press and hold small button above EN pin.
Power on and keep pressing small button.
Small LED should start to blink slowly about once every 2 seconds.


   
ReplyQuote


 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2660
 

Thanks for the tip! 👍 

I have one of those modules here, but I haven't gotten around testing it yet. 😊 


   
ReplyQuote

Like what you see and you'd like to help out? 

The best way to help is of course by assisting others with their questions here in the forum, but you can also help us out in other ways:

- Do your shopping at Amazon, it will not cost you anything extra but may generate a small commission for us,
- send a cup of coffee through PayPal ($5, $10, $20, or custom amount),
- become a Patreon,
- donate BitCoin (BTC), or BitCoinCash (BCH).

Share: