Project 15: Hacking


I have been doing the Arduino Uno Projects for a class and I ran into some trouble with project 15. In the book it wants me to use a sound board which I do not have access to. My professor suggested that I use a cheap pair of earphones instead. I was unsure of how to execute this project because the book does not correlate with what I am trying to do. My idea is to hack a press button that will operate the headphones. I attached a picture of my wiring. If someone could give me feedback on this and point me in the right direction I would greatly appreciate it.


Can you draw out a diagram/schematic? I don't know what that chip is, and I can't see how the headphones are connected to it.

Also, what are the headphones supposed to do when you press the button?

And unless I'm mistaken, that red wire is going to a point on the breadboard that's not connected to anything.

You only have 2 wires going from the arduino to your circuit (pin 2 and Gnd). I see no power getting to anything.

Thank you for your responses and I apologize if I do/say anything that would seem idiotic to you, as I am still fairly new to the arduino system. I truly apologize in advance for any frustration I may cause.

In response to DrAzzy, I attached a diagram of my wiring. The chip that I am using is optocoupler. Also, I decided to strip the wire so I can use both head phones. Also, I attached another pin to the optocoupler so it will read in the serial monitor. To answer you last question about the wire, the red wire connected to pin 2 is my INPUT which is bringing in power through my resistor and into the optocoupler. This is how the book explains it.

In response to KenF, the wire connected to pin to is my INPUT being pulled through the 220ohm resistor to power the circuit. The book does not show anything connected to the 5v and I am getting a reading in my serial monitor when I plug the arduino into my computer power source.

Thank you so much and I look forward to hearing from both of you.

Where did you get this crazy circuit from? There's no way in hell that's ever going to do anything.

I think the sound board does more than you're assuming it does....

So you're driving pin 10 with tone() or analogWrite() right? (tone is more interesting, ofc - analogWrite will always give the same tone) (Just turning it on solid won't do anything; you need changes in the signal getting to the headphones to get audio out).

Buncha problems with the circuit:

  1. Don't use the button like that. First off, if you do it like that, you're just using the Arduino as a tone generator, which is pretty boring. Secondly, although those buttons have 4 pins, on many of the ones that look like that, they're connected in two pairs internally (check with multimeter).

You probably want to set it up so that button causes the Arduino to turn the PWM on pin 10 on and off (there are many examples of this online)

  1. You're using the Opto Coupler wrong. On the arduino side, the input to the optocoupler, you want to connect ground to negative side of the led in the opto, and D10 to positive side.

  2. You have no power or ground, or anything, connected to the headphones. You need a source of power for that side, you need ground connected to one side of the supply. Then power on one (or both) sides of the headphones through a smallish resistor (lower value = louder), and the headphone connected to the collector of opto, ground on emitter. This sort of wiring won't cut it for making nice sound - the right way is to put a bias voltage on ground and so on, but this should get some sound out of it.

  3. You can salvage crap speakers from old computers and other electronic devices. These might make for a better demo.

  4. Headphone wire is incredibly hard to work with, because it's covered with this varnish that's very hard to get off without destroying the wire underneath. If possible, use a socket to plug it into, instead of cutting the wires and trying to solder to that horrid stuff. It's the most unpleasant wire I've had to work with. You should be prepared to check your solder connections with a multimeter, so you can make sure you have an electrical connection; I've often had connections that looked okay but weren't actually a decent connection when working with that stuff.

Okay so I decided to go a little simpler and work up to the headphones. I’m going to hack the push button first and get it to read the push button on and off without having to push it. I have posted my code and a picture of my wiring. I’m still having trouble though. Im getting a reading off 0000 in my serial monitor when I should be getting 0101. Any suggestions?

const int optoPin = 2;
const int pushButtonPin = 10;
int pushButtonValue;

void setup() {
// put your setup code here, to run once:
pinMode(optoPin, OUTPUT);
pinMode(pushButtonPin, INPUT);

void loop() {

digitalWrite(optoPin, HIGH);

digitalWrite(optoPin, LOW);