Firstly, there are three different functions to write out serial data:serial.print(), serial.println()
, and serial.write()
Looking at the reference for serial.print()
, what actually happens is that the data is sent to the serial port in a human-readable format, but in the format specified by the second parameter.
So the number 65 sent with serial.print(65, HEX)
would write 0x41 (65 in HEX) to the serial port, but using human readable characters. So in actuality, the binary values 0x34 and 0x31 would be sent (producing ASCII characters '4' and '1' on the serial monitor). This function is primarily intended to make monitoring and debugging easier, while not being what you need in your case.
So in your case, Serial.print(dimmerON,HEX)
is actually writing the following bytes to the serial port:
You need to use the serial.write()
that will actually write the binary value for 0x02ff400d to the serial port. You will probably want to use the method using an array of bytes.
Secondly, it will likely not be quite that simple. RS-232 has more to its protocol than simply writing serial data on the lines. I am not certain, but it does not appear that you are using any type of RS-232 driver chip. I've never implemented anything using RS-232, so I'm definitely not experienced in working with it.
There is an Arduino Software RS-232 tutorial: http://www.arduino.cc/en/Tutorial/ArduinoSoftwareRS232
There are also Arduino RS-232 shields available.
Either the software version with a driver chip, or the shield version are probably your best options. If you're working on an UNO, the shield will probably use the available serial port, so if you'll be reprogramming a lot it might be in your interest to look at the version using software serial.