Switching sensor output into serial port

Thread Starter

flyingsock

Joined Oct 21, 2017
16
Hello, guys. How's it going?

In my school prototype I need to detect a box with a sensor, and it's output will be used to trigger the printing of our names into the box.
The signal must go into the school computer via the serial port, as that's where the printer is connected.

Well I'm kind of an impulsive person, so I just bought the sensor before hand without overthinking, which is stupid.
Specs of the sensor: Input voltage: any ranging from 20 to 250V. AC/DC. Output: relay contacts, NO.

I though: 'well, I'll simply get some 120V from the outlet to feed the sensor, then I'll get +5V from the serial port and connect to the NO contact of the sensor and then to an input pin of the serial port, so everytime the sensor detects the box the contact is gonna close (NF) and then the serial port will be receiving 5V into the pin I assigned. Piece of cake'.

Nope. Looks like the serial port is RS232, and not TTL Which changes everything. Tbf, I'm lost.

Am I able to get -13V out from the serial port to connect to the NO contact of the sensor and then to an input pin of the serial port? To make it work just like I thought..?
What would you do? Is it possible? Plan B is getting a +24V PNP sensor from the maintenance, would it be any easier?

After managing to input High and Low signals into my serial port, what's the best workaround software to communicate with the printer connected to the PC? (Yes, sorry)
 

bug13

Joined Feb 13, 2012
1,976
Possibly need more info from you.

Assuming you don't know what a MCU is and, can't write a computer software, here is my solution:

  • Find a way to print whatever you need to print with one mouse click. (You can download some free software to do these sort of things)
  • Connect your sensor output to a relay.
  • Connect your relay N.O. output to a mouse left click button.

When a sensor detect a box, it will trigger the relay, the relay click the left button of the mouse, stuff got print :)
 

Reloadron

Joined Jan 15, 2015
5,991
What would you do? Is it possible? Plan B is getting a +24V PNP sensor from the maintenance, would it be any easier?
No problem is so big and so great it cannot be run away from. I would run and not look back.

Seriously I am not sure what you are actually after here but using a computer to read a RS 232 serial port can be relatively simple with several lines of code. You may want to start by looking at a RS 232 serial port pinout and signal levels. Surprised you are using RS 232 serial port as the computers having them are becoming fewer and fewer. You may want to note that aside from the data lines RX and TX Data there are 3 pins which can be used as digital inputs and two pins which can be used as Digital Outputs. CTS pin 8, DSR pin 6 and DCD pin 1 can all serve as a digital in. You can apply a Logic High to any of those 3 pins and detect it or a Logic Low. There are also two pins, DTR pin 4 and RTS pin 7 which can serve as digital outputs. Pin 5 is Ground. The data pins are Pin 3 Tx Dataq and Pin 2 Rx data. Logic levels are typically 13 Volts and -13 Volts. That is Logic High and Logic Low. I suggest you read about RS 232 communications and logic levels.

Years ago I write a tiny program in VB 6.0 which will monitor a RS 232 port. You can download the little program here. Download the zip folder and open it. Double click on the .exe file to install the program. Between Ground and any of the three digital input pins I mentioned apply a logic level greater than 5 volts you should see the changes. Also you can click the two Digital Out channels and watch them with a voltmeter between the pin and pin 5 ground. Incidentally that little program is over 20 years old and written in VB 6.0.

Now what exactly are you wanting to do?

Ron
 

Thread Starter

flyingsock

Joined Oct 21, 2017
16
Possibly need more info from you.

Assuming you don't know what a MCU is and, can't write a computer software, here is my solution:

  • Find a way to print whatever you need to print with one mouse click. (You can download some free software to do these sort of things)
  • Connect your sensor output to a relay.
  • Connect your relay N.O. output to a mouse left click button.

When a sensor detect a box, it will trigger the relay, the relay click the left button of the mouse, stuff got print :)
sounds evil, I like it.
Not gonna get me the wheelchair I want, though
 

Thread Starter

flyingsock

Joined Oct 21, 2017
16
No problem is so big and so great it cannot be run away from. I would run and not look back.
Ron
Please don't make me run, I wanna learn.
Thanks for providing the download, I'll download it on school's pc tomorrow.

What I wanna do: use silverlight (or similar software) to make DTR pin constantly output -13V (once activated, by you know, a start routine command via hypertherminal/software).
Well I'll then connect DTR to my sensor's NO contact, and then connect it to the CTS pin.
So, everytime my sensor detects a box, the CTS pin will receive -13V (high logic) provided from the DTR pin into the NO contact.
Ok, so now I'll assign the CTS pin state (via silverlight or whatever) to trigger my printer... to print.

Is it possible? Still want me to run? (it's kind of ironic to tell me to run, but let's not talk about that right now)
 

Reloadron

Joined Jan 15, 2015
5,991
Microsoft Silverlight is for web based activities and has nothing to do with communicating with the RS 232 port.
Microsoft Hyperterminal is nothing more than terminal emulation software which I do not believe has been included with a Windows OS since Windows XP. It was designed for communication over a port and not doing what you seem to want to do. What operating system(s) exactly are you working with?

What exactly is your sensor? My advice is just run the little program I linked to and using a 6 volt or 9 volt battery connect the Negative (-) to pin 5 and touch the Positive to pins 1, 6, and 8 one at a time and note what the program does. Forget trying to toggle a digital out pin and running it to a digital in pin. The little program I linked to is merely an example of looking at the digital in and digital out pins on a RS 232 Serial; Port. You will have to write your own software to do whatever it is you want to do when your sensor detects something.

Ron
 

Reloadron

Joined Jan 15, 2015
5,991
You are going to have to write your software solution. You mentioned your hardware sensor will trigger a digital input on a RE232 serial port and when it does that you want a printer to print your name. You will not find an off the shelf solution to do that. Be it a RS232 port or any form of digital I/O what you are saying is IF something happens THEN do something, in this case call a print function and print something. Now you can hang another piece of hardware on a RS232 port or a USB port but the end result is you will need to write some software hardware. Just as an example in VB 6.0 (older than dirt) when I monitored the three digital input pins the code looks like this:
Code:
If MSComm1.CTSHolding = True Then
    Shape1.FillColor = &HFF&
Else: Shape1.FillColor = &HFF00&
End If
If MSComm1.DSRHolding = True Then
    Shape2.FillColor = &HFF&
Else: Shape2.FillColor = &HFF00&
End If
If MSComm1.CDHolding = True Then
    Shape3.FillColor = &HFF&
Else: Shape3.FillColor = &HFF00&
End If
The digital inputs are Boolean they are either true or false. I am saying If True Then do something and the something is to change the fill color of a shape. You want to say IF something is True THEN call a print function and print something.

Also before communicating withe the comm port there is a need to open the port and close the port when we are done. That looks a little like this in VB 6.0.

Code:
Private Sub Command1_Click() 'Start
MSComm1.CommPort = Val(Combo1.Text) 'Select port from combo box
MSComm1.PortOpen = True 'Open the port
Timer1.Enabled = True
End Sub

Private Sub Command2_Click() 'Stop
MSComm1.PortOpen = False 'Close the port
Timer1.Enabled = False
End Sub
Microsoft did at one time offer free express versions of their Visual Studio software. You may want to Google Microsoft Visual Studio Express and see what if anything is still offered for free. There are likely a half dozen languages you can write the code in.

What you describe doing is not very difficult but will take some work and learning.

Ron
 
Last edited:

bug13

Joined Feb 13, 2012
1,976
Seem like you can deal with software, in this case, just stick an Arduino in it. That's all you need. (plus a resistor)

  • Pull up resistor to the output of you NO relay output.
  • Read Arduino input tutorial
  • Read Arduino serial com tutorial
  • Now write a code to read the input, send some stuff to serial com.
  • At the computer, read the serial com, and do whatever you want to do at the PC
 
Top