Category: Uncategorized

  • What’s the deal with optoisolators

    An optoisolator, a.k.a. optocoupler (opto), is a device that sends a signal from its input to its output using a beam of light. They are typically used when the input and output must be isolated electrically from each other. Generally this is because one of the devices at either end of the opto can’t handle the voltage at the other end. e.g., an input signal of 100 volts that must be detected by an Arduino that can only accept 5 volts. In this case, the opto offers a safer voltage interface than using a voltage divider. Voltage dividers mean that one leg of the input voltage must be connected to the Arduino and this can lead to an unsafe circuit. Using an opto means that the only connection between the input and output is a beam of light inside the opto.

    Optocouplers are rated by their isolation voltage. e.g., the isolation voltage for an inexpensive and common 4N26 optocoupler is 5000 volts! This means that the input voltage in the previous paragraph would have to be greater than 5000V before damage would be caused to the Arduino.

    A useful application for an optocoupler is in driving an output to a higher voltage than an Arduino can handle. A 4N26 opto can be controlled by a 5V-tolerant Arduino and can switch up to 70 volts. This means that if you want to control e.g., a PLC (Programmable Logic Controller)  by sending it a 24V control signal, your Arduino can be used to control the optocoupler which is switching the 24VDC signal. This provides isolation and a higher drive capacity to the Arduino. Some of you may realize that the same thing can be done with a relay. The benefit in this case is that an optocoupler is (a) less expensive than a relay, (b) much smaller than a relay and (c) can be driven directly from the Arduino digital output without additional drivers or inductive protection. The drawback is that only very small signals can be switched, but for the right application it’s perfect.

    In short, the optocoupler is a very useful addition to the toolbox of available interface components that can be utilized by the Arduino.




    If you’d like to subscribe to this blog, please click here.

  • Arduino One-shot timer

    A recurring task that comes up in machine control or experimenting with Arduino is turning an output on for a fixed time, then shutting the output off. In electronics, the circuit that does this is called a One-Shot Multivibrator. A multivibrator is a circuit that switches between two states – On (or High) and Off (or Low). A one-shot multivibrator does this once. Its  normal state may be off, but when triggered, it switches on for a period of time and then back off.

    We use the same name to describe code or an Arduino sketch that performs this one-shot function. Typically there is an input like a pushbutton that is monitored and a digital output that will execute the one-shot function when the pushbutton is active.

    A retriggerable one-shot is a version where triggering it again before the time is up causes the time to be extended. So, say the one shot output would be on for 10 seconds, pushing the button in our example three times would result in a total output On time of 30 seconds. A non-retriggerable one-shot ignores the triggering input while the output is active.

    Here is code for a basic non-retriggerable one-shot Arduino timer.

    // Project sponsor: N/A
    // Email: sales@cedarlakeinstruments.com
    // Creator: Cedar Lake Instruments LLC
    // Date: April 2018
    //
    // Description:
    // Demonstrate one-shot logic with Arduino
    //
    // Arduino pins
    // 2 - Digital trigger input. Pull LOW to trigger one shot
    // 3 - Cancel one shot timer (output goes LOW)
    // 13 - One shot output (goes HIGH for one shot time)
    //
    #define TRIGGER 2
    #define CANCEL 3
    #define OUT 13
    
    // *********************************** U S E R  A D J U S T M E N T S **************************
    // One shot time in milliseconds
    #define DELAY 6000
    
    int _timeout = 0;
    
    void setup() 
    {
        pinMode(TRIGGER, INPUT_PULLUP);
        pinMode(CANCEL, INPUT_PULLUP);
        pinMode(OUT, OUTPUT);
        digitalWrite(OUT, LOW);
    }
    
    void loop() 
    {
        // One shot triggers on high->low transition of TRIGGER pin
        if ((digitalRead(TRIGGER) == LOW) && (digitalRead(CANCEL) == HIGH))
        {
            _timeout = DELAY;
            digitalWrite(OUT, HIGH);
        }
    
        // Hold output High until timeout or cancel pressed
        while (_timeout-- > 0 && (digitalRead(CANCEL) == HIGH))
        {
            delay(1);
        }
        digitalWrite(OUT, LOW);
    
        // Hold here until inputs inactive
        while ((digitalRead(TRIGGER) == HIGH) && (digitalRead(CANCEL) == HIGH));
    }



    If you’d like to subscribe to this blog, please click here.

  • Production Counting

    Any business producing an item needs to count the numbers put into inventory. However, counting items in production can provide far more benefits than just stock quantity. One of the main points of tracking the production of any item you make is knowing how efficient your process is.

    • How many widgets did you make last week vs. this week?
    • How many yesterday vs. a week ago?
    • How many bad ones did we make?
    • How close did we get to our target?
    • Do you get more done at a particular time of day?
    • What time of day do most of your production defects crop up?

    To answer these questions, you first need to track how many widgets you make and when you make them.

    You don’t need a complicated, expensive MRP (Manufacturing Resource Planning) system to this. More than anything, you need data! Whether that data is collected manually with pencil and paper or electronically, by automated counters is up to you.

    One of the simplest methods of automated counters is sensing the product on a belt. Your item passes by a sensor that is an input to the counter and each unit is counted.

    Alternately,  tally counters can be used to do manual counts. Tally counters can be simple handheld mechanical or electrical counters that have a push button to advance the count. PC versions are also available. An advantage of a PC counter is the ability to easily track the time of day when each item was counted.


    If you’d like to subscribe to this blog, please click here.

  • Counters with custom serial output

    We recently made a modification for a customer that was such a great idea, I thought I’d post it here. They wanted to use our PRT-232 counter with RS232 serial interface but it was needed to interface to a legacy control software package. The software was originally designed to read data from a different serial measuring device. We modified the output of the PRT-232 to provide the text string the control software wanted to see on its serial port and the integration went smoothly.

    It was such a useful concept we decided to offer it to anyone who requests. We will now customize any of the output strings the device generates for a nominal charge. That means that on an input switch transition, or specific level, we can output a string. e.g, input 1 goes active, it can send “Pump On” or if it goes inactive “Pump Off”
    Or after counting to a certain value, we can output “Limit Reached” etc. It’s only limited by your imagination!

    Of course, the normal behavior of the counter is unchanged: it will still count and report data as normal.


    If you’d like to subscribe to this blog, please click here.

  • Measure temperature with AD592 and Arduino

    The menu example in a previous post can easily be modified to conver the raw A0 analog reading into voltage. Since the Analog Devices AD592 converts temperature into a current proportional to absolute temperature, we can convert this to a voltage using a single resistor. By taking advantage of the Arduino’s 10-bit analog input, we read this voltage and convert to a temperature.

    Here’s the updated code:

    // Description:
    // Simple menuing system for Arduino
    // Demonstrates a menu with controls and
    // data readback
    //
    // Communicates with PC at 115,200 bps 8N1
    //
    #define LED1 2
    #define LED2 3
    
    void setup() 
    {
      pinMode(LED1, OUTPUT);
      pinMode(LED2, OUTPUT);
      Serial.begin(115200);
      menu();
    }
    
    void loop()
    {
     int m = readMenu();
     switch (m)
     {
      case 1:
       digitalWrite(LED1, HIGH);
       break;
      case 2:
       digitalWrite(LED1, LOW);
       break;
      case 3:
       digitalWrite(LED2, HIGH);
       break;
      case 4:
       digitalWrite(LED2, LOW);
       break;
      case 5:
      {
        // VT100 reset cursor to end of menu (row 15, column 1)
        char resetCursor[] = {27,'[','1','6',';','1','H',0};
        Serial.print(resetCursor);
        double temp = analogRead(A0) * 4.9 / 10.0 - 273.1;
        Serial.print("Temp: ");
        Serial.print(temp);
        Serial.println("C");
        break;
      }
      default:
       break;
      }
    }
    
    // Waits in a loop until key is pressed
    // then returns digit selected
    int readMenu() 
    {
     while (!Serial.available())
     {
       delay(100);
     }
     return Serial.read() - 48;
    }
    
    
    // Displays menu
    void menu()
    {
      // Clear
      char buf[] = {27,'[','2','J',0};
      Serial.print(buf);
      
      // Print menu
      Serial.println("\n\n\n\n\n");
      Serial.println("1....LED1 on");
      Serial.println("2....LED1 off");
      Serial.println("3....LED2 on");
      Serial.println("4....LED2 off");
      Serial.println("5....Read A0");
      Serial.println("\n\n Select 1..5");
    }
    

    If you’d like to subscribe to this blog, please click here.

  • Communicate to Arduino from PC

    Although the Arduinos are great little controllers, sometimes you need to connect them to a PC to transfer data or control. One of the simplest ways of using a PC to control your Arduino is with a menu.

    Menus have been used on computers pretty much forever. Back in the 80’s the green screen (green text on a black background) text menu was very popular. They persist to this day in some specialized applications.

    In a nutshell, your PC will run a simple terminal program. Putty.exe is a great choice. It’s free, works great and supports the popular VT100 terminal control characters we will need.

    The Arduino serial parameters are set to 115,200 bits/second, 8N1. Make sure your terminal program is set up similarly.
    The example program turns on and off two LEDs and displays the raw data read back from the Analog0 port

    Here’s the program:

    // Description:
    // Simple menuing system for Arduino
    // Demonstrates a menu with controls and
    // data readback
    //
    // Communicates with PC at 115,200 bps 8N1
    //
    #define LED1 2
    #define LED2 3
    
    void setup()
    {
      pinMode(LED1, OUTPUT);
      pinMode(LED2, OUTPUT);
      Serial.begin(115200);
      menu();
    }
    
    void loop()
    {
      int m = readMenu();
      switch (m)
      {
        case 1:
          // Turn on LED 1
          digitalWrite(LED1, HIGH);
          break;
        case 2:
          // Turn off LED 1
          digitalWrite(LED1, LOW);
          break;
        case 3:
          // Turn on LED 2
          digitalWrite(LED2, HIGH);
          break;
        case 4:
          // Turn off LED 2
          digitalWrite(LED2, LOW);
          break;
        case 5:
        {
          // VT100 reset cursor to end of menu (row 15, column 1)
          char resetCursor[] = {27,'[','1','6',';','1','H',0};
          Serial.print(resetCursor);
          Serial.print("A0: ");
          // Read Analog 0 input and display data
          Serial.print(analogRead(A0));
          break;
        }
        default:
          break;
       }
    }
    
    // Waits in a loop until key is pressed
    // then returns digit selected
    int readMenu()
    {
      while (!Serial.available())
      {
        delay(100);
      }
      return Serial.read() - 48;
    }
    
    // Displays menu
    void menu()
    {
      // Clear screen
      char buf[] = {27,'[','2','J',0};
      Serial.print(buf);
    
      // Print menu
      Serial.println("\n\n\n\n\n");
      Serial.println("1....LED1 on");
      Serial.println("2....LED1 off");
      Serial.println("3....LED2 on");
      Serial.println("4....LED2 off");
      Serial.println("5....Read A0");
      Serial.println("\n\n Select 1..5");
    }
    

     

    When you run this, you will get a menu with 5 options. We demonstrate how to position the cursor on the screen using escape commands. Look at the code that prints the value of A0 on the screen for an example.

    Menuing is a simple but effective way to get your PC and Arduino talking to each other.


    If you’d like to subscribe to this blog, please click here.

  • Duplicating an existing item

    Copying an item that is already on the market is a topic that continues to come up no matter what kind of manufacturing business you have.

    The guys running machine shops, for example, are very familiar with people walking in off the street wanting a special washer, or bracket made. Often they are very upset at being told that the doohickey they could purchase at WalMart for $20 will cost hundreds or thousands to make. Why does this happen?

    Let’s say you broke a part for a lawnmower. It’s a very simple piece of metal with three holes that is bent into a Z shape. It looks like a 5 minute job.

    So you walk into a sheet-metal shop and ask how much it would cost to have one made, since you can’t wait a week for a replacement to be shipped. They shop foreman looks at it and says $500.

    Why does it cost $500? Well, someone has to take that part, measure each dimension, measure the distance of each bent section, the offsets to all the holes, measure hole dimensions, material thickness, etc. Then the raw metal stock has to be retrieved from inventory, marked out, cut to size, drilled. The bender has to be set up, metal bent, edges deburred, etc. And that’s assuming that the shop even has the free time to get to it within a  reasonable time and that no jobs in progress have to be stopped. Under the best case, it could easily take half a day to make the first bracket. Of course, the next 500 could be made in the next half day now that all the design and setup work is done, but you only need one, so that doesn’t matter.

    Much easier to just order it online for $15 + shipping!

    It’s no easier in our world of electronics. In fact, it’s complicated by the fact that most of what we do involves the invisible aspect of software. A seemingly simple item that has a parts cost of $10 and sells for $100 could have $20,000 of engineering time behind it to create the first unit. Sure,  as a hobbyist you could copy it and do an awesome job and in the end it only cost you $10, but that ignores the cost of your time. If you’re doing it for fun, who cares about accounting for the time? The problem comes when you need someone else to do all or some of the work for you. Even without the overhead of a large engineering firm, that $100 item could still end up costing you $10,000 to make the first unit.

    What does all that extra money pay for?

    • Documentation: how to build the next 5,000 units after that first one is done
    • Packaging: designing the enclosure it goes into and where the pushbuttons and LEDs go
    • User interface: does it have a display? Should multiple languages be supported? Is the flow from one screen to the other smooth and intuitive? It’s really easy to build something for your own use, but much harder when it has to be usable by a wider variety of people
    • Parts selection: which components should be used? Who to buy them from? Is anything critical about to be discontinued?

    This is only scratching the surface. The point is that very often, asking to duplicate the functionality of a professionally designed item will require an equally professional designer and there won’t be any cost savings. Unless you need something customized for your needs, it is almost always far less expensive to buy an existing item off the shelf.

    So, if you do need something specially built, how do you go about it?

    Well, in an ideal world you’d have a complete set of requirements, or a detailed specification. In the real world, you typically only have an idea of what you want and need the details filled in.

    So, the engineer you’re working with may need to know the answer to questions like:

    • Do you need just one, or thousands?
    • Will it use battery power or plug into a wall outlet?
    • Does it need to fit into another assembly?
    • If it measures something, how accurate does it have to be? More accuracy than needed can be expensive!
    • Will it be outside and need to be protected from the elements, or in a nice, clean office environment?

    Developing a brand new product, or even a variation of an existing one, is a collaborative process. As you discuss your needs, you may find out that there are many small details that are actually important, but you haven’t had the opportunity to think about before.

    In our prototype-building work, we come across this quite often. In the process of discussing a need, often the client realizes that there’s something off the shelf that could be modified instead. And it will cost a lot less than a custom design!


    If you’d like to subscribe to this blog, please click here.

  • Arduino Programming: stuff we forget

    This post will probably grow over time as I add suggestions from you guys. I see a lot of posts online from Arduino enthusiasts who want to build one thing or another. It’s easy to think of which Arduino version you need and the sensors, actuators, etc. The problem is that we forget all the small, incidental things and those costs can add up. When you’re making up your Bill of Materials (BOM), it helps to remember all this “extra” stuff you might not think of right off the bat so you get a good idea of what it will all cost.

    So, what do makers/builders often forget?

    • Power. You need a power supply if you’re not planning on keeping your project connected to a USB port. And sometimes even if you are, you’ll need extra power to drive that motor, or multiple supply voltages because you can’t/won’t use a regulator
    • Enclosure. Is it going to be outside? Probably need a NEMA4-rated box. Even if it’s kept inside, a pretty enclosure is a great way to finish up your project and make it look professional.
    • Wire. Yep, something as basic as wire can really add up, especially if you need multiple gauges or ratings
    • Connectors. Round is better. Drilling holes is easy even with cheap tools. Making square, trapezoidal or just plain weird shaped holes is not. Well, not unless you have a machine shop at your disposal. If you do, maybe we can help each other!
    • Tools. Can you drill all the hole sizes you need?

    If you’d like to subscribe to this blog, please click here.

  • Android Bluetooth serial port communication

    Tablets and smartphones are everywhere and prices are dropping fast.  A tablet provides a great user interface: it’s inexpensive, has a high resolution color touchscreen and it’s an ideal method to control an embedded system.

    The most straightforward way to do this is with an embedded system exposing a web  interface over Wi-Fi. In this case, the tablet only needs a browser to connect. However, smaller embedded systems may not have this luxury. Here we will look at using an Android tablet to connect to a small embedded system using Bluetooth.

    We won’t get into the details of the embedded system but for clarity’s sake, let’s say it’s a small Arduino measuring room temperature and connected to a Bluetooth transmitter. It sends a reading automatically once per second.

    There is a lot of information online about using Bluetooth with the Android. The problem is that it is fragmented and few sites have all the information in one place. So I figured I’d compile a set of the major points you need to know to get the Bluetooth Serial Port Protocol (SPP) working on an Android app.

    First, your app needs the BLUETOOTH and BLUETOOTH_ADMIN permissions. This goes in yourAndroidManifest.xml file.

    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
    

    Now that we have given the app permission to access the Bluetooth API, let’s look at the classes that are relevant. We’ll need the BluetoothAdapter, BluetoothDevice and BluetoothSocket classes to connect to the external system.

    First, we need to find and pair with the device. The following code snippet builds a collection of Bluetooth devices that were discovered by your Android device.

        BluetoothAdapter bta = BluetoothAdapter.getDefaultAdapter();
        bta.startDiscovery();
        Set deviceList = bta.getBondedDevices();
    

    Now that we have a list of external devices, we can iterate over the collection and extract the name and address of each device like this.

        for (BluetoothDevice i : deviceList)
        {
            String name = i.getName();
            String address = i.getAddress();
        }
    

    You can select which one you need from the list and connect to it. Selecting the device is something you can decide how to handle yourself. Connecting to the device is done using its Bluetooth address. Once you have a selected device, we connect to it by requesting the device through its address. The address is a unique 48-bit ID assigned to each Bluetooth device.
    Once we have the device, then we’ll open a socket using the standard UUID for the SPP serial port protocol to indicate that we want to connect to the device as if it were a standard serial port.

        BluetoothAdapter bta = BluetoothAdapter.getDefaultAdapter();
        BluetoothDevice device = bta.getRemoteDevice(address);
        BluetoothSocket socket = null;
        if (device != null)
        {
            UUID serialID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
            try
            {
                socket = device.createRfcommSocketToServiceRecord(serialID);
            }
            catch (java.io.IOException e)
            {
            }
        }
    

    Next, we’ll handle sending and receiving data from the socket.


    If you’d like to subscribe to this blog, please click here.

  • Open collector output connection

    20150513_080103


    If you’d like to subscribe to this blog, please click here.