Learn how to sense distance using ultrasonic and laser sensors with a Productivity2000 industrial automation controller in this brief, hands-on demo.
For this demo we’ll be using an Ultrasonic distance sensor that outputs 4-20mA and a Laser Distance sensor that is configured to output 0-10Volts. Watch the Tech Tip videos to see how to setup and configure those sensors. We just take those outputs and wire them into the Analog Inputs of the controller. The Productivity 2000 has several ways we could approach this. We could use single 4 channel input module that can do Voltage or Current, We could use an 8 channel current input module and an 8 channel voltage input module, or we can use a 16 input current module and a 16 input voltage module. Since we only have one current and one voltage input, we’ll just use the least expensive option: the single 4 channel module. The cool thing about this module is you can set each channel to either current or voltage – you don’t have to dedicate the entire module to one or the other. That’s really handy that you can do both voltage and current on the same module. Let’s wire the Ultrasonic sensors current output into channel 1 and the laser sensors voltage output into channel 2. Make sure you add this jumper to any current inputs – there’s a little note here in the datasheet to remind you but it’s easy to miss … The module also needs 24Vdc . Here it is in hardware: the current input on channel 1 jumpered to its V+ terminal. The Voltage input on channel 2, and the 24Vdc. While we are here, look at the clarity of this amber organic LED display. It’s just incredible. This photo was taken from an extreme off angle, yet the display is still super clear. This is the actual un-retouched photo – I didn’t enhance it at all. This is what the display really looks like. That’s amazing. Now we just bring up the Productivity suite software, start a new project, and go straight to the hardware configuration dialog. Of course we need to connect to the controller … we’re connected via USB … and we want to use our new clean project. Configuring the Productivity series hardware is so easy, you just click on this button and all the hardware is automatically discovered. You don’t have to fill in any tables specify modules or anything like that – it does it all for you. It tells us it found some new stuff – we know that – so we’ll just say yes to all. And just like that we now have a snapshot of this base and if we double click on that we can see what we have. Awesome. Let’s double click on the analog input module to set it up. Channel 1 is the Ultrasonic sensor which has a current output, so we select 0-20mA and let’s change the name to Ultrasonic. The laser sensor we wired to channel 2 is outputting 0-10V so we select that one. Let’s change the name of that guy to Laser. And let’s deselect the two channels we aren’t using. We don’t really need to do that, but it is a good habit to get into - when your system starts to grow it reduces the burden on the processor. Let’s add all of these to a dataview by clicking this Monitor Button. And that’s all there is to it. Let’s transfer this configuration to the productivity 2000 and see what happens. The data view on the Productivity series controllers is awesome. In a single dialog you can see each TAG – let’s delete the ones we aren’t using - a real time plot of any tags you drag in here, and my favorite, the I/O view where I can see at a glance what every I/O in my system is doing. You may need to widen this window to see all of four channels of the analog input module. If I had more modules in this system, we would see those here too. Looks like both of our sensors are maxed out right now, but if I put my hand in front of the laser sensor, sure enough the I/O responds. And if we do the same thing to the Ultrasonic sensor, again, same result. If we drag these tags into the chart area, then we can watch the results scroll by. To use this in our ladder code, we just grab a compare contact like this, and compare the input value to something to make a decision. There is one problem though, wouldn’t it be great if instead of numbers in the range of 0 to 65535 we had real numbers we could understand, like inches to the object? Well, that’s exactly what this scale function is for. You just enter the input min and max and the output min and max. The Laser is 0 to 10 Volts input which to the PLC is 0 to 65535. And the sensor was setup to go from three to 20 inches over that range. Let’s give the new scaled value a name – we’ll call it Laser_inches. The Ultrasonic is a little bit different. The modules input range is from 0 to 20mA which corresponds to 0 to 65535 counts. But our sensor is 4 to 20mA. So if we do a little math we find the input minimum is 13107 which goes here. The sensor was setup so that 3 inches is 4mA and 16 inches is 20mA so we put that here. We’ll call that Ultrasonic_Inches. Transfer to the controller. With monitoring turned on, we see that this count that’s read by the analog module is converted into inches for both of our sensors. Perfect. We would now use that value in our ladder code to make the code easier to read and work with. And of course, the analog values are displayed right on this Analog module screen. You can even select how you want those results displayed, raw values, hexadecimal, and current/voltage. This OLED display makes debugging analog inputs easy because you see the answer right on the module and immediately know if the problem is outside or inside the controller. I love that. The Productivity Series controllers just make your life easy. From the Auto Discovery of the hardware to the OLED displays on the modules to the intuitive programming and instruction set. It’s all set up to make you more productive. If you have any questions, please don’t hesitate to contact automation directs free award winning tech support during regular business hours. They will be happy to help you. And don’t forget the forums. There are lots of folks there that love to share their years of experience. Just don’t post any support questions there. AutomationDirect’s support staff doesn’t monitor the forums on a regular basis.