Help with LED control via Bluetooth

Good morning all,

This is my second post regarding my plan to use an Arduino Uno Mini LE to power LEDS on my 1/8th scale Mustang. Sincere thank to alto777 for solving the first issue I had

The car will be in a display case and I plan to control the LEDs from an App on my phone

I'm using a HC-05 bluetooth module along with an App created on MIT App Inventor 2

The pictures below show that I have the basic set up and running. The Arduino board is powered from the mains (with a switching adaptor plug) I have set the Uno LE up on a small bread board, the pics show the app and the blocks that are set up to power 3 different coloured LEDs

![20220618_104410|375x500](

upload://nRNqkE0fjAwCXIcy3divhRVOdYA.jpeg)



The code I have written is as follows:

char Incoming_value = 0;
                
void setup() 
{
  Serial.begin(9600);         
  pinMode(13, OUTPUT); 
  pinMode(12, OUTPUT);
  pinMode(11,OUTPUT);      
}

void loop()
{
  if(Serial.available() > 0)  
  {
    Incoming_value = Serial.read();      
    Serial.print(Incoming_value);        
    Serial.print("\n");        
    if(Incoming_value == '1')             
      digitalWrite(13, HIGH);  
    else if(Incoming_value == '0')       
      digitalWrite(13, LOW);
    if(Incoming_value == '2')             
      digitalWrite(12, HIGH);  
    else if(Incoming_value == '3')       
      digitalWrite(12, LOW);  
    if(Incoming_value == '4')             
      digitalWrite(11, HIGH);  
    else if(Incoming_value == '5')       
      digitalWrite(11, LOW);  
  }                            
}

As a complete noob you may say I have done this incorrectly but its the only way I can get the set up working to control each individual LED

I plan to use the Uno LE to power LEDs for the following purpose:

Leds required:

  • Headlights (can be powered from 1 pin) if possible I'd like an option to flash as well as constant
  • Spotlights
  • Indicator/ side repeaters, these need to be able to flash the front and rear near side, another button for front and near off side. I'd also like an option to have all 4 flash at once like hazard lights
  • Rear lamps
  • Brake lights
  • Interior/ door lights
  • Dash lights, there maybe multiple micro led's in different colours (I'll know more when I get to it

I believe the UNO LE has enough pins to power the LEDs I need but this is the problem I have:

To start with I am setting up the front bumper with 2 warm white LEDs (headlights) another 2 warm white LEDs (spotlights) and finally 2 orange LEDs for the indicators/ side repeaters

I have attempted to get the LEDs to blink (as the side repeaters would) but cannot seem to get it to work with the bluetooth. When not connected to bluetooth its simple.

Ideally I'd like the side repeaters to work from individual buttons from the App but then also both together at the same time from another button (simulating a hazard light flashing)

I'd also like the headlights to be able to flash/ blink as well as being on constant

Is this even possible??

Thanks in advance

Pete

the logic is surely possible. Even much more complex things.

But you can't power so many LEDs directly from any Arduino-board.

A single IO-pin can stand 20 mA to 30 mA. The whole microcontroller 150 mA.
Each standard-LED pulls a current of up to 20 mA.
The onboard-voltage-regulator can not stand so high currents.
There is a must for supplying so many LEDs from an extra powersupply.
And as you are doing this there is a need for doing it with transistors or small MOS-FETs.

Depending on your soldering skills and if you want to solder you could use a chip like the ULN2803 which is a 8 channel transistor-driver or something like this board

There are really tiny DC-DC-stepdown voltage-regulators in the size of a stamp.
You should post datasheets of the LEDs you want to use and how many LEDs you want to use of each type to summarise and calculate the maximum current.

best regards Stefan

Thanks Stefan,

I really appreciate your reply, I'll look into it

In the short-term though I really need some assistance with how to get the leds to work as I need them too

Thanks again

you have asked is this all possible? Yes for sure. But not in 10 lines of code. It will take much more lines of code.

All in all you want a pretty complex functionality which makes use of different coding-techniques.

The code you have posted above uses the serial-interface of IO-pins 0 and 1 which are "welded" to "Serial".

Some microcontrollers have multiple hardware serial interfaces.
Hardware in this case means there is a sub-unit inside the microcontroller that does receive a byte.

Is your board this mini Arduino Uno?
If yes this board has only one hardware serial interface.
But you can add software-serial interfaces with lower buadrates like 9600
For sending a few bytes this is sufficient.

You have two main parts in your code

  • receiving bytes over bluetooth-module
  • blink LEDs in different paterns

blinking LEDs in different patterns is done by a coding technique called non-blocking timing.
This means you have to learn how non-blocking timing works
As a start that is easier you could code just for switching LEDs on/off

For receiving commands you need a "logic"
if I received this command "1" do "A"
if I received this command "2" do "B"
etc.

For different blinkings your code must have "software-represented" switches. They represent the real switches in a real car. You need a "software-switch" for all of them front-light, blinkers etc.

Asking experts always stays and is a good method. Anyway you should learn more and more to self-initiate learning.

I did a qoogling with
https://www.google.de/search?as_q=arduino+HC-05+demo+code
and came up with this links

https://create.arduino.cc/projecthub/electropeak/getting-started-with-hc-05-bluetooth-module-arduino-e0ca81

So give it a try and start to read if it is understandable.
In case it would be hard to understand ask here in the forum a specific question.

So there are different things that you must learn. There is almost no better suited order than another.
With which part do you want to start?

best regards Stefan

Hello peteh1980
This is possibile.
And this is my proposal to kickoff your project:
You have postet a list of tasks:

To get these task operational you split these in sub tasks using the IPO model:

  • INPUT: BT-Modul
  • PROCESSING: change of LED-state, eg. blinking etc. wrt the received command
  • OUTPUT: copy LED-state change to the LEDs

Per task I would design a task control block containing a relevant and common information for the mentioned tasks. Thus means BT control character, timing information, pin addresses of leds and so on.
The timing information is used by a event controlled timer, derived from the mother of all Arduino timer BLINKWITHOUTDELAY example.
This timer shall be startable and stoppable.
This sounds very complicated, but if your have coded the task, eg Spotlights, the following tasks will be added by the defintion of a new task control block easily. All in all a perfect play ground for C++.

Have a nice day and enjoy programming in C++ and learning.
Дайте миру шанс!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.