STEP #10-1 : bluetooth receiver (HC-06) tests (1)

arduino4fun
Site Admin
Posts: 37
Joined: Mon Jun 06, 2016 1:16 pm

STEP #10-1 : bluetooth receiver (HC-06) tests (1)

Postby arduino4fun » Thu Jun 09, 2016 9:51 am

Bluetooth receiver (HC-06) tests (banggood SKU103805) :

TIPS : the bluetooth module MUST BE deconnected before uploading the sketch, the uploader uses the serial port to upload which is in conflict with the BT module : 1) un-plug the red wire (+) of the BT module, 2) upload the sketch, 3) re-plug the BT module

Code: Select all

// ----------------------------------------------------------------------------------------------
 // This sketch allows to check the bluetooth shield HC-06
 //
 // https://www.facebook.com/arduino4fun
 // http://www.arduino4fun.com
 // ----------------------------------------------------------------------------------------------

‪#‎include‬ <Wire.h>

String buffer; // buffer containing the message receibed
 char blueToothVal; //
 char laststate; // last state

int ledpin1=13; // Define the digital interface signal line 13 is connected to the red LED
 int ledpin2=12; // Define the digital interface signal line 12 is connected to the green LED

void setup()
 {
 Serial.begin(9600); //set baud rate
 pinMode(ledpin1,OUTPUT);
 pinMode(ledpin2,OUTPUT);
 digitalWrite(ledpin1, LOW); // Turn off the red LED
 digitalWrite(ledpin2, LOW); // Turn off the green LED
 }

void loop()
 {
 // return;
 char val = Serial.read();
 if (val != -1)
 {
 if (val == 'a')
 {
 digitalWrite(ledpin1, HIGH); // Turn on the red LED
 Serial.println( "Red led is ON" );
 }
 else if (val == 'b')
 {
 digitalWrite(ledpin1, LOW); // Turn off the red LED
 Serial.println( "Red led is OFF" );
 }
 else if (val == 'c')
 {
 digitalWrite(ledpin2, HIGH); // Turn on the green LED
 Serial.println( "Green led is ON" );
 }
 else if (val == 'd')
 {
 digitalWrite(ledpin2, LOW); // Turn off the green LED
 Serial.println( "Green led is OFF" );
 }
 else
 Serial.write(val);
 }
 else
 {
 //stop();
 //delay(500);
 }
 }
 


Image
Image

Return to “Multifunction Bluetooth Controlled Robot Smart Car Kits For Arduino”

Who is online

Users browsing this forum: No registered users and 1 guest