I have stand up table for about 1.5 years and I had this idea to “improve” it for some time now and finally for Christmas bought Arduino Uno starter kit.

For first version it simply measures tables height and shows charts. That’s it.

This is pre alpha version and I am using huge soap box with duct tape attached at the bottom of table.

WP_20160109_12_08_52_Pro

 

Inside is not much fancier just Arduino Uno with distance sensor (HC-SRO4 Ultrasonic Sensor).

WP_20160109_12_09_54_Pro

 

Simple dashboard to track my goal, which currently is 30% of time to be standing. For charts, I used Metro UI charts.

Application

 

Current Arduino project source code is really good example of how easy it is to communicate with computer. Just putting it there, maybe it will motivate others to start their Arduino projects.

#define echoPin 7 // Echo Pin
#define trigPin 8 // Trigger Pin

String command;   // for incoming serial data

long duration, distance; // Duration used to calculate distance

void setup()
{
    Serial.begin(9600);
    pinMode(trigPin, OUTPUT);
    pinMode(echoPin, INPUT);
}

void loop()
{
    if (Serial.available() > 0)
    {
        command = Serial.readString();
        if (command == "1")
        {
            Serial.println(getHeight());
        }
    }
}

long getHeight()
{
    digitalWrite(trigPin, LOW);
    delayMicroseconds(2);
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW);
    duration = pulseIn(echoPin, HIGH);
    return duration / 58.2;
}

C# sample code which will send command to Arduino and when it responds will print distance. Rinse and repeat.

using System;
using System.IO.Ports;
 
namespace ArdApp
{
    class Program
    {
        private const string GetHeight = "1";
 
        private static SerialPort _serialPort;
 
        static void Main()
        {
            _serialPort = new SerialPort(portName: "COM3", baudRate: 9600);
            _serialPort.DataReceived += serialPort_DataReceived;
 
            _serialPort.Write(GetHeight);
        }
 
        private static void serialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            var height = Int32.Parse(_serialPort.ReadLine());
            Console.WriteLine($"{DateTime.Now} - {height}");
 
            if (_serialPort.IsOpen == false)
            {
                _serialPort.Open();
            }
 
            _serialPort.Write(GetHeight);
        }
    }
}

And if you don’t know port name, got to “Device Manager” and look under Ports. Baund rate should match one specified in Arduino application source.

image

 

Well this is just a beginning, I have more plans how to improve it by adding more sensors and extensions to it. Will see if Arduino Uno can handle what I have in mind.

Project source code.

Comments


Comments are closed