Interface and application programs

This week have to write an application that interfaces with an input &/or output device that you made, comparing as many tool options as possible

Idea

I have decided to make an app to control motor dc. The idea is to develop a control remote via bluetooth. So the hardware implementation requires a fabduino, bluetooth module HC-05, H-bridge and motor DC. The android app will connect to HC-05, so when we press the button, it sent a message which is listened by fabduino. The H-brdige is able and not able when the correct message.

The bluetooth module HC-05 should connect TX and RX to pins on fabduino. Additionally, we must connect state pin in fabduino, which is HIGH when some devices connecting with it. In the right image we can see the final hardware implementation. The H-bridge has designed for this assigment based on output devices of Gonzalo Siu . You can download the eagle file.

Arduino source code

This souce code has the program to upload in fabduino. We used the library SoftwareSerial to simulate serial communication because the original serial ports were using by the Arduino program. Status bluetooth pin and H-bridge pins were setting as INPUT and OUTPUT. In setup function details configuration for each pin and connection between fabduino and bluetooth. The baup rate for each Serial communication were 9600.

#include <SoftwareSerial.h>
//arduino >> bluetooth
//D2 >> Rx
//D3 >> TX
byte BTPin = 7;
bool bconnect = false;
bool flag = true;
char c;

SoftwareSerial blue(2,3); //Rx, Tx
void setup() {
  // put your setup code here, to run once:
  pinMode(BTPin, INPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);

Serial.begin(9600);
Serial.println("Fabduino is ready");
Serial.println("Connect the HC-05 to device");

while(!bconnect)
{
  if(digitalRead(BTPin)==HIGH)
  {
    bconnect = true;
  }
}
Serial.println("HC-05 is now connected");
blue.begin(9600);

}

void loop() {
  // put your main code here, to run repeatedly:
  if(blue.available()){
    c = blue.read();
    if(c == 'A')
    {
      if(flag)
      	{
	Serial.println("turn on motor");
	digitalWrite(5, HIGH);
	digitalWrite(6, LOW);
	flag = !flag;
	}
      else{

	Serial.println("turn off motor");
	digitalWrite(5, LOW);
	digitalWrite(6, LOW);
	flag = !flag;
	}
    }

  }
  if(Serial.available())
  {
    c = Serial.read();
    blue.write(c);
  }

}

Android source code

We follow the tutorial to create android app with HC-05. This tutorial has some importants keys as UUID to connect without pass, list favorite devices and an activity lunch after selecting the correct device. We add a function and our GUI which has image button. When you press it changes the icon to on or off, and send a message through bluetooth. The app has two activities, the first one connects with the correct device and other activity to operate via bluetooth. You can donwload source code here

Finally, we did it!!!