Hi, everyone - first post so forgive me if I'm maybe in the wrong forum.
I'll explain what I'm trying to achieve. I have an utrasonic range sensor (HC-SR04) and wanted to use it to control the output volume of a guitar before it goes into my ampllifier.
Given that I only have limited components available, one of which was an LDR, I came up with the attached (crudely drawn) circuits.
It's actually really simple and works, to an extent, but there are some problems.
Let me explain the setup here, I'm testing this on breadboard before I go all-out and build this into my project strat.
We have two small circuits, the first is just two 1/4 inch input jacks, back to back. The ground of each are connected on the breadboard with nothing in between. The 'live' of the guitar has an LDR in series, this is what should control the volume or output of the guitar.
The second circuit is just the sensor connected to 5V and the UNO (it's actually a Freenove v4 clone, great little board), I also have an LED (blue) coming from pin 3 of the board, the idea is that the closer my hand is to the sensor the dimmer the LED gets, this controls the LDR and subsequently the output volume.
Results...
So it works, I had to create a small enclosure for the LED and LDR to omit ambient light, but it works! The problem, the biggest problem, is that when the intensity of the LED changes I get a slight electrical buzz from the amp which intensifies with the brightness of the light, this only happens while the light is changing intensity. Both of the circuits are isolated but naturally, the LDR and LED are enclosed in close proximity, is this potentially the cause? There's definitely some interference there and I'm wondering how I could maybe filter this out, it's quite noticeable.
The second issue, which isn't so bad but still - even the the LED is completely off, I can still hear a very faint output from my amp, it needs to be up quite loud but it's there.
The way this is working is the sensor will drop the LED intensity to 0 if the sensor detects anything <= 5 cm away, from there we have a range of 20 cm to control the volume - if we hold our hand 25 cm away or greater we get 255 (max) output, if we're at exactly 5 cm we get 0, and there's everything else in-between.
As I say, this works to a fashion, if I could filter out that pesky buzz and maybe figure out how to really drop the output signal it'd be great. What I don't want to do is process the guitar signal via the board, I'd prefer to keep that isolated, no processing other than volume control.
Much obliged and hope this all makes sense - apologies for my crude schematic but it's a fairly simple concept.
EDIT: Just thought I should add, my mistake - I neglected to include the 220 ohm resistor in series with the LED, but it's there. If it helps I can take a picture of the breadboard but it's not pretty - if there's a way I can upload video I could post a demo of it in action althought I'd be using my phone, not great.
The code I have is fine and I intend to re-factor, it's not relevant to the obvious buzzing problem but I'm happy to post it if it helps. I've tried a few things, adding caps in various configurations, tried the LDR in series with ground as opposed to live - kinda guessing at this stage so any input or even suggestions on how to better achieve this would be appreciated.