React Native Smart Switch App – Arduino – Part 2

This is second part of React Native Smart Switch App – Arduino tutorial series. You can check the first part of tutorial here . In the first part we create an app to turn bluetooth on and off and also detect the paired bluetooth devices. In this part of tutorial we will take things further and establish connection with bluetooth device and app. Also, send signal to control the device.

Lets first create bluetooth gadget that we will control with our app. Following are the things we will need to create a simple bluetooth gadget :

1) Arduino Uno board

2) USB cable

3) 6 male to male jumper cables

4) one 220ohm resistor

5) one LED light

6) breadboard (400 tie-point)

7) Bluetooth Module (HC-05/HM-10)

Now connect the 5v and ground of Arduino with 5v and ground of bluetooth module. Connect RX and TX of Aurdino with TX and RX of Bluetooth module respectively. Connect ground of Arduino with  anode of LED  and pin 13 of Aurdino with one side of 220 ohm resistor. Connect the other side of resistor with cathode of LED.

Now disconnect the RX and TX jumper cable from Arduino and upload the following code to it.

Now reconnect the jumper cables back as it was.

In the above code, we have set pin 13 as output pin so that it glows the LED when we send signal for it. We have set the speed of (bluetooth) communication to 9600 baud (bits per second). In the loop we first check if some data is available and read the data. On every transmission of data (i.e. ‘T’) we just toggle the state of the output pin.

Now modify the React Native App code so that it is like the code below :

In the above code, we are turning bluetooth on and off on tapping of Switch control. When bluetooth is tuned on it detects the nearby visible bluetooth devices. Once we find our device in the list, we tap on it and establish connection. Now when we tap the Switch button it turns LED on and if we tap again LED is turned off.

Video Tutorial