Analog Input Question

Hello, I have a few questions on controlling multiple servos (4) by using LEDs (also 4), however I can not control the LEDs. I am using an Arduino Uno and the LEDs are apart of a game and if I make it to a certain level an LED turns on and I would like to use that LED turning on to control a servo motor. I have attempted connecting a wire to each LEDs power line that is connected to an analog input pin, but the results are haywire analog readings that are hard to predict and control. I know I can use photo resistors, but I would like to stay away from that if possible. Anyone have any suggestions? I have attached the code I am using to get the analog input values. I will later be editing the code once I have the input control lined out so that it doesn't just read and output analog into serial monitor.

int gamepin1 = A1; //Gamepin inputs from LEDs int gamepin2 = A2; int gamepin3 = A3; int gamepin4 = A4;

int concentration1; //Labelling for analog output int concentration2; int concentration3; int concentration4;

void setup() { Serial.begin(9600);

}

void loop1() { analogRead(gamepin1); Serial.print("Game input 1: "); delay(1500); Serial.println(analogRead(gamepin1)); concentration1 = analogRead(gamepin1);

}

void loop2(void){ analogRead(gamepin2); Serial.print("Game input 2: "); delay(1500); Serial.println(analogRead(gamepin2)); concentration2 = analogRead(gamepin2); }

void loop3(void){ analogRead(gamepin3); Serial.print("Game input 3: "); delay(1500); Serial.println(analogRead(gamepin3)); concentration3 = analogRead(gamepin3); }

void loop4(void){ analogRead(gamepin4); Serial.print("Game input 4: "); delay(1500); Serial.println(analogRead(gamepin4)); concentration4 = analogRead(gamepin4); }

void loop() { loop1(); loop2(); loop3(); loop4();

}

Stop now and disconnect the LEDs, you can wipe out you Arduino connecting it to unknown voltages.

Once you’ve done that, tell us about the LEDs. What are they? What powers them?

Ultimately, you could possibly do it without LDR’s but you’ve got to provide far more information about the LED’s.

Thanks for the heads up! I'm totally new to it and tried what I figured may work. I know their current is well below 1 A in addition they are running approx. 3 V. there is a series of 5 of them and I'm not sure of anything else I may provide that would be of much help. I hope this helps some though.

Maybe you should think about using an opto-isolator?

4n25 connection-2.PNG

The input and gnd on the left are from your game, and the resistor on the left you add to limit the current in the opto-isolator led.

The gnd on the right is your Arduino gnd, and is not connected to the one on the left. The pullup resistor top-right would most easily be an Arduino built-in one, using INPUT_PULLUP in pinMode.

So your "random" game machine voltage controls the led inside the opto-isolator, and whatever that voltage is, it doesn't get to an Arduino pin. The pullup makes the Arduino pin high until the opto-isolator's leds fires up, at which point that transistor closes and grounds the Arduino pin. So you just digitalRead() that Arduino pin and it mimics your game machine.

(The 4n25 is I believe obsolete, there are newer ones afaik, but I don't know their numbers; you get the idea though.)

Hmm, based on the way you describe it it definitely sounds like what I'm looking for. To make sure I understand you correctly, you mean I could essentially connect the games input and ground and move the led to the opto-isolator or possibly just use the opto-isolator as a channel to output a digital code to control a servo motor? It's a very dumbed down version, but I hope I understood it correctly. I have not dealt with any opt-isolators or heard of them before but if you think I could use them as essentially a switch to control the servo motors I believe it is exactly what I'm looking for. As a side note I'm using the game input as like an on/ off switch for the servo motors if the LED is on the servo will rotate so many degrees and stay until the LED turns off and then it will return to normal. (I've played around and already figured out this pease of the code, but thought it may be of benefit.)

No, don't "move the led" (although I'm not really sure what you mean there ;) ) , and you also can't use the game to directly control the servo (servos need specific well defined control signals.)

What I was thinking was, seeing as you already seem to be able to grab from the game machine to the Arduino , instead take that voltage to the isolator (through a resistor). Then when your existing game machine led goes on or off, so too will the one inside the isolator (which btw you can't see; it's all inside a chip).

The left hand ground on the isolator, goes to the game machine ground.

So essentially the led inside the chip is a duplicate of the one you already have access to, but it in turn is controlling the transistor inside the chip.

Then you read the Arduino pin which has pinMode(pinNum, INPUT_PULLUP); which will vary between high and low depending on what's happening over at the gamer led.

THEN you use that knowledge (of the pin changing from high to low or low to high) inside some logic (probably an "if") to in turn control a servo using servo.write(somePositionOrOther).

The servo library takes care of all the voodoo under the hood; you just tell the servo to go to "45" or "123" degrees or whatever.

Ahh okay I understand what you mean now. I was unsure of the structure or design of the onto-isolator at first, but I understand it better now. The High/Low output from the onto-isolator should work perfectly for what I'm looking for! Do you have any idea where I may find any like the ones you referenced? I don't believe I will need one too sophisticated and really in this case the smaller the better for me.

I got mine at my local brick-and-mortar… But as I said I’m not sure of the latest part numbers.

They are very small. I think (don’t quote me) there may be versions where there are say 4-in-1 on a single chip.

Have a look on Mouser or Digikey.

Also maybe wait an hour or two for other responses here as the time zones change… there may be better ideas than mine.

Sounds great I really appreciate your advice an input. I’ll have a go and see if I can find anything just in case I don’t get any better solutions. However, I’m definitely open to any suggestions!

I was looking online at some things to try and find a solution and learn about the opt-isolators and found a bi-directional logic level converter and was wondering if you thought it might do the trick.

acdavis1999: found a bi-directional logic level converter and was wondering if you thought it might do the trick.

The only ones I've ever seen are between 5V and 3V, and it just struck me that you haven't in any case said what voltage you're dealing with from the gamer system. Maybe we should back up a bit a you should say what that is.