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
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.
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); } }