Using android phone to control remote dimmer

TKHouse:

011345687:
i tried to directly wire up from arduino to RS-232 ( yea seriously). and I try to write a program.

i tested this program and i watched the status from the serial monitor, it kept print the value 2FF000D repeatedly
while i send 1 to the monitor, it changed the value to 2FF400D but still repeatedly
and i tried to send another num to monitor, it stopped.

how come the value keep looping, how can i send hex once only?

however i tried the above step after i connected between TX,RX and GND of arduino board and 232port 2,3,5 pin.
i sent 1 out , i could see the monitor that showed the hex of 2FF400D, but the remote dimmer didnt turn on.
what's the problem here?

Reference the serial.available() function: http://www.arduino.cc/en/Serial/Available .

Serial.available() returns the number of data bytes available. In your code the statement

 if (Serial.available () == 0)

means that every time there are 0 bytes available to read,

Serial.print ( dimmerOFF,HEX);

will be executed.

What you want to do is test for when Serial.available() > 0 and then read the byte from serial. You can then have an if statement, or switch statement to determine what should happen when a given byte is received.

ok, i have just tested with a very simple program
the code are as following:

unsigned long dimmerON = 0x02ff400d;

void setup()
{
Serial.begin(9600);
}

void loop()
{
if (Serial.available() >0)
{
Serial.print(dimmerON,HEX);
delay(5000);
}
}

the program is just to test if i can send hex number through serial communication
if it is work, i think the lighting dimmer could turn on by the hex number.
but it doesnt work.
in the above program.
do i really send a hex number out through serial port?