Circuit Troubles

can phototransistors also be known as resistors

No a photo transistor and resistor are two different thing. Also a photo transistor and a photo resistor are two very different things.

is there anything particularly wrong with the code?

Yes the photo transistor is never read, that line is commented out.

I have been thinking about this and your best bet is to swap the resistor and photo transistor round like I said. Use a 100K resistor and connect it to an analogue input, say A0.
Then read it with a line
eye = analogRead(0); // set eye to the light value we "see"
Serial.println(eye); // look at the value
Then try it and look at the range of numbers you get when you cover the light. Pick a number in the middle of this range and assign it to a variable call threshold at the start of your code. For example if 200 is the middle number you would put:-
int threshold = 200; Then remove the Serial.println(eye); line.
Just before the void setup();
Then change the line:-
if (eye) {
to
if ( eye < threshold ) {

@Grumpy Mike,
still having difficulties understanding your antipathy towards what, to me, looks to be a perfectly mathematically-correct inversion.

Would you be happier if it were written:
eye = (HIGH + LOW) - digitalRead(sensorPin);     ?

(not trying to make a mountain out of a molehill)

looks to be a perfectly mathematically-correct inversion.

Yes it does produce a result. My problem with it is that is just making something a lot more complicated than it needs to be and at the same time shows that the writer of it doesn't know what they are doing. If it were me I would have simply put:-
eye = digitalRead(sensorPin);
And then when I used it put:-
If(!eye) {
Well actually if it were me I would have wired up the sensor correctly and so there would have been no need to invert it anyway. :slight_smile:

Grumpy_Mike:

can phototransistors also be known as resistors

No a photo transistor and resistor are two different thing. Also a photo transistor and a photo resistor are two very different things.

Okay, thank you for that explanation :).

Grumpy_Mike:

is there anything particularly wrong with the code?

Yes the photo transistor is never read, that line is commented out.

I have been thinking about this and your best bet is to swap the resistor and photo transistor round like I said. Use a 100K resistor and connect it to an analogue input, say A0.
Then read it with a line
eye = analogRead(0); // set eye to the light value we "see"
Serial.println(eye); // look at the value
Then try it and look at the range of numbers you get when you cover the light. Pick a number in the middle of this range and assign it to a variable call threshold at the start of your code. For example if 200 is the middle number you would put:-
int threshold = 200; Then remove the Serial.println(eye); line.
Just before the void setup();
Then change the line:-
if (eye) {
to
if ( eye < threshold ) {

So, from my understanding of your posts, I will need to produce one of the following circuits? Please excuse the crude drawings! :slight_smile:

(Version 4)

(Version 5)

Please note that on the Version 4 drawing, the positive from the RGB LED is to go to the positive on the LiPo board (left-most board).

It is almost impossible to follow something like that but it does look wrong.
Where is the 56R resistor, it wasn't on the original schematic from the first post. I can't make that bit out. It seems to say on the photographs emitter positive and emitter negative. An emitter is the name of one of the pins on a transistor so it does not make much sense.

The photo transistor circuit is also wrong. The junction of the 100K resistor and the photo transistor should go to the arduino with the other end of the 100K going to +5 and the other end of the photo resistor going to ground.

Grumpy_Mike:
It is almost impossible to follow something like that but it does look wrong.
Where is the 56R resistor, it wasn't on the original schematic from the first post. I can't make that bit out. It seems to say on the photographs emitter positive and emitter negative. An emitter is the name of one of the pins on a transistor so it does not make much sense.

The Emitter circuit drawn above is exactly the same as before (although admittedly I have made a mistake on the Version 5 drawing - the resistor connected to the Emitter should be a 56R (ohm) not a 56K).

Should I keep the Emitter circuit as it is at the moment? GND >> Emitter >> 56R >> Pin 6?

Grumpy_Mike:
The photo transistor circuit is also wrong. The junction of the 100K resistor and the photo transistor should go to the arduino with the other end of the 100K going to +5 and the other end of the photo resistor going to ground.

Right okay, thank you for clearing that up :). When you say "should go to the arduino", do you mean the "a0" pad you mentioned in your previous post?

do you mean the "a0" pad

Yes.

Are you using the word 'emitter' to mean LED? If so then are you sure that 56R does not exceed the maximum current of 40mA of the arduino output pins. Even 40mA will damage the arduino if you run it for too long.

Grumpy_Mike:

do you mean the "a0" pad

Yes.

Are you using the word 'emitter' to mean LED? If so then are you sure that 56R does not exceed the maximum current of 40mA of the arduino output pins. Even 40mA will damage the arduino if you run it for too long.

Okay thanks.

The "Emitter" is an IR Emitter...I assume it's also known as an LED? :~. I'm not sure....I assumed that 56R would be harmless as it's a lot lower than 10k? :~. Is the current setup of the IR Emitter correct for it to work or will I also need to reposition this? How long is "too long"?

The Instructable I am working from states that I needed a 10KOhm and a 56Ohm resistor. Full details can be seen here: http://www.instructables.com/id/Arduino-Lilypad-Interactive-Passion-Sensing-Scarf

....I assumed that 56R would be harmless as it's a lot lower than 10k?

That's a really bad assumption if the resistor is acting as a current limiter.
Whilst 10k may be too high to allow enough current to flow to light a LED, at least it won't cause damage, but 56R may be too low, allowing too much current to flow, potentially damaging both the output and the LED.

AWOL:

....I assumed that 56R would be harmless as it's a lot lower than 10k?

That's a really bad assumption if the resistor is acting as a current limiter.
Whilst 10k may be too high to allow enough current to flow to light a LED, at least it won't cause damage, but 56R may be too low, allowing too much current to flow, potentially damaging both the output and the LED.

Do you have any suggestions as to what may be a suitable resistor value please? :slight_smile:

You need to know the current limit of your LED and the voltage it drops when on. Form this you can work things out properly.
If you don't know what these are then do not go lower than 100R.

The Instructable I am working from states that I needed a 10KOhm and a 56Ohm resistor.

From the Instructable it says:-
The emitter and detector each get hooked up from POWER to RESISTOR to LILYPAD PIN to IR LED to GROUND.

You are wiring your LED up to an output pin of the arduino. That means the current will come from the arduino pin not direct from the battery! It is fine if you wire it up like it is described in the Instructable with a 56R resistor but NOT if you source the power through an arduino pin.

Grumpy_Mike:

The Instructable I am working from states that I needed a 10KOhm and a 56Ohm resistor.

From the Instructable it says:-
The emitter and detector each get hooked up from POWER to RESISTOR to LILYPAD PIN to IR LED to GROUND.

You are wiring your LED up to an output pin of the arduino. That means the current will come from the arduino pin not direct from the battery! It is fine if you wire it up like it is described in the Instructable with a 56R resistor but NOT if you source the power through an arduino pin.

The problem is, that setup is what I had in the first place and the circuit didn't work (see picture below).

I'm completely confused as to how this circuit is meant to be wired if it is to actually work, as the instructable instructions appear to be completely wrong, at least according to the results I have gathered from the above setup.

I will hopefully be sourcing a number of 100K resistors tomorrow so will try your suggestion with the analog pin.

As for the Emitter (IR LED), I am still unsure of how to set it up. Directly from the IR Emitter LED Datasheet from Rapid:


The entire datasheet for the Emitter can be downloaded from: http://www.rapidonline.com/netalogue/specs/58-0442.pdf

As for the Emitter (IR LED), I am still unsure of how to set it up

The way the Instructable has it wired up will damage your arduino, I have just put a note on the site to warn people.

Take the code from the site again as you have messed up your code and make this change:-
eye = 1 - digitalRead(sensorPin); // set eye to 1 if we "see" any IR light
should become:-
eye = digitalRead(sensorPin); // set eye to 1 if we "see" any IR light

Then wire it up as shown in this circuit.

LiliPad circuit.png

Grumpy_Mike:

As for the Emitter (IR LED), I am still unsure of how to set it up

The way the Instructable has it wired up will damage your arduino, I have just put a note on the site to warn people.

Take the code from the site again as you have messed up your code and make this change:-
eye = 1 - digitalRead(sensorPin); // set eye to 1 if we "see" any IR light
should become:-
eye = digitalRead(sensorPin); // set eye to 1 if we "see" any IR light

Then wire it up as shown in this circuit.

I see. No wonder the guy that made the Instructable wasn't returning my messages then, he'd probably received quite a few regarding this problem!

Thank you very much for the advice and also for the clear diagram and code. I will be sure to try this out tomorrow when I'm a little more awake :wink: :slight_smile:

KugarWeb:

Grumpy_Mike:

As for the Emitter (IR LED), I am still unsure of how to set it up

The way the Instructable has it wired up will damage your arduino, I have just put a note on the site to warn people.

Take the code from the site again as you have messed up your code and make this change:-
eye = 1 - digitalRead(sensorPin); // set eye to 1 if we "see" any IR light
should become:-
eye = digitalRead(sensorPin); // set eye to 1 if we "see" any IR light

Then wire it up as shown in this circuit.

I see. No wonder the guy that made the Instructable wasn't returning my messages then, he'd probably received quite a few regarding this problem!

Thank you very much for the advice and also for the clear diagram and code. I will be sure to try this out tomorrow when I'm a little more awake :wink: :slight_smile:

Okay, I've managed to get the circuit up and working, but the RGB is now changing straight to red and will not change colour even after covering the Phototransistor or moving the IR LED and Phototransistor apart.

The instructable states that the RGB should change from blue to red depending on the proximity of the IR LED. I assume this is a problem with sensitivity which I need to adjust within the code?

Okay, after a quick bit of playing around, the only way I can get one device to work is if I touch the two legs of the Phototransistor together, which changes the RGB to blue, then if I let the legs come apart again, the RGB changes back to red.

I'm not quite sure what this means, however. Is the signal too strong for the Phototransistor? Or, do I need to find a matched pair of Phototransistor and Emitters and fit them in opposite circuits?

Bear in mind this is only a prototype and I'll be happy if only two devices work against each other :).

EDIT: Would something like 2 sets of these do? :~ http://www.rapidonline.com/productinfo.aspx?tier1URL=Electronic-Components&tier2URL=Optoelectronics&tier3URL=Infrared-Devices&tier4URL=Matched-T1-infrared-emitter-and-phototransistor-pair&moduleno=29405

EDIT 2: Okay, so to test something out I removed the Emitter from one of the devices (the other device was switched off) and the Phototransistor was still detecting IR light, even when in a dark, secluded room. After this, and to ensure that the red light was not on constantly and was actually working using the IR light detection, I removed the Phototransistor from the circuit. After removal of both of the components from one device, the RGB LED did indeed glow blue. This leads me to believe that there is either a fault with the Phototransistor itself or with the detection code. Any ideas? :slight_smile:

OK now to plan B, like I said before:-
Connect your photo transistor not to pin 5 but to analogue input 0 (sorry don't know the pad number)
Then change this line of code:-
eye = digitalRead(sensorPin);
to
eye = analogRead(0); // set eye to the light value we "see"
Serial.println(eye); // look at the value
and finally change:-
if (eye) {
to
if (eye < 1000) {

Now run the code and see what numbers you get out of your sensor. Change the 1000 in the last line to a value between the maximum and minimum numbers you get or adjust it until it is as sensitive as you like.
Off for the weekend, catch up on Monday.

Grumpy_Mike:
OK now to plan B, like I said before:-
Connect your photo transistor not to pin 5 but to analogue input 0 (sorry don't know the pad number)
Then change this line of code:-
eye = digitalRead(sensorPin);
to
eye = analogRead(0); // set eye to the light value we "see"
Serial.println(eye); // look at the value
and finally change:-
if (eye) {
to
if (eye < 1000) {

Now run the code and see what numbers you get out of your sensor. Change the 1000 in the last line to a value between the maximum and minimum numbers you get or adjust it until it is as sensitive as you like.
Off for the weekend, catch up on Monday.

Excellent! :D. It is now working as it should and I just need to make a couple of tweaks to the sensitivity and it'll be perfect :). Thank you so much for your help Grumpy_Mike! I'd still be banging my head against a brick wall I think XD.