Hey guys.
I'm new here and new to using an Arduino.
Basically all I'm looking to do is to be able to control the pin out puts of my arduino using my android phone using the OTG cable (serial usb).
I've modified a sketch that i found online and i believe it will work, however, i do not know how to code an app to do what i want it to do. I have tried MIT App inventor but it does not seem to allow communication
over a serial link, only bluetooth and i am unsure of how to use android studio or eclipse.
My project is a simple 4 channel relay. If anyone can help or knows of an app which already exist, i would be greatful.
Thank you.
Here is the sketch that I'm using :
int ledpin[6] = {2,4,6,8,10,12};
int ledstate[] = {3,5,7,9,11,13};
String rx="";
byte b = 0;
char c = 'a';
boolean rx_done = false;
void setup(){
pinMode(2,OUTPUT);
pinMode(4,OUTPUT);
pinMode(6,OUTPUT);
pinMode(8,OUTPUT);
pinMode(10,OUTPUT);
pinMode(12,OUTPUT);
pinMode(3,INPUT);
pinMode(5,INPUT);
pinMode(7,INPUT);
pinMode(9,INPUT);
pinMode(11,INPUT);
pinMode(13,INPUT);
Serial.begin(9600);
}
void loop(){
while(Serial.available()){
char c = (char) Serial.read();
rx += c;
delay(2);
}
if(rx != ""){
int pin_number = rx.charAt(0)-48;
//int pin_state = rx.charAt(1)-48;
if(pin_number > 5){
//Serial.println("false");
}
else{
int new_state;
if(digitalRead(ledpin[pin_number]) == HIGH){
new_state = 0;
digitalWrite(ledpin[pin_number],new_state);
} else {
new_state = 1;
digitalWrite(ledpin[pin_number],new_state);
}
String s = rx+new_state;
Serial.print(s);
}
rx ="";
}
delay(1000);
}