Example Projects
Workshops
Announcements
Actuators
Connections
Power
Sensors
Traces

Circuits and Code Wireless

Meet the Materials
Conductive Materials
Non-Conductive Materials
Tools
Techniques
Thinking Out Loud
Circuits and Code
  • Arduino Overview
  • Arduino as Bluetooth HID
  • ATtiny: 7-Segment Display
  • ATtiny: Capacitive Sensing
  • ATtiny: Programming
  • ATtiny Serial & Wireless Boards!
  • ATtiny: Soft Serial
  • ATtiny: Sound
  • ATtiny: Soft Fade
  • Bits and Bytes Binary numbers
  • Multiplexed Matrix
  • Controlling EL Panel and EL Wire
  • EL panel/wire inverter hack
  • EMF amplifier
  • Heat Controlling Circuit
  • LED with Light Sensor
  • Lilypad XBee Shield
  • My First Arduino Connection Check
  • pressure matrix code + circuit
  • Pull-up Resistors
  • Rabbit Control Client on Bela
  • RabbitControl on Bela
  • RGB Colour Fade
  • simple heat circuit
  • Solar Powered Motor Circuit
  • Sound Amplifying Circuits
  • Graphing and Drawing Sensor Values
  • Teensy as HID Device
  • Transistor Switch
  • Volume Detection
  • Visualization: 2x2 Matrix
  • Visualization: Drawing
  • Visualization: Graph
  • Visualization: Pressure Sensor Matrix
  • Visualization: Touchpad
  • Voltage Divider
  • Voltage Divider with Arduino
  • What is Variables?
  • Support the creation of content on this website through PATREON!
  • About
  • E-Textile Events
  • E-Textile Spaces
  • Newsletter
  • Print & Publications
  • E-Textile Shopping

  • SEARCH
    Content by Mika Satomi and Hannah Perner-Wilson
    E-Textile Tailor Shop by KOBAKANT
    The following institutions have funded our research and supported our work:

    Since 2020, Hannah is guest professor of the Spiel&&Objekt Master's program at the University of Performing Arts Ernst Busch in Berlin

    From 2013-2015 Mika was a guest professor at the eLab at Kunsthochschule Berlin-Weissensee

    From July - December 2013 Hannah was a researcher at the UdK's Design Research Lab

    From 2010-2012 Mika was a guest researcher in the Smart Textiles Design Lab at The Swedish School of Textiles

    From 2009 - 2011 Hannah was a graduate student in the MIT Media Lab's High-Low Tech research group led by Leah Buechley


    In 2009 Hannah and Mika were both research fellows at the Distance Lab


    Between 2003 - 2009 Hannah and Mika were both students at Interface Cultures
    We support the Open Source Hardware movement. All our own designs published on this website are released under the Free Cultural Works definition
    Circuits and Code

    Graphing and Drawing Sensor Values

    CODE EXAMPLES

    ARDUINO
    Single Analog Sensor Value
    Smoothing a Single Analog Sensor Value
    Multiple Analog Sensor Values
    Smoothing Multiple Analog Sensor Values

    ARDUINO —> PROCESSING
    Graph Single Analog Sensor Value in Processing
    Graph Multiple Analog Sensor Values in Processing


    ARDUINO


    Single Analog Sensor Value

    Examples: Communication –> Graph
    This example contains the code you need to read an analog sensor value and send it over the Serial port.
    You will need to build a voltage divider in order to connect your sensor to the Arduino.

    Voltage Divider:

    External voltage divider connected to Arduino:

    Or you can use the following line of code to turn on the internal pull-up resistors inside the Arduino’s ATmega328 chip:
    pinMode(A0, INPUT_PULLUP);

    Internal voltage divider using “pull-up” resistor inside Arduino:

    Open the Serial Monitor> and you should see the sensor’s value 10bit [0-1023] being printed.
    Arduino monitors and plotters

    Open the Serial Plotter> and you should see the sensor’s value 10bit [0-1023] being plotted as a graph.
    Arduino monitors and plotters

    Notice that the graph auto-zooms to adjust to the current sensor range. This is annoying. You can fix the graph to a set range by also printing the analog sensor’s minimum and maximum values. Add the following lines of code to the sketch:


    Serial.print(0);
    Serial.print(“,”);
    Serial.print(1023);
    Serial.print(“,”);
    Serial.println(analogRead(A0));

    Open the Serial Monitor and you should see:
    Arduino monitors and plotters

    Open the Serial Plotter and you should see:
    Arduino monitors and plotters


    Smoothing a Single Analog Sensor Value

    To smooth your sensor value, a simple line of code you can add to calculate the running average is:
    averageSensorValue = (averageSensorValue * (average-1) + currentSensorValue) / average;

    GITHUB: a_graphMultiple-smoothing

    Open the Serial Monitor and you should see:
    Arduino monitors and plotters

    Open the Serial Plotter and you should see:
    Arduino monitors and plotters

    The green line is the raw sensor value, the yellow line is the smoothed sensor value.


    Multiple Analog Sensor Values

    To graph multiple sensor values, you can use this code:
    >> GITHUB: a_graphMultiple

    Open the Serial Monitor and you should see:
    Arduino monitors and plotters

    Open the Serial Plotter and you should see:
    Arduino monitors and plotters


    Smoothing Multiple Analog Sensor Values

    Open the Serial Plotter and you should see:
    Arduino monitors and plotters


    ARDUINO —> PROCESSING


    Graph Single Analog Sensor Value in Processing

    Examples: Communication –> Graph
    This example contains the Arduino code you need to read an analog sensor value and send it over the Serial port. As well as the Processing code (see the un-commented section bellow the Arduino code!) you need to graph that value in processing.

    In the Processing code you need to change the port number ### to match your Arduino port number.
    myPort = new Serial(this, Serial.list()[###], 9600);

    Run the Processing sketch and you should see something like:
    Processing graph


    Graph Multiple Analog Sensor Values in Processing

    This code draws circles in different colours with the diameter of the incoming sensor value.
    >> GITHUB: a_graphMultiple-ellipse

    Run the sketch and it should look like this:
    Processing circle


    /////////
    NOTES
    /////////

    // note the 20mS delay between sending serial data packets. This is because the Arduino sends data faster than Processing can read and act on it.

    Tom Igoe’s initial graphing code for processing:
    https://gist.github.com/madeintaiwan/6410770
    // does not work for me in latest version of processing 3.5.3 !?!?!

    Ingo’s packetizer code
    download zip: https://github.com/i-n-g-o/Packetizer
    sketch —> include library —> add ZIP library

    Arduino Cookbook by Michael Margolis
    Chapter 4. Serial Communications
    https://www.oreilly.com/library/view/arduino-cookbook/9781449399368/ch04.html



    Leave a comment