What am I doing wrong with this wiring?
January 3, 2014 12:53 AM   Subscribe

I am playing with an animatronic toy I got from a thrift shop. Before I started trying to hack it, there was a rocker switch that when pressed in one direction, made the head turn left, and when pressed in the other direction, made the head turn right. I have hooked this up to my arduino by replacing the switch with transistors, but the head now will only turn right. Without knowing exactly how the circuit board inside the toy works, is there enough information to figure out what I'm doing wrong?

This is an attempt to map out what the wiring looked like before I started fiddling with it. I'm pretty sure the motor is a motor rather than a servo, as there are only two wires going to it (with a resistor and a bunch of capacitors on each).

I don't really know what the circuit board does, but I don't want to disconnect it and control the motor directly, because (a) I have no other motor drivers and (b) the circuit board also makes the dinosaur roar and its eyes flash when its head turns. Those are on separate wires coming off the circuit board that have no direct interaction with the motor/switch thing, so I haven't represented them in my diagram.

This diagram is what I've done to replace the switch with my arduino (i.e it equates to just the left side of the previous diagram). I'm kind of just guessing that this is the correct approach, so please tell me if it is laughable. In case my drawing is hard to interpret, I snipped the green, red and white wires off the switch. I then put a PN2222A transistor between the green wire and the red wire, and another one between the white wire and the (same) red wire. I connected a 1k resistor to the middle leg of each transistor, and then connected them each to a different arduino pin. I put another wire connecting each of the green wire and the white wire to the common ground pin of the arduino.

I also have no idea about the specs of the motor or anything, so I'm kind of just guessing at what would be appropriate resistors and transistors and so on. Please let me know if I've chosen stupidly.

The problem is that when I send a "HIGH" signal to either pin of the arduino, the motor turns the same direction. I would have expected it to turn one direction when I send HIGH to one pin, and the other direction when I send HIGH to the other pin.

If we assume that I have wired everything up correctly (i.e. no short circuits, the transistors the right way around, and it does actually match what I've sketched out here), am I doing something else obviously wrong?

I know about the arduino forums, by the way, but I don't think this is an arduino-specific problem, necessarily, so I thought I'd try here first.
posted by lollusc to Technology (10 answers total)
Response by poster: Damn, those links don't work properly. The two images are now at this link.
posted by lollusc at 12:56 AM on January 3, 2014

Diagram and description omit too much info to be of much use.

I presume you have a meter?

If I were debugging this, the first thing I'd assume is that I did something wrong with the transistor drivers. Thus, they'd come off and the switch would go back on. You need to know it's all still OK, and you need to get some operational data.

Using the meter, see what happens to the pins on the switch when you run the motor both ways. You need to know what they all do. The motors eventually stop, I am sure. This means there is a mechanism for doing the stopping. You need to figure out what it is.

Motors can run on various voltages. Transistors have voltage drops and other limits. If I were DESIGNING a circuit as opposed to hacking one, I'd use a specific topology to accomplish what you are trying to do. But this is a hack, not a design. You've got the cart before the horse here. You need to understand what is happening in the circuit before you design something to manipulate it.

I suspect a number of things. I could speculate all day, though. Data will shorten than a lot.

I also suspect you can get a couple of sensitive relays with NO contacts and wire up a switch substitute. Relay contacts will work in ways transistors can't, just because of the physics.

Get some data on what happens to the switch pins and post it. Guidance will be forthcoming from many folks here. Before long, you'll have it working.
posted by FauxScot at 1:30 AM on January 3, 2014

Response by poster: Okay, so I did fiddle around with a meter and the switch and so on before I started pulling it apart. I didn't write down anything, though, and that was a couple of days ago now. I thought I understood the circuit at the time, but a bunch more things I discovered later suggested my understanding was incorrect. Do you really think the only way to understand this is to rewire the switch back on? I really suck at soldering and I finally got all the bits soldered together well. The idea of cutting them off and redoing it makes me very sad.

I am pretty sure the transistors are wired up correctly (what do you mean by "transistor drivers"? I really am a noob, sorry!) I tested each one of them individually before soldering the whole thing together. I.e. I wired just one transistor to the green wire, arduino pin, and red wire, with a wire from green to ground, and sent "HIGH" to this. The motor turned left. Then I disconnected that and wired one to the other pair of wires, and sent "HIGH" to it and the motor turned right. I connected both of them and I thought that it was all working fine on the breadboard with it turning left for one and right for the other. But then I soldered it all together and now it only turns right, and I'm not 100% sure it wasn't doing that all along and I just missed it.

I wondered whether it was wrong to have wired the red centre wire to both transistors at the same time (but I also figured that if I was only sending power to one of them at a time, then it should be fine).

The switch is spring-loaded and returns to a neutral middle position automatically. That is when the motor stops. Otherwise it does continue.
posted by lollusc at 1:43 AM on January 3, 2014

Response by poster: Also, when I first cut the three wires off the switch, I found that connecting red to green (directly) made the head turn one direction and connecting red to white made it turn in the other direction. So I assumed it was kind of irrelevant what was ACTUALLY going on with the circuit: I just needed to create (using my Arduino) a way to connect the red wire to either the green or to the white (as the switch had been doing). Hence the plan to use transistors.
posted by lollusc at 1:46 AM on January 3, 2014

Response by poster: Oh my god, it is weirder than I had thought.

If I set either of the Arduino pins to HIGH very briefly (less than 1 second), there seems to be an equal chance that the motor will revolve left or right. (No matter which one I set to HIGH.) If I set it to HIGH for longer, it will always revolve right. No wonder I thought it was working fine on the breadboard and when just touching the wires together - I was always doing it for a very brief amount of time.

I guess I am going to have to start from scratch again and undo it all and put the switch back on. But it's going to take me longer than I have tonight, so I'll try it tomorrow. Meanwhile any other thoughts, or suggestions on what I should measure and what those measurements will tell me, are very welcome.
posted by lollusc at 2:06 AM on January 3, 2014

Are you sure about where your ground is going?

This may very well be a dumb suggestion, but should the ground not be on your red wire?
posted by Just this guy, y'know at 2:12 AM on January 3, 2014

Response by poster: Okay, because I am unable to leave it alone, I did snip off my wiring and put the switch back on. I put my multimeter across the white and red wires, and it read 35.9 microA. Across the green and red wires it read the same. Across the white and green wires it read 0.

I have no idea what that tells me, though.

As before, flipping the switch one direction makes the head turn one way; the other direction makes it turn the other way, as expected. Also, as before, directly connecting green to red makes it turn one way; directly connecting red to white makes it turn the other.

I also played around briefly with a relay on the breadboard. I connected it the same as the switch had been, but of course there is no equivalent of the central "neutral" position, so the motor turns no matter what. But it always turns the same direction whether the relay is powered or not, whereas I would have expected it to turn one direction when powered and the other when not.

As for Just this Guy's suggestion: I don't know for sure that my ground was connected correctly. I thought so, but I can't easily test it now I've snipped all that wiring off. (I can probably only manage to connect it up one more time now, as the wires get shorter every time I cut and reconnect them.) Would that mistake have caused the weird behaviour I was getting?
posted by lollusc at 2:45 AM on January 3, 2014

Best answer: I think you are taking the right approach trying to replicate the switch going into the board.

My thinking was that by connecting the Green and White to ground you are essentially connecting them together, so that when one goes high the other will also go high.
This would have the effect of sending odd signals to your board and could cause the motor to go either way.
posted by Just this guy, y'know at 2:50 AM on January 3, 2014

Response by poster: Oh my. You are genius, sir! I can't believe I didn't realise that myself. I have breadboarded it back up with ground coming off red instead, and it works perfectly. (Of course, it seemed to work on the breadboard earlier too, but I have tested it more thoroughly this time, and I am cautiously optimistic.) Now I can finally go to bed and I will solder it back together tomorrow.

My robotic dinosaur overlord salutes you.
posted by lollusc at 4:47 AM on January 3, 2014 [3 favorites]

I am phenomenally delighted to have helped.
posted by Just this guy, y'know at 6:20 PM on January 3, 2014

« Older Books with shameless cheating   |   How do I brush this cat? Newer »
This thread is closed to new comments.