Assignment 16
write an application that interfaces with an input &/or output device that you made
What I did in this assignment was to Connect my phone using an application with Appinventor2 and Bluetooth to turn-on the led of my board.
When you click on the start button the application on the phone the led turns on.
I designed previously (Assignment 6) a board with bluetooth and with a LED.
Step 1--> Set my Arduino as a programmer
1. Open File --> Examples --> ARduino ISP
2. TOOLS -->BOARD --> ARDUINO
3. TOOLS --> PORT --> ARDUINO/GENUINO UNO
4. TOOLS --> PORT --> PROGRAMER --> AVRISP MKLL
THEN UPLOAD IT
STEP 2. PROGRAM MY BOARD WITH THE ARDUINO THROUGH THE ISP
1. CONNECT THE ISP;
i.e: MISO with MISO, Vcc with Vcc, MOSI with MOSI, SCK with SCK , GND with GND and the RST of my circuit with PIN 10.
2. Program in AppInventor2
GO TO : http://ai2.appinventor.mit.edu and start your application.
For my application:
a. Add 4 Buttons : 2 to connect and disconnect, and 2 to start and end the program. The idea is that when you click "Start" the led is going to turn on and when you click "End" the led will turn off. Each button has its function:
Button 3-- > Connect to the Bluetooth with the led
Button 4--> Disconnect from Bluetooth
Button 1--> It's the button that will turn on the LED
Button 2 -->It's the button that will turn off the LED
b. Add BluetoothClient and BluetoothServer from
the option of Connectivity (left-hand side of the tool
bar).
BLUETOOTHCLIENT: It is the way we are going to
be able to connect to the server.
BLUETOOTHSERVER: Is in case our device (like a
button will send a signal and this will allow us to
receive the information).
Note: everything you add (for example, buttons)
comes from the left hand side OPTIONS shown
on the application
c. Go to Blocks:
In this section will be programming each one of the buttons:
We use the command: When --- Do:
For Button 3: when Button3.click we call Bluetoothclient1 to connect to the bluetooth address: 98:D3:31:20:7A:D0
For Button 4: when Button4.click we call Bluetoothclien1 to disconnect and close the application.
For Button 1: when Button1.click we call the Bluetoothclient1 to send the number 1 and change the background color to yellow
For Button 2: when Button2.click we call the Bluetoothclient1 to sent the number 0 and then change the background color of the application to black.
d. Go back to the "Designer" section and up in the left-hand side go to Build --> Provide QR Code
This will provide you with the QR code as seen on the top.
e. Open the application in your phone: You Open Lector Optico in the phone, and you take a picture and then the application opens.
- > go to url
It will download the application.
Then you have to install the application.
3. Write the program for the Attiny --> This program is really simple. I used the library "SoftwareSerial.h" The variable "dato" will save whatever the application is sending. The application sends either: 1 or 0. If the application sends 1 then the led will turn on and if the application sends 0 then the led will turn off.
********************************************************************************************************************************************************
#include <SoftwareSerial.h>
int dato = 0;
int led=8;
SoftwareSerial mySerial(11, 10);// RX, TX
void setup()
{
// Open serial communications and wait for port to open:
mySerial.begin(9600);
pinMode(led, OUTPUT);
}
void loop() { // run over and over
if (mySerial.available() > 0)
{
dato = mySerial.read();
}
if (dato == 1)
{
digitalWrite(led, 1);
}
if (dato == 0)
{
digitalWrite(led, 0);
}
}
**********************************************************************************************************************************************
4. Upload the program in the Attiny
(The ISP of the Attiny and the Arduino are already connected)
Put the correct settings:
b. Tools --> Board --> ATiny
c. Tools --> Processor ->Attiny84
d. Tools --->Clock --> 1Mhz
e. Port --> COM9/ARDUINO/GENUINO/UNO
d. Tools -->Programmer -->Arduino as ISP
And upload the program.
5. CONNECT THE BLUETOOTH
Connect the Tx of the External Bluetooth with the Rx of the Bluetooth in the board.
Connect the Rx of the External Bluetooth with the Tx of the Bluetooth in the board.
Connect the VCC and GND with the one in the arduino and the same with the board.
6. Open the application in your phone and start playing :) ( I couldn't document this part with a picture because I only had the camera of my phone)
External bluetooth