Hello and thank you in advance for any help you may be able to give me.
I want to connect a simple switch to a serial port so that read the com port and determine the state of the switch.
Ultimately I want to connect the switch to a serial port on a bluetooth module and send a character to indicate that the switch is closed (at some reasonable sample rate, say 1hz or less). Because I am going to use a serial port over bluetooth, I think I need to actually use the TX/RX pins.
If someone could point me in the right direction it would be very helpful
if you can use the port in bidirectional mode, then sending a byte will cause the port to receive a byte (with the switch closed), and you would put the switch between pins 2 and 3.
or you could put the switch between pins 7 and 8. tell the port to assert RTS, and read the status of CTS
in any case, make sure you clear any leftover data in the port buffer before doing each write/read operation
Some time back I wrote a small program for looking at the RS232 serial port. A screen shot is attached to this post. The Comm Port has 5 lines that can be used as simple digital in / out lines. The little program can be downloaded from here. The program downloads as a zip folder. Just extract the contents and open the folder. Double click the .exe file to install the program. When you are done with it it can be removed.
The two output lines on a RS232 port are the DTR and RTS lines, pins 4 and 7 respectively. Clicking the check boxes will cause those pins to swing from the default low to a high status. Jumping either of those pins when high through a switch to pins 1, 6, or 8 will result in you watching the input pin status change. Additionally placing a logic high (I used 5 volts) between pin 5 ground and any of those pins will result in the input pin showing a logic high.
Feel free to download the program and play around with it. Any questions, just ask. You may want to note that this in part runs with the suggestion(s) of unclejed613's post.