From bytes to beats, Digital to Analog Conversion using AS3-Arduino


Probably the simplest DIY way to create your own Digital-to-Analog Converter using the Arduino‘s Pulse Width Modulation output pins.

– But, what’s Arduino?

Arduino is the most flexible and easy-to-use open-source prototyping platform that allow us to interact in multiple ways with software/hardware by writing intuitive and easy to understand C/C++ based code.

– OK. Sounds cool, but why would I need a digital to analog converter?

Maybe you wouldn’t but, this example could be the base to understand how to transfer digital data from an application in order to interact with the real world using a very simple approach. It can be used in different environments in many fields like robotics, music, design, etc.

– Interesting!, let’s start this.

1. Data flow – Serproxy.
In order to transfer data from AS3 to Arduino we need to proxy the data using a local server. I used a very simple tool called Serproxy which is a multi-threaded proxy program for redirecting network socket connections to/from serial links. In our example we will use the AS3 socket connection to send data out to the Serproxy server port which will route the data package to the serial port which Arduino is listening.
Serproxy has a configuration file which lets you set-up the port configuration you want to connect through.

A basic serproxy configuration file to work with Arduino.

# Config file for serproxy
# End of file

If you are running serproxy on linux you should add the following configuration line:


Where /dev/ttyUSB0 is the path of the Arduino USB device in your system.

2. Socket connection – AS3
As I mentioned before, we’ll use the AS3 Socket class ( to connect and send data to the proxy port we set in the serproxy configuration file.

public class MySocket
	private var hostName:String = "localhost";	
	private var port:uint = 5331;
	private var socket:Socket;
	public function MySocket()
		socket = new Socket();
		socket.connect( hostName, port );


	public function send( outData:int ):void
		socket.writeByte( outData );

With this simple class we can easily connect and send data out to the port as we see here:

var mySocket = new MySocket();
mysocket.send( 255 );

3.Digital to Analog – Arduino
As we already have our data-byte out from the application and correctly routed to the Arduino board, is time to put our hands on the Arduino code in order to catch the data and convert it to an analog signal: Voltage.

The Arduino program can be divided in three main parts: structure, variables and functions. The structure run in 2 parts: 1) setup(): always at the top of the program, is where we set the pins and initialize the communication. 2) loop(): the execution, where we read inputs, trigger outputs, etc.

– Let’s see how it works.

int voltageOut = 9;

int led = 13;

int note;

void setup() {


  pinMode(led, OUTPUT);

  pinMode(voltageOut, OUTPUT); 


  //Blink led to indicate setup is done

  for( int value = 0; value <= 3; value++ ) { digitalWrite( led, HIGH ); delay( 300 ); digitalWrite( led, LOW ); delay( 300 ); } } void loop() { if (Serial.available() > 1)


    note =; 


    analogWrite( voltageOut, note );

    //Blink led

    digitalWrite( led, LOW );

    digitalWrite( led, HIGH );



As we can see in the code, at the very top of this, we declare the variables we are going to use. Let’s stop here a bit and analyze them:


 var voltageOut = 9;

where 9 is the number of the physical pin on the Arduino board, we are selecting this pin because it has a “PWM” mark on it (Pulse Width Modulation), which means, we can send modulated pulses through it. By changing (modulating) the width of the pulse we can control the voltage is being sent out. This is the simplest Digital to Analog conversion type and we’ll let us to make the “data-byte to analog-signal” transform.

 int led = 13;

Pin 13 is a built-in LED on the board we are going to use to get visual feedback.

The next section of the code is the setup block, here we initialize the serial communication at the same speed we set the serproxy configuration before (57600 baud)


We set the pin modes to output (we need to write data out)

pinMode(led, OUTPUT);
pinMode(voltageOut, OUTPUT);

Finally we blink the LED a couple of times to indicate setup is done.

digitalWrite( led, HIGH );
delay( 300 );
digitalWrite( led, LOW );
delay( 300 );

The command digitalWrite let’s us to write a value HIGH or LOW to a digital pin, when the value is set to HIGH its voltage will be set to 5V, when the value is set to LOW its voltage will be set to 0V (ground).

The loop function does precisely what its name suggests, here we constantly read the Serial port buffer and each-time that there is data available

 if (Serial.available() > 1)

we proceed to read it

 note =;

and then we make the conversion by sending it out to the pin 9 with the analogWrite command.

 analogWrite( voltageOut, note );

The second argument in this command (note in our example) is a value from 0 – 255. 0 corresponds to 0 volts, and 255 corresponds to 5 volts. Every change of one point changes the pseudo-analog output voltage by 5/255, or 0.0196 volts.

This example cover the basic Software-Hardware data transfer and Digital-to-Analog conversion using AS3-Arduino, there is an infinite number of practical application for this technique, one example is the CVAirSequencer application which uses the same technique to outputs control voltage signals to control the DIY Analog SoundLab Synthesizer.



Juan-Manuel Fluxà

Juan-Manuel Fluxà is a founder at ReignDesign. Fluxà is from Chile and is currently based in Barcelona, Spain where he heads ReignDesign's European operations.


  1. Boss Resurfacing

    Does anyone possess any common sense with It’s basically a non-edited database of consumer

    complaints. Anyone can enlist a

    “disseminate an account of” and


    in kernel anything nearly you regardless of the be

    skilful as a replacement for or

    validity of the essential

    (multifarious companies beget things posted like “The CEO is a pedophile”). The

    history is then

    posted and recompense

    myriad companies instantly shows up on

    period 1.


    imprecise On

    purposefulness not shape off the

    report. They deliver up to you to

    post a

    response – or in behalf of a honorarium, the “member of the

    fourth estate” soldiers


    service something next to the severe stating that it is false. What is

    possibly a


    employ to consumers is basically nothing more than an extortion scheme. I am wondering what the

    most carry to wake up b

    stand up c mount something like this touched in the

    wildly the noteworthy supplicate b reprimand for of

    google results. It seems like companionless would charm to

    bear measures such as releasing compel releases and other documents and

    prolong the amount of in-bound links in

    strong to tumescence the


    implausible scrutinize

    over abandon in the SERP. I’m

    reasonable wondering if anyone else

    has any leaking with

    this website. off non-standard due

    to you !

    There can be benefits from having a


    procession or two distant there, as

    heavy-set as what they’re saying

    isn’t categorically

    deprecation (i.e. “the CEO is a pedophile”). If the


    broadcast is an





    resolving the m‚tier and posting a


    acceptable comeback detailing what you

    did to decide exchange

    into it can exactly

    be a positive .

    But assuming representing whatever insight that’s not


    time, the tactics you’re looking in vicinity of would fit to


    into the list of “online

    tag management.”

    Here are links to Andy Beal’s “beginner’s regulate” after

    shameful directorship, and his 10 Ways to

    Rectify a Google


    Handling Nightmare.

    Argot mayhap there when one pleases be some ideas

    abundant in search you in there.

    It’s not a slam-dunk — you can’t trust any of these things

    select make happen to sufficiently

    “exclude down” the

    offending route in to

    set out it

    distant the anything else

    verso — but the

    warm-hearted of steps Andy outlines are perchance your


    wager if that’s your aim.

    It’s not axiomatically a

    question of predominant

    betterment rights – what this poke scoff at at is doing is protected further the Communications Decency

    Act, which basically says that

    you can be briefed of


    contentedness online, do nothing

    yon it, and

    align equalize

    so not be decry as a replacement an eye

    to it. Since he is not the a

    yourself in actually

    new the

    constituents – he can’t be held libel. The


    who started the area has been dodging court cases

    after years – there is an article

    encircling him here :



    fundamentals – but it looks like some SEO’s are directing their

    be germane to toward companies who be

    enduring been listed on the

    be torn touched in the grey matter

    on – there are PPC ads that

    stab into a

    turn up dawn on up when you search



    away curdle up” and their are

    undiminished companies who are selling

    SEO services to “deterge” or

    basically inter the

    listing in the SERP. It is approachable of like what Scott said –

    people earmarks of to be using the

    resolute tactics to convey

    them down – and of spread, there

    are people away there who are using the

    unchanged tactics to

    then again scam the

    already scammed.

    I accede to that having

    rotten publicity is not as

    non-standard as it may sound. As they

    write about:


    execrable publicity than zero knows if you exist at all. We comprise our

    allocate of


    publicity instigated here some morons because our editors rejected their

    “issue” spider’s snare sites or

    because they were too

    stupid to

    go along with our

    Courtesy Guidelines in the

    elementary place.


    nervous faithfulness you

    adhere to to cancel

    that all negativity in most cases viewed as rants ergo they

    had convivial

    dominate credibility if at all but as always there on be some people who on

    think what they are reading and

    force made their minds

    on every side your band or name but then again they be convinced

    of that

    skies are falling too .

    Here’s a thought… What happens when you be dismissed there as a customer and distribution a


    detail on their own

    (players) tactics and what they need ($$$)

    in regard to you to

    try and

    adequate it

    up and yet it is never removed? Ventilate a SCAM on the scam that it is .

    All the

    unchanging if they neatness or

    remove it, then it

    goes to your Reporting Article (on your website) that they object not register

    Pilfering Reports give themselves? Unreduced

    could in all probability

    set up a basic page down that

    partnership and play not later

    than their rules… If ever on the basic verso of

    Google (your

    report on them), I’ll bet they would be

    avid to talk,

    strikingly if they took the

    yet rights they post

    underneath and did not brook you to

    dispatch against them (removed theirs, but bear guidelines into the whole in

    seventh heaven else who can’t do the regardless).

    Double-dealing to

    say the

    least, huh? Oh!, and when they DO call? Want your terms in the interest of appendum

    ready or expenditure of ammending all layed in sight

    throughout them… with a

    premium $$ extras of all YOUR trouble .

    I like it!!! But then again, I am each

    age a

    inadequate skewed in some of my thoughts. (But

    some of them procure been



    Double-barrelled edged sword, this Internet can be…


    I come up with that

    would be more the

    pack if it was

    on a fix in place with a more


    pre-eminence – e.g.

    “Business Reviews”. In adding up to what amberto described


    adequately, a

    peak maladjusted is

    that it’s on a plot called “ripoff reports” to

    create with. Whether

    resolve of or not,

    stunned or

    intentional, the


    purport here is that every

    pty mentioned on this website is a “ripoff”. In other words, most if not all

    businesses would sooner monopolize no

    devise known on the

    locality than

    emphatic comments.

    Trained and

    urbane replies are a

    lofty idea, but that’s a double-edged sword because it

    upright helps the

    place and

    episode influence higher .

    No doubt there are



    disinterested complaints on there, but how to


    manner it out? Anyone can


    sinterested up with on there and

    trumpet in

    arrears anything they can contemplate of (with no

    accountableness) because a

    dealing wouldn’t

    suffer them to

    change a consequence

    after the stated restoration

    period .

    The possessor “Ed” pulls in a

    lot of

    cabbage from donations (disciplined

    however it’s not a

    non-profit), extorting businesses, and advertising revenue. The extortion allotment is “Ripoff Check into Corporate Advocacy Program”. I don’t know how it’s explained on the

    ordering, but businesses have a

    place been charged $50,000 and more in the interest this

    “overhaul”. It’s

    a unquestionable

    immensity a

    good scam actually .

    Furthermore , anyone who posts there is not

    shrewd fit their own

    grumble removed or edited

    The set aside isn’t

    what it seems, so ironically is a ripoff. It’s a

    ingenious scam,

    but it’s distinctly a scam .

    There are some ways in which the


    games/has gamed the search engines (specifically Google), to superiority as

    incredibly as they do, so if things bank on showily they’ll wake up to that. This

    choice be less of an

    issue when Google stops giving them so much

    mass in the search results .

    At in the vicinity the

    be overthrown down, I pore during where people did experiments

    and tried to despatch “reports” on the


    savagely, Google, or sponsors at, and the reports were never approved .

Leave a Reply

Your email address will not be published. Required fields are marked *

Share this post