Wiring schematic

Simple Bluetooth serial communications for your Arduino. Pair with your Mac, Linux, or Windows computer to send and receive messages using regular Serial.print() commands. [Product page]
CAMS2908
Posts: 9
Joined: Thu Jan 01, 2015 8:39 pm

Wiring schematic

Post by CAMS2908 » Tue Jan 20, 2015 5:24 am

Hi
I have been able to create a android app using MIT and connect it to the freetronics bluetooth shield, I know that it is connected and the link light is on. However, I have been trying to get the app to turn a led on and off but can not seem to get it to do it. I have checked online and everyone seems to have the HC-05 module with it wired different to anything I've done. Would I be able to get a wiring schematic that would do that and maybe a sketch for it. As the one I'm using is not working..... (using Neil Kenyon's sketch at the moment to no avail)

Code: Select all

int ledPin = 13;
String readString;

void setup()
{
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
}
void loop()
{
  while ( Serial.available() )
{    // While there is data in the buffer
    delay( 3 ); 
    char c = Serial.read();
    readString += c;         // build the string - “on” or “off”
}
  if ( readString.length() >0 )
   {
    Serial.println( readString );
    if ( readString == "on" )
     {
      digitalWrite( ledPin, HIGH) ;
      }
    if ( readString == "off" )
     {
      digitalWrite( ledPin, LOW );
      }
    readString="";
   }
}

andrew
Freetronics Staff
Freetronics Staff
Posts: 978
Joined: Sun Jul 14, 2013 7:06 am
Location: Melbourne, Australia
Contact:

Re: Wiring schematic

Post by andrew » Tue Jan 20, 2015 6:45 am

You can't use Serial.print() if you're using pins D0 and D1 for TX/RX as your sketch appears to do.
As per the shield quickstart guide, let's use software serial for your example.

Fit the jumpers as per the guide:
http://www.freetronics.com.au/pages/blu ... tart-guide

then try the following sketch:

Code: Select all

    #include <SoftwareSerial.h>

    int ledPin = 13;
    String readString;
    SoftwareSerial BT(2,3); // RX, TX
      
    void setup()
    {
      Serial.begin(9600);
      BT.begin(9600);
      pinMode(ledPin, OUTPUT);
    }
    void loop()
    {
      while ( BT.available() )
    {    // While there is data in the buffer
        delay( 3 );
        char c = BT.read();
        readString += c;         // build the string - “on” or “off”
    }
      if ( readString.length() >0 )
       {
        Serial.println( readString );
        if ( readString == "on" )
         {
          digitalWrite( ledPin, HIGH) ;
          }
        if ( readString == "off" )
         {
          digitalWrite( ledPin, LOW );
          }
        readString="";
       }
    }


CAMS2908
Posts: 9
Joined: Thu Jan 01, 2015 8:39 pm

Re: Wiring schematic

Post by CAMS2908 » Tue Jan 20, 2015 8:57 am

Thank you, It is now lighting up the D13 light on eleven R3 however the led is till not turning on. I followed the MIT app inventor instructions to construct the app so I don't think its is on that end, but think it is down to the wiring, I have simply constructed the project 1 in Freetronics project guide with jumper leads attaching to D13 and GND but am getting no where. Thanks so much for your help :)

andrew
Freetronics Staff
Freetronics Staff
Posts: 978
Joined: Sun Jul 14, 2013 7:06 am
Location: Melbourne, Australia
Contact:

Re: Wiring schematic

Post by andrew » Tue Jan 20, 2015 10:52 am

CAMS2908 wrote:Thank you, It is now lighting up the D13 light on eleven R3 however the led is till not turning on. I followed the MIT app inventor instructions to construct the app so I don't think its is on that end, but think it is down to the wiring, I have simply constructed the project 1 in Freetronics project guide with jumper leads attaching to D13 and GND but am getting no where. Thanks so much for your help :)
OK, let's try the simplest possible sketch. Ensure the TX jumper on the BT shield is set to 2 and RX to 3. Also, change the Android app so when you press ON it just sends the letter A and B for off. Finally, remove the LED hardware, this will use the onboard D13 LED.

Code: Select all

#include <SoftwareSerial.h>
SoftwareSerial BT(2, 3);

// creates a "virtual" serial port/UART
// connect BT module TX to D2
// connect BT module RX to D3

void setup()
{
  // set digital pin to control as an output
  pinMode(13, OUTPUT);
  // set the data rate for the SoftwareSerial port
  BT.begin(9600);
}

char a; // stores incoming character from other device

void loop()
{
  if (BT.available())
    // if text arrived in from BT serial...
  {
    a=(BT.read());
    if (a=='A')
    {
      digitalWrite(13, HIGH);
    }
    if (a=='B')
    {
      digitalWrite(13, LOW);
    }
    // you can add more "if" statements with other characters to add more commands
  }
}


CAMS2908
Posts: 9
Joined: Thu Jan 01, 2015 8:39 pm

Re: Wiring schematic

Post by CAMS2908 » Tue Jan 20, 2015 11:34 am

Thanks, that worked perfectly.
However, am befuddled as to how transfer this into being able to turn LED on and off and eventually serial monitor data from freetronics accelerometer onto an android device, any suggestions/help?

Am still learning the ropes with this but thank you for all your help.

CAMS2908
Posts: 9
Joined: Thu Jan 01, 2015 8:39 pm

Re: Wiring schematic

Post by CAMS2908 » Tue Jan 20, 2015 9:19 pm

Hooray! I got an LED to turn on and off using the bluetooth shield (finally!) Thank you for your help.
However, can I please ask how, and where in the sketch do I add a command to send serial monitor data to (collected from an accelerometer) an android device. Again thank you.

andrew
Freetronics Staff
Freetronics Staff
Posts: 978
Joined: Sun Jul 14, 2013 7:06 am
Location: Melbourne, Australia
Contact:

Re: Wiring schematic

Post by andrew » Tue Jan 20, 2015 9:20 pm

CAMS2908 wrote:Thanks, that worked perfectly.
However, am befuddled as to how transfer this into being able to turn LED on and off and eventually serial monitor data from freetronics accelerometer onto an android device, any suggestions/help?

Am still learning the ropes with this but thank you for all your help.
Sending data from the accelerometer to the Android device is easy, just use the Bluetooth software serial to send whatever data you want out via the BT shield.
An example to show how data is sent is the ASCII table example in the quick start guide:
http://www.freetronics.com.au/pages/blu ... tart-guide
but with accelerometer data instead (etc).

CAMS2908
Posts: 9
Joined: Thu Jan 01, 2015 8:39 pm

Re: Wiring schematic

Post by CAMS2908 » Tue Jan 20, 2015 10:47 pm

johnb wrote:
CAMS2908 wrote:Thanks, that worked perfectly.
However, am befuddled as to how transfer this into being able to turn LED on and off and eventually serial monitor data from freetronics accelerometer onto an android device, any suggestions/help?

Am still learning the ropes with this but thank you for all your help.
Sending data from the accelerometer to the Android device is easy, just use the Bluetooth software serial to send whatever data you want out via the BT shield.
An example to show how data is sent is the ASCII table example in the quick start guide:
http://www.freetronics.com.au/pages/blu ... tart-guide
but with accelerometer data instead (etc).
Sorry you have completely lost me somewhat I have used the tera term software and was able to get data onto a laptop but still not onto android thats the bit thats got me.....

andrew
Freetronics Staff
Freetronics Staff
Posts: 978
Joined: Sun Jul 14, 2013 7:06 am
Location: Melbourne, Australia
Contact:

Re: Wiring schematic

Post by andrew » Tue Jan 20, 2015 11:07 pm

CAMS2908 wrote:
johnb wrote:
CAMS2908 wrote:Thanks, that worked perfectly.
However, am befuddled as to how transfer this into being able to turn LED on and off and eventually serial monitor data from freetronics accelerometer onto an android device, any suggestions/help?

Am still learning the ropes with this but thank you for all your help.
Sending data from the accelerometer to the Android device is easy, just use the Bluetooth software serial to send whatever data you want out via the BT shield.
An example to show how data is sent is the ASCII table example in the quick start guide:
http://www.freetronics.com.au/pages/blu ... tart-guide
but with accelerometer data instead (etc).
Sorry you have completely lost me somewhat I have used the tera term software and was able to get data onto a laptop but still not onto android thats the bit thats got me.....
If you can get data onto the laptop then you're halfway there. Learn how the accelerometer works (see the guide from the product page) - but instead of sending it to the serial monitor you have the sketch send it out to the BT shield (E.g. recall the BT.print functions in the sketch sends data to the shield in the same manner as Serial.print sends it to the serial monitor).

Then you need to work on your Android app. I'm afraid this is outside the scope of our support, however there are many tutorials on this topic, they're linked from the MIT App Inventor site. Plus Google found this for me which is a good start:
https://www.youtube.com/watch?v=xjtxrxVauZg

CAMS2908
Posts: 9
Joined: Thu Jan 01, 2015 8:39 pm

Re: Wiring schematic

Post by CAMS2908 » Tue Jan 20, 2015 11:24 pm

Original sketch looking at getting reads from potentiometer:

Code: Select all

/*   Demonstration sketch to send data to an Android App via Bluetooth - essentially simple; this is just serial output of integer data.
     The Bluetooth module is connected across the Arduino Rx and Tx lines as before.
      A 10k pot is connected across +5v and ground; the slider is connected to analog input 0, to supply varying data.
 
     Neil Kenyon
     15 July 2014
*/
  
int potPin = 0;                                  // Define the Analog input
void setup()
{
  Serial.begin(9600);
  pinMode(potPin, INPUT);
}
void loop()
{
    int value = analogRead(potPin);    // read the value of the Analog Input
    Serial.println(value);                     // Print the value; can also be seen on Serial Monitor
    delay(1000);                                   
 }
Then tried to alter as you described

Code: Select all

#include <SoftwareSerial.h>
SoftwareSerial BT(2, 3);
int potpin = 0;

void setup()
{
  BT.begin(9600);
  pinMode(potpin, INPUT);
}
void loop()
{
  if (BT.available())
  int value = analogRead(potpin);
  delay(1000);
}
but still nothing......

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests