Norton University joined Malaysia International Robot Competition (MIRoC) 2014
1. Home made PCB by the method of screen printing
ទស្សនាវដ្ដីអេឡិចត្រូនិចកម្ពុជា - 8 Awesome Videos Tips And Guides on PCB Design!
only works with AppInventor version 1.0 or also called classic that you can see here http://appinventor.mit.edu/explore/classic.html Click
the button: “Invent your own Apps now” . This project still works just
fine with my app and with my Arduino code. But you can only edit the
source code on Appinventor classic version. I’ll try to update the
source code in the next 4 weeks or something. I’m currently working on
another projects that I need to finish right away.
In this tutorial I’ll show you how you can control 2 DC motors via bluetooth with my brand new Android app.
It’s called “BlueArd” and It’s the 1.0 version. I want to upgrade my app later and add more features.
This app was created with MIT App Inventor. It’s a great place to start with android development.
If you remember my previous tutorial (Click here to see that project) where I was controlling 1 DC motor, I was using an app called “BlueTerm“. That app did the job but I didn’t like the design that much. So I’ve decided to make my own.
It’s my very first app and It’s working for me but I’m not sure if this will work for everyone.
If you want to make some improvements to my app, feel free to do that. But please contact me here! I’ll be glad to hear what you changed in my app.
Let’s take a look to “BlueArd“:
ទស្សនាវដ្ដីអេឡិចត្រូនិចកម្ពុជា - Arduino – Control 2 DC Motors Via Bluetooth
This is a simple project. It uses an Android device to switch an LED
driven by the Arduino. Connectivity is provided by the Bluetooth module
inserted in the breadboard. But one look at the UI on the Android device
and you might think this is anything but simple. The truth is that [Kerimil] didn’t spend forever learning Java and programming the app. Instead he’s showing off the power of App Inventor to get your Android controls up and running fast.
Check out the third button down; when was the last time you added
voice commands to your project? It’s worth clicking through to see just
how simple that portion was. App Inventor
— a Google cast-out that is now maintained by MIT — is a graphical tool
that unlocks the power of an Android handset to those with the most
basic of programming understanding. For instance, the voice controls
shown off after the break are provided by a single bracket which uses
conditional statements to ‘listen’ for the words on, off, and blink.
You’ll find the voice recognition diagram after the break as well.
.
1. Android Mobile
2. Bluetooth Module
3. Arduino ces-eshop
4. LED
/***********************
Bluetooth switch arduino
***********************/
int state = 0;
int incomingByte;
void setup() {
//set pin 12 to output mode
pinMode(12, OUTPUT);
Serial.begin(9600);
}
void loop() {
// see if there's incoming serial data:
if (Serial.available() > 0) {
// read the oldest byte in the serial buffer:
incomingByte = Serial.read();
// depending on the incoming byte do the needful action
if (incomingByte == '1') {
digitalWrite(12, HIGH);
delay(500);
Serial.println("ON");
state=1;
}
else if (incomingByte =='2') {
digitalWrite(12, LOW);
delay(500);
Serial.println("OFF");
state = 0;
}
}
if(state)
Serial.println("ON");
else
Serial.println("OFF");
delay(250);
}
When pairing with the Bluetooth device (linvor) from Android it might ask a password which is generally ’1234′.
package Android.Arduino.Bluetooth;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.EditText;
import android.widget.Button;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Set;
import java.util.UUID;
public class BluetoothTest extends Activity
{
TextView myLabel;
EditText myTextbox;
BluetoothAdapter mBluetoothAdapter;
BluetoothSocket mmSocket;
BluetoothDevice mmDevice;
OutputStream mmOutputStream;
InputStream mmInputStream;
Thread workerThread;
byte[] readBuffer;
int readBufferPosition;
int counter;
volatile boolean stopWorker;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button openButton = (Button)findViewById(R.id.open);
// Button sendButton = (Button)findViewById(R.id.send);
Button closeButton = (Button)findViewById(R.id.close);
Button onButton = (Button)findViewById(R.id.onButton);
Button offButton = (Button)findViewById(R.id.offButton);
myLabel = (TextView)findViewById(R.id.label);
// myTextbox = (EditText)findViewById(R.id.entry);
//Open Button
openButton.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
try
{
findBT();
openBT();
}
catch (IOException ex) { }
}
});
//Send Button
/*sendButton.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
try
{
sendData();
}
catch (IOException ex) { }
}
});*/
//ON SWITCH
onButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
try {
onButton();
} catch (Exception e) {
// TODO: handle exception
}
}
});
//OFF SWITCH
offButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
try {
offButton();
} catch (Exception e) {
// TODO: handle exception
}
}
});
//Close button
closeButton.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
try
{
closeBT();
}
catch (IOException ex) { }
}
});
}
void findBT()
{
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if(mBluetoothAdapter == null)
{
myLabel.setText("No bluetooth adapter available");
}
if(!mBluetoothAdapter.isEnabled())
{
Intent enableBluetooth = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBluetooth, 0);
}
Set pairedDevices = mBluetoothAdapter.getBondedDevices();
if(pairedDevices.size() > 0)
{
for(BluetoothDevice device : pairedDevices)
{
if(device.getName().equals("linvor")) //this name have to be replaced with your bluetooth device name
{
mmDevice = device;
Log.v("ArduinoBT", "findBT found device named " + mmDevice.getName());
Log.v("ArduinoBT", "device address is " + mmDevice.getAddress());
break;
}
}
}
myLabel.setText("Bluetooth Device Found");
}
void openBT() throws IOException
{
UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb"); //Standard SerialPortService ID
mmSocket = mmDevice.createRfcommSocketToServiceRecord(uuid);
mmSocket.connect();
mmOutputStream = mmSocket.getOutputStream();
mmInputStream = mmSocket.getInputStream();
beginListenForData();
myLabel.setText("Bluetooth Opened");
}
void beginListenForData()
{
final Handler handler = new Handler();
final byte delimiter = 10; //This is the ASCII code for a newline character
stopWorker = false;
readBufferPosition = 0;
readBuffer = new byte[1024];
workerThread = new Thread(new Runnable()
{
public void run()
{
while(!Thread.currentThread().isInterrupted() && !stopWorker)
{
try
{
int bytesAvailable = mmInputStream.available();
if(bytesAvailable > 0)
{
byte[] packetBytes = new byte[bytesAvailable];
mmInputStream.read(packetBytes);
for(int i=0;i{
byte b = packetBytes[i];
if(b == delimiter)
{
byte[] encodedBytes = new byte[readBufferPosition];
System.arraycopy(readBuffer, 0, encodedBytes, 0, encodedBytes.length);
final String data = new String(encodedBytes, "US-ASCII");
readBufferPosition = 0;
handler.post(new Runnable()
{
public void run()
{
myLabel.setText(data);
}
});
}
else
{
readBuffer[readBufferPosition++] = b;
}
}
}
}
catch (IOException ex)
{
stopWorker = true;
}
}
}
});
workerThread.start();
}
void sendData() throws IOException
{
String msg = myTextbox.getText().toString();
msg += "";
//mmOutputStream.write(msg.getBytes());
//mmOutputStream.write(msg.getBytes());
//mmOutputStream.flush();
//mmOutputStream.close();
//mmSocket.close();
myLabel.setText("Data Sent"+msg);
}
void onButton() throws IOException
{
mmOutputStream.write("1".getBytes());
}
void offButton() throws IOException
{
mmOutputStream.write("2".getBytes());
}
void closeBT() throws IOException
{
stopWorker = true;
mmOutputStream.close();
mmInputStream.close();
mmSocket.close();
myLabel.setText("Bluetooth Closed");
}
}
Send messages with PIC microcontroller: