Introduction: 3-LED Backlight: Xamarin and Arduino With HC05

Picture of 3-LED Backlight: Xamarin and Arduino With HC05

Hello dear community,

Today im gonna show you how to make a full Androidapp-controllable LED Backlight for your TV for under 10$.

In this Instructable i will show you:

  • To use my Xamarin Bluetooth-APP(Open Source C#-Code)
  • Programming your Arduino
  • And let them communicate to each other

I am using an Arduino Uno r3(Sainsmart UNO) for the HC-05 and Visual Studio Ultimate 2013(Xamarin Plug-In) for programming our Bluetoothsoftware. I really looked a long time on the internet to find such a tutorial, but there just were a few good tutorials, which only described the Xamarin- or the Arduino-sided stuff well. Especially the the compatibilty of my Smartphone(Android 4.1.2) made huge problems, but i found a solution which worked for me. And it runs more stable on Android 5.0> :). Ok Here we go:

You will need:

  • Arduino(Mega, uno, etc.)
  • HC-05(HC-06 is also possible)
  • Xamarin Plugin or IDE. It's free for 30 days of trial (https://www.xamarin.com/)

Actuallly this Instructable is not directed to C#-Programming, but the code should be easy to understand.

If not post a comment, or write a message :)

Step 1: The Xamarin - Code

Picture of The Xamarin - Code

Okay first of all we have to write our Code:

Make your own Design or use mine(recommended) to have a GUI which the user can use easily.

"Disconnect" causes an event which sends the value 187 to the Arduino which restarts the HC-05(required).

The Buttons LED1, LED2, LED3 causes the event to send a 1,2 or 3 to the Arduino.

The Brightness seekBar sends a value between 10 and 168.

Download below !

_____

Create a new Xamarin-Project and call it e.g. "BluetoothApp".

When you have done this, please change the namespace (Options>Android options) to Backlight, or change the namespace in the MainActivity.cs, you already integrated, to yours. After this you have to pair your device over Bluetoothsettings.

We want to create this App as easy as possible, so we only use the static name of our HC-05/-06 in my case the standard name of this module "HC-05" to connect and communicate.

The only thing i found out to get this work is to create a "BluetoothDevice" by using the Name "HC-05" of your Bluetoothmodule. When I try to create a BluetoothSocket with a BluetoothDevice which is not created with the name, it crashes. I dont know why but it's a adequately solution.

In my code you can change the name to your devices name in the class BluetoothConnection. This step is required to get the App running!

this Line:

public void getDevice() { this.thisDevice = (from bd in this.thisAdapter.BondedDevices where bd.Name == "HC-05" select bd).FirstOrDefault(); }

When you have done this, try to get away possible errors and then we come to the interesting Part :)

Step 2: Arduino Code

In this .ino file you find the program i am running on my Sainsmart Uno. I used numbers to code the information i want to transmit, e.g. '187' for killing, '1' for LED one etc. There are also values between 15 and 168 for the brightness given by the APP(Slidebar). The standard brightness is 80.

I used following Pin-assignments:

13 - Pinout TTL 5V for HC05/06-Supplyvoltage(and also for restarting)

3,5 and 6 - PWM output for LED's

Tx - to HC05/06 Rx

Rx - to HC05/06 Tx ( a bit confusing, but very important! )

GND - TO HC05/06 GND

In some documentations I found a voltage divider between Tx and Rx(and of course GND) to set the Voltage to 3.3V, but my HC05/06 also works great with 5V potential. So just connect and go on! :)

________

I also tried this with an AtTiny45, but this is a bit more complicated, becauce this IC only has one PWM-port and you need 3 for 3 LED's. That's why you have to programm a timer.

An other way is, to use a bipolartransistor as amplifier.

Write me for more information!

Step 3: Relax and Be Proud of Yourself

Picture of Relax and Be Proud of Yourself

Hopefully you got it soon. If there are some Questions, just write a comment or a private message. I will reply as soon as possible.

If you enjoyed this instructable please leave a comment and follow me :)

See you!

Comments

PvelV (author)2017-10-18

is the xamarin project created as xamarin.forms and then you only use the android part or is it created just as xamarin.android? could you maybe post the whole project, not just the two files? thanks

RussellL6 (author)2017-09-10

Why is it that everytime I try to Connect, the app closes

"The application has stopped."

gokhangocmen (author)2017-06-23

Thank you so much. I send data to my special bluetooth device which is not Arduino+HC05+BTModul. After I send data, I want to read that coming data from my special bluetooth device by changing Baud Rate. How Can I do this?

Ryz3D (author)2017-01-13

Thank you SO MUCH! You helped out a lot with your code, I didn't know the UUID so just one adjustment did the job. By the way, how did you even find out the UUID? ^^

MarkKl (author)2016-12-28

Hi,

Thanks for you great post!

I am trying to get it running but is get the error "CS0103 - The name 'Rasource' does not exist in the current context".

I do not understand why this is happeping, can you help?

Mark

MarkKl (author)MarkKl2016-12-28

Sorry for the typo "Rasource" must be "Resource". The first occurence is on line 29 see below:

SetContentView(Resource.Layout.Main);

ErikaC35 (author)2016-10-09

Thanks for the tutorial, it's really simple and useful! But now I need something to receive data from arduino, can you recommend me something, please?

maole_95 (author)ErikaC352016-10-16

Yes, the HC-05 / 06 is a Transceiver. That means, that you can also transmit data. Google something like "HC-05 Arduino transmitting"

regards

MuradB1 (author)2016-03-11

I have led in 5,6,9 pins but if i write in code 5,6,9 program don't work i connect to the bluetooth modul hc05 and next i click the buttons but bluetooth module don't turn on the leds

maole_95 (author)MuradB12016-09-27

Does your HC-05 give any Signals? Try to measure some stuff with a simple Serialmonitor-Loop.

regards

fatdox (author)2016-07-19

I get a NullReferenceExection while debugging the App on my Nexus5 at the line _socket = MyConnection.thisDevice.Create[...]
Any help to get this work for me would be realy great!
Thanks a Lot!

maole_95 (author)fatdox2016-09-27

Sorry for the late reply. It seems like there is an error while creating the Device. This could happen, when your device was not found in Bluetooth Discovery. is Your Bluetooth enabled?

fatdox (author)fatdox2016-07-19

I also used HC-06

About This Instructable

7,195views

8favorites

More by maole_95:~10-15kV Tazer / High Voltage Multiplier3-LED Backlight: Xamarin and Arduino with HC05ESC Programming on Arduino (Hobbyking ESC)
Add instructable to: