Skip to content

14. Networking and communications

Assignments for the week

Group assignments

  • Send a message between two projects (assignments made by different students)

Individual assignment

  • design, build, and connect wired or wireless node(s) with network or bus addresses.

Requirements

  • Described your project using words/images/diagrams/schematic screenshots.
  • Explained the programming process/es you used.
  • Outlined problems and how you fixed them.
  • Included design files (or linked to where they are located) and original code.

Group assignments

See 2019 Fablab Taipei Group site Week 14

Individual assignment

Connect board via Bluetooth (BLE)

HC-05 module

Datasheet of HC-05 module

HC-05 is a Bluetooth module that can be master or slave by software setting.
HC-06 can only be slave but and less setting options.
It works like a serial without cable.

Set up HC-05 by arduino and arduino IDE

  1. Upload program to arduino.

    /*
    AUTHOR: Hazim Bitar (techbitar)
    DATE: Aug 29, 2013
    LICENSE: Public domain (use at your own risk)
    CONTACT: techbitar at gmail dot com (techbitar.com)
    */
    #include  <SoftwareSerial.h>
    SoftwareSerial BTSerial(10, 11); // RX | TX
    void setup()
    {
    Serial.begin(9600);
    Serial.println("Enter AT commands:");
    BTSerial.begin(38400);  // HC-05 default speed in AT command more
    }
    void loop()
    {
    // Keep reading from HC-05 and send to Arduino Serial Monitor
    if (BTSerial.available())
    Serial.write(BTSerial.read());
    // Keep reading from Arduino Serial Monitor and send to HC-05
    if (Serial.available())
    BTSerial.write(Serial.read());
    }
    
  2. Wiring (Remove USB cable first).

    Arduino Nano HC-05
    5V or 3.3 V VCC
    GND GND
    10 TXD
    11 RXD
  3. Press button while links to Arduino.
    Remove HC-05 side of wire,
    links Arduino to conputer.
    Press button on HC-05 while connect HC-05 with Arduino.
    This button allow It into setting mode (AT mode).
    It will blink at ~1 sec. rate if sussesful enter AT mode.

  4. Open Serial port monitor.

    Choose NL&CR mode and 9600 baud.
    Send AT, It will return “OK” if all step works.
    Send AT+NAME=testws to setup the name of BLE device.
    Send AT+UART=38400,0,0 to setup the baud of wireless rate (to fit terminal baud on phone).
    Send AT+PSWD="1234" to set passwords to 1234.(Yes, It’s a bad password.)

  5. Install a bluetooth terminal for phone.

    here is link to Serial Bluetooth Terminal

    Test for two-way communication.

operate with Arduino.

Using Arduino to test if HC-05 works.

Testing Code (Same as the HC-05 setting code).

/*
AUTHOR: Hazim Bitar (techbitar)
DATE: Aug 29, 2013
LICENSE: Public domain (use at your own risk)
CONTACT: techbitar at gmail dot com (techbitar.com)
*/
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(10, 11); // RX | TX
void setup()
{
  Serial.begin(9600);
  Serial.println("Enter AT commands:");
  BTSerial.begin(38400);  // HC-05 default speed in AT command more
}
void loop()
{
  // Keep reading from HC-05 and send to Arduino Serial Monitor
  if (BTSerial.available())
    Serial.write(BTSerial.read());
  // Keep reading from Arduino Serial Monitor and send to HC-05
  if (Serial.available())
    BTSerial.write(Serial.read());
}

BOM

Parts Spec. Quantity
ATtiny 44a - 1
Capacitor 105 (1uF) 1
18 pF 2
Crystal 20.0 M hz 1
HC-05 module - 1
Led - 1
Pin header 1x6 1
1x4 1
2x3 2
Resistor 10k ohm 1
1k ohm 1
o ohm 1

Make own board.

Design by Eagle.

Code for the board.

Because of the Attiny44a will read wrong message if too many “if loop” in code,
the power button of UI does not have its code.

/* Write by Weng, Wei-Sung at Fablab Taipei for fab academy 2019
 * CC BY-NC 4.0 licence 
 * Acknowledgement: 
 * Devon Hsin (Maker Xin @ Facebook) - helps for debug.
 * Hazim Bitar - Bluetooth communication.
 * Tom Igoe - Serial Event example.
 */


#include <SoftwareSerial.h>
SoftwareSerial BTSerial(1, 0); // RX | TX
char sense = 1;

void setup()
{
  BTSerial.begin(38400);
  pinMode(2, INPUT);
  pinMode(3, OUTPUT);
}

void loop()
{
  // lights up if motion detector works
  if ((char)sense == '1') {
    if (digitalRead(2) == HIGH) {
      digitalWrite(3,HIGH);
      }
      else {
        digitalWrite(3,LOW);
      }
    }
    else {
      digitalWrite(3,HIGH);
    }
  // Bluetooth control
  if (BTSerial.available()){
    char data= (char) BTSerial.read();
    if ( data == 'c'){
      sense = '1';
    }
    else if (data == 'd'){
      sense = '0';
    }
  }
}

Make and programing it.

Test the bord.

Datasheet of HC-05 module
Serial Bluetooth Terminal
board traces
board interior