Go Down

Topic: arduino board and andriod phone interfacing (Read 990 times) previous topic - next topic

AhmadZaim13

Hi guys,

I am working on project where I am using an arduino mega and a bluetooth module to send a simple text to the andriod phone. I can build the program but I cant get to send the signal over to the phone.  The program structure is such , Once the led is high , the buzzer goes on and the signal is sent out to the HTC phone. Can somebody with a kind soul please help me with my program below.

best regards
nash


#include <MeetAndroid.h>

MeetAndroid meetAndroid;

int buzzer = 48;                                 // Buzzer connected to digital pin 48
int ledPin = 50;                              // the number of the LED pin 50

// variables will change:
int ledState = 0;                                 // variable for reading the led status


void setup()
{
pinMode(ledPin,INPUT);                              // pin 13 led as OUTPUT
pinMode(buzzer, OUTPUT);                         // pin 48 buzzer as OUTPUT
Serial.begin(115200);                           // start serial communication at 115200bps
                       

}

void loop()
{
 ledState = digitalRead(ledPin);

if( ledState == HIGH  )                            // if 'HIGH' was received
{
  digitalWrite(buzzer, HIGH);                // turn ON the buzzer
  delay(1000);
  Serial.print("Door is opened\r\n");         // print the message when the Mega received input from Serial1
  delay(5000);  // delay 5 seconds
  meetAndroid.receive();                   // read input pin and send result to Android
  meetAndroid.send(digitalRead(ledPin));   // add a little delay otherwise the phone is pretty busy
delay(1000);
}
else
{
  digitalWrite(buzzer, LOW);            // otherwise turn it OFF
   delay(1000);                         // wait 1000ms for next reading

}

}

PaulS

Code: [Select]
int ledPin = 50;      // the number of the LED pin 50
pinMode(ledPin,INPUT);    // pin 13 led as OUTPUT

The first comment is useless. Anybody with 3 gray cells can see that you are setting the pin to 50. The 2nd comment is completely wrong.

Code: [Select]
ledState = digitalRead(ledPin);
You want to read whether an LED is on or off? Since the pin is set as input, you can't have turned the pin on. Since LEDs don't source current (or enough to turn a pin on), this is rather a silly thing to do.

Of course, since the LED is never on, the code to talk to the android is never executed.

Go Up