arduinoarduino-ultra-sonic

Draw image from live arduino sensor data


I want to draw real time graph using data coming from a rotating ultrasonic sensor through arduino. What are the tools or library required for this. I am using official arduino IDE using C language.


Solution

  • The Arduino itself can't really draw a plot, so you'll have to send the data to your computer using Serial communcation. Your computer can then draw a graph. There are two options:

    Use an existing program

    The easy way.

    This official Arduino page has some example code for the program Processing, but I'm sure you can find a bunch of other examples and tutorials online.

    Write it yourself

    This is the difficult and fun way.

    If you already know a programming language, great! Search some tutorials about how to connect your Arduino & how to plot data.

    Otherwise, I recommend starting with Python, this is a good place to start.

    Java

    I have some old code written in Java that connects to the Arduino using the very easy JSSC library:

    SerialPort port = new SerialPort("COM9");
    port.openPort();
    port.setParams(9600, 8, 1, 0);
    
    byte b = port.readBytes(1)[0];    //read a single byte
    port.writeByte(b);                //write a single byte
    

    Where you'd replace "COM9" with whatever port your Arduino is connected to, as displayed in the bottom right of the Arduino IDE.

    Actually plotting the data would require another library, I see JFreeChart being recommend a lot online.