# Arduino based ADSR

**URL:** https://lookmumnocomputer.discourse.group/t/arduino-based-adsr/344
**Category:** DIY STUFF
**Created:** [March 1, 2020, 7:00pm UTC](https://lookmumnocomputer.discourse.group/t/arduino-based-adsr/344 "2020-03-01T19:00:30Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![d42kn355](https://yyz2.discourse-cdn.com/free1/user_avatar/lookmumnocomputer.discourse.group/d42kn355/32/273_2.png) [@d42kn355](https://lookmumnocomputer.discourse.group/u/d42kn355)
#### Post date: [March 1, 2020, 7:00pm UTC](https://lookmumnocomputer.discourse.group/t/arduino-based-adsr/344/1 "2020-03-01T19:00:31Z")

</div>

Here is a project that I found over on [Github](https://github.com/search?q=ADSR&type=Repositories) for a basic ADSR that utilizes an [Arduino](https://en.wikipedia.org/wiki/Arduino) and an [MCP4921 DAC](http://ww1.microchip.com/downloads/en/DeviceDoc/22248a.pdf) (12-bit) to generate a very nice Curve!

It is called the “[ADSRduino](https://github.com/m0xpd/ADSRduino)” ([designed by mOxpd](http://m0xpd.blogspot.com/2017/02/signal-processing-on-arduino.html) \< — Blog Link)

 ![ADSR diagram](https://global.discourse-cdn.com/free1/uploads/lookmumnocomputer/original/1X/748e90414df806eafd90fd29ba408d8f666e57d4.jpeg) ![ADSR duino schem](https://global.discourse-cdn.com/free1/uploads/lookmumnocomputer/original/1X/c774af727cd44ab97bd43670e9d9a1bfbe197018.jpeg)  
 ![Arduino ADSR](https://global.discourse-cdn.com/free1/uploads/lookmumnocomputer/original/1X/aeea74e4343d4487d7641b9d3118c61d8d16069f.jpeg)

> **[Signal Processing on the Arduino](http://m0xpd.blogspot.com/2017/02/signal-processing-on-arduino.html)**
>
> I've been doing some DSP on the Arduino Since signal processing is so computationally intensive, we tend to associate it with powerful...

Probably gonna give it a build myself 😃

---

<div class="post-metadata">

### Author: ![Maxhirez](https://yyz2.discourse-cdn.com/free1/user_avatar/lookmumnocomputer.discourse.group/maxhirez/32/42_2.png) [@Maxhirez](https://lookmumnocomputer.discourse.group/u/Maxhirez)
#### Post date: [March 2, 2020, 2:26am UTC](https://lookmumnocomputer.discourse.group/t/arduino-based-adsr/344/2 "2020-03-02T02:26:01Z")

</div>

I spent part of the weekend laying out something very similar! I’m using an ATTiny 84 and an MCP4131 digital potentiometer and it’s more of a function generator like MakeNoise Maths or Buchla 281. Sounds like I’ll want to go with a stateside PCB house (I’m thinking OSH Park.)

---

<div class="post-metadata">

### Author: ![ChristianBloch](https://yyz2.discourse-cdn.com/free1/user_avatar/lookmumnocomputer.discourse.group/christianbloch/32/56_2.png) [@ChristianBloch](https://lookmumnocomputer.discourse.group/u/ChristianBloch)
#### Post date: [March 2, 2020, 3:21am UTC](https://lookmumnocomputer.discourse.group/t/arduino-based-adsr/344/3 "2020-03-02T03:21:03Z")

</div>

JLCPCB is supposedly back to normal, but I guess that doesn’t necessarily include shipping.

---

<div class="post-metadata">

### Author: ![analogoutput](https://yyz2.discourse-cdn.com/free1/user_avatar/lookmumnocomputer.discourse.group/analogoutput/32/29663_2.png) [@analogoutput](https://lookmumnocomputer.discourse.group/u/analogoutput)
#### Post date: [March 2, 2020, 3:24am UTC](https://lookmumnocomputer.discourse.group/t/arduino-based-adsr/344/4 "2020-03-02T03:24:44Z")

</div>

Looks nice, but it seems to me if you’re going to stick a microcontroller in an envelope generator, it should have something more interesting to do than ADSR! ADSR is a decent simplified approximation of some real world envelopes, but no more than that; with a microcontroller on the job, so much more varied and interesting envelopes are possible…

---

<div class="post-metadata">

### Author: ![Caustic](https://yyz2.discourse-cdn.com/free1/user_avatar/lookmumnocomputer.discourse.group/caustic/32/15588_2.png) [@Caustic](https://lookmumnocomputer.discourse.group/u/Caustic)
#### Post date: [March 2, 2020, 5:47am UTC](https://lookmumnocomputer.discourse.group/t/arduino-based-adsr/344/5 "2020-03-02T05:47:15Z")

</div>

I saw that this week! I was wondering to myself if it would need something like an op amp to bring the voltages up. Still unsure whats a good voltage to send for CV. I know 12v is typical for power, but you never know with these things.

---

<div class="post-metadata">

### Author: ![d42kn355](https://yyz2.discourse-cdn.com/free1/user_avatar/lookmumnocomputer.discourse.group/d42kn355/32/273_2.png) [@d42kn355](https://lookmumnocomputer.discourse.group/u/d42kn355)
#### Post date: [March 2, 2020, 7:12am UTC](https://lookmumnocomputer.discourse.group/t/arduino-based-adsr/344/6 "2020-03-02T07:12:28Z")

</div>

This confuses me…  
Can someone maybe explain the Switch here?

 ![switch](https://global.discourse-cdn.com/free1/uploads/lookmumnocomputer/original/1X/bfac737b898a0e0cc04399124f41be0c69bf320c.png)

Also - What is the other jack he has there on the panel (next to the switch) - it isn’t on the schematic lol.

Here is what I’ve got so far, but am not positive about the switch…

 ![ADSRduino DIYLC](https://global.discourse-cdn.com/free1/uploads/lookmumnocomputer/original/1X/90fc7df585f07aa172dd0018a43a6c92bdf912a8.png)

(update on the bottom section - switch is possibly wired incorrectly but I am truly unsure based on the diagram)

 ![bottom half](https://global.discourse-cdn.com/free1/uploads/lookmumnocomputer/original/1X/43c6e0ce977739cf790bfa225efc8f8659b9f51c.png)

(yes… i spent a crapload of time on the thonkiconn jacks and pots… lol)  
 ![lol](https://global.discourse-cdn.com/free1/uploads/lookmumnocomputer/original/1X/fb84fb91741e74f7d43ae46f9601a0ed4ecab03a.png)  
layers… lolol

---

<div class="post-metadata">

### Author: ![sebastian](https://yyz2.discourse-cdn.com/free1/user_avatar/lookmumnocomputer.discourse.group/sebastian/32/39_2.png) [@sebastian](https://lookmumnocomputer.discourse.group/u/sebastian)
#### Post date: [March 2, 2020, 8:15am UTC](https://lookmumnocomputer.discourse.group/t/arduino-based-adsr/344/7 "2020-03-02T08:15:27Z")

</div>

> [@d42kn355](#):
>
> Can someone maybe explain the Switch here?

The switch is for the loop mode.

```auto
const int modePin = 3;
pinMode(modePin, INPUT);

```

It is set to high

```auto
digitalWrite(modePin,HIGH);  

```

but when the switch is closed, the pin is pulled to ground and therefore reads 0 in the check:

```auto
loop_mode=!digitalRead(modePin);

```

Why is it done like this? It seems a little bit backwards, right?  
The reason is noise. When the switch contact is open it can read strange results (the state is unknown because there is nothing there), so switches usually need a kind of pull-up or pull-down resistor to work consistently. Arduino digital pins have an internal pull-up resistor that can be enabled by setting the pin to HIGH (`digitalWrite(modePin,HIGH); ` This way you need less components 🙂

While reading [this](https://www.arduino.cc/en/Tutorial/DigitalPins) page again, I noticed that the proper way to enable the internal pull-up is now to set it as `pinMode(modePin, INPUT_PULLUP);`. I don’t understand if that then also inverts the signal, so LOW then means true? can someone help me here?

---

<div class="post-metadata">

### Author: ![Bitnik](https://yyz2.discourse-cdn.com/free1/user_avatar/lookmumnocomputer.discourse.group/bitnik/32/274_2.png) [@Bitnik](https://lookmumnocomputer.discourse.group/u/Bitnik)
#### Post date: [March 2, 2020, 12:49pm UTC](https://lookmumnocomputer.discourse.group/t/arduino-based-adsr/344/8 "2020-03-02T12:49:24Z")

</div>

From what I know of the Arduino system, I doubt that pinmode call has any effect on the interpretation of the signal. Low and high will still have their original meanings so unless the pin is pulled to ground the internal pull-up will keep it reading high. How those high and low values are interpreted by the software is up to the program logic. If you want something to happen when the switch is closed then check the pin value and perform the action if the value is low.

---

<div class="post-metadata">

### Author: ![Maxhirez](https://yyz2.discourse-cdn.com/free1/user_avatar/lookmumnocomputer.discourse.group/maxhirez/32/42_2.png) [@Maxhirez](https://lookmumnocomputer.discourse.group/u/Maxhirez)
#### Post date: [March 2, 2020, 1:28pm UTC](https://lookmumnocomputer.discourse.group/t/arduino-based-adsr/344/9 "2020-03-02T13:28:19Z")

</div>

That probably ought to be an interrupt, right? 3 can do it on most Arduino I think.

---

<div class="post-metadata">

### Author: ![fredrik](https://yyz2.discourse-cdn.com/free1/user_avatar/lookmumnocomputer.discourse.group/fredrik/32/682_2.png) [@fredrik](https://lookmumnocomputer.discourse.group/u/fredrik)
#### Post date: [March 2, 2020, 1:44pm UTC](https://lookmumnocomputer.discourse.group/t/arduino-based-adsr/344/10 "2020-03-02T13:44:08Z")

</div>

No need for interrupts; he’s just polling the pin after each full ADSR cycle (note the `!` which means “not”, i.e. expression is true if input is low).

> <https://github.com/m0xpd/ADSRduino/blob/master/ADSRduino.ino#L160>

As noted above,

```
pinMode(pin, INPUT); // set pin to input
digitalWrite(pin, HIGH); // turn on pullup resistors

```

is [the pre-1.0.1 way](http://code.google.com/p/arduino/issues/detail?id=246) of saying `INPUT_PULLUP`.

---

<div class="post-metadata">

### Author: ![Maxhirez](https://yyz2.discourse-cdn.com/free1/user_avatar/lookmumnocomputer.discourse.group/maxhirez/32/42_2.png) [@Maxhirez](https://lookmumnocomputer.discourse.group/u/Maxhirez)
#### Post date: [March 2, 2020, 2:04pm UTC](https://lookmumnocomputer.discourse.group/t/arduino-based-adsr/344/11 "2020-03-02T14:04:37Z")

</div>

Is the single zener to GND going to be enough protection? I know most triggers are in the +5 range but Dieter recommends a full clamp on the A-100 diy page. I like interrupts myself to get around debounce issues.

---

<div class="post-metadata">

### Author: ![Bitnik](https://yyz2.discourse-cdn.com/free1/user_avatar/lookmumnocomputer.discourse.group/bitnik/32/274_2.png) [@Bitnik](https://lookmumnocomputer.discourse.group/u/Bitnik)
#### Post date: [March 2, 2020, 2:57pm UTC](https://lookmumnocomputer.discourse.group/t/arduino-based-adsr/344/12 "2020-03-02T14:57:22Z")

</div>

If you were generating audio frequency signals you’d need an interrupt service routine, and even then you’d be running close to the limit of the microcontroller’s capabilities. For generating an envelope CV or reacting to slow human switch flipping, you can get away with busy loops and polling.

---

<div class="post-metadata">

### Author: ![d42kn355](https://yyz2.discourse-cdn.com/free1/user_avatar/lookmumnocomputer.discourse.group/d42kn355/32/273_2.png) [@d42kn355](https://lookmumnocomputer.discourse.group/u/d42kn355)
#### Post date: [March 2, 2020, 4:32pm UTC](https://lookmumnocomputer.discourse.group/t/arduino-based-adsr/344/13 "2020-03-02T16:32:31Z")

</div>

welp… this all just went way above my head… lololol

so uh… do i have the switch right on my DIYLC pictures… lol…

---

<div class="post-metadata">

### Author: ![Maxhirez](https://yyz2.discourse-cdn.com/free1/user_avatar/lookmumnocomputer.discourse.group/maxhirez/32/42_2.png) [@Maxhirez](https://lookmumnocomputer.discourse.group/u/Maxhirez)
#### Post date: [March 2, 2020, 5:13pm UTC](https://lookmumnocomputer.discourse.group/t/arduino-based-adsr/344/14 "2020-03-02T17:13:25Z")

</div>

I can’t really tell, but so long as one pole is going to pin 3 (I think it was) and the other goes to ground you ought to be okay.

---

<div class="post-metadata">

### Author: ![Bitnik](https://yyz2.discourse-cdn.com/free1/user_avatar/lookmumnocomputer.discourse.group/bitnik/32/274_2.png) [@Bitnik](https://lookmumnocomputer.discourse.group/u/Bitnik)
#### Post date: [March 2, 2020, 5:35pm UTC](https://lookmumnocomputer.discourse.group/t/arduino-based-adsr/344/15 "2020-03-02T17:35:06Z")

</div>

Does it do what you expect?

---

<div class="post-metadata">

### Author: ![fredrik](https://yyz2.discourse-cdn.com/free1/user_avatar/lookmumnocomputer.discourse.group/fredrik/32/682_2.png) [@fredrik](https://lookmumnocomputer.discourse.group/u/fredrik)
#### Post date: [March 2, 2020, 5:47pm UTC](https://lookmumnocomputer.discourse.group/t/arduino-based-adsr/344/16 "2020-03-02T17:47:38Z")

</div>

> Is the single zener to GND going to be enough protection?

All Arduino inputs are rated for +VCC+0.5 V = 5.5 V which is higher than a typical 5.1 V zener’s max of 5.1+5% = 5.355 V so should be safe, as long as you don’t fry the zener. Assuming 1/4 W components, the series resistor gives you enough headroom for 10 V and a bit over that.

(the inputs do have built-in clamping diodes too – see [this post](https://lookmumnocomputer.discourse.group/t/1222-tuner-vco-module/16/47) – but they can only handle a milliamp or so, so you’ll need a much larger resistor if you remove the zener).

---

<div class="post-metadata">

### Author: ![d42kn355](https://yyz2.discourse-cdn.com/free1/user_avatar/lookmumnocomputer.discourse.group/d42kn355/32/273_2.png) [@d42kn355](https://lookmumnocomputer.discourse.group/u/d42kn355)
#### Post date: [March 2, 2020, 5:54pm UTC](https://lookmumnocomputer.discourse.group/t/arduino-based-adsr/344/17 "2020-03-02T17:54:27Z")

</div>

i am one of those people who do not build things until I get input lol  
So I do not know yet. 😛

I will probably try this this upcoming week - need to replenish funds and order some parts.

Also - Any idea what Pots I should use? lol

---

<div class="post-metadata">

### Author: ![fredrik](https://yyz2.discourse-cdn.com/free1/user_avatar/lookmumnocomputer.discourse.group/fredrik/32/682_2.png) [@fredrik](https://lookmumnocomputer.discourse.group/u/fredrik)
#### Post date: [March 2, 2020, 6:24pm UTC](https://lookmumnocomputer.discourse.group/t/arduino-based-adsr/344/18 "2020-03-02T18:24:06Z")

</div>

> [@d42kn355](#):
>
> Also - Any idea what Pots I should use? lol

10k is a good default. You can use higher values, but the analog read samples the input by very briefly charging a (tiny) capacitor, so if you go too high it may not charge up properly, and the channels may start affecting each other. The usual fix for that is to add external capacitors.

 ![image](https://global.discourse-cdn.com/free1/uploads/lookmumnocomputer/original/1X/82be5de574a88dea29f34c91eafb915c2234ef9e.png)

EDIT: Added input circuitry.

---

<div class="post-metadata">

### Author: ![antoine.pasde2](https://yyz2.discourse-cdn.com/free1/user_avatar/lookmumnocomputer.discourse.group/antoine.pasde2/32/326_2.png) [@antoine.pasde2](https://lookmumnocomputer.discourse.group/u/antoine.pasde2)
#### Post date: [March 2, 2020, 8:00pm UTC](https://lookmumnocomputer.discourse.group/t/arduino-based-adsr/344/19 "2020-03-02T20:00:41Z")

</div>

I’d go for a 4.7V zener diode to keep the inputs below 5V.

@fredrik, any reason not to use a 15K resistor to keep the current into the protection circuit below 1mA for all voltages between +12V and -12V? What’s the input impedance of the digital inputs?  
You might not even need the zener then, as the builtin protection diodes would be able to handle the current even at 12V.

If you expect possible negative input voltages, and want to keep the resistor small (I’d use at least 1K) an additional schottky or germanium diode in parallel with the zener would do the trick. (Schottky and germanium diodes have a lower forward voltage than regular silicon diodes (forward voltage of zener diodes is not always on the spec sheet, but I suspect it is probably at least as high as regular silicon diodes).

---

<div class="post-metadata">

### Author: ![fredrik](https://yyz2.discourse-cdn.com/free1/user_avatar/lookmumnocomputer.discourse.group/fredrik/32/682_2.png) [@fredrik](https://lookmumnocomputer.discourse.group/u/fredrik)
#### Post date: [March 2, 2020, 9:02pm UTC](https://lookmumnocomputer.discourse.group/t/arduino-based-adsr/344/20 "2020-03-02T21:02:14Z")

</div>

The 5.1 V zener should be ok (unless it 's really slow) and if you expect 5 V it won’t conduct under normal operations, but a 4.7 V should work too, it may just produce a tiny amount of extra heat in the diode 🙂 (if you want to push it, it looks like the logic high threshold is +Vcc×0.6 = 3 V).

Agree that a 15k (or higher) and no zener is likely to be fairly robust. The digital inputs are CMOS gates with very high (“near infinite”) impedance (the Arduino docs say 100M but I suspect they mixed that up with the analog inputs, and I don’t think the AVR data sheet spells it out for the digital inputs.)

(I guess I should do some experiments some day 🤓)

[Next page](https://lookmumnocomputer.discourse.group/t/arduino-based-adsr/344.md?page=2)
