Weird programming error

jadesteffen

New Member
I'm learning how to progam the picaxe, and I just built a simple circuit. it has one light sensor on input 1, and one led on output 4. I typed in my code and downloaded it. The led remains off. I bring it under ythe light and its still off. then i unplug the serial cable and all of a sudden the led turns on?! please help!


heres my code:

symbol res=b1

loop:

readadc 1,res

if res>100 then ledon
if res<100 then ledoff



goto loop


ledon:

High 4

goto loop

ledoff:

low 4

goto loop





Edited by - jadesteffen on 9/29/2005 9:28:31 PM
 

womai

Senior Member
Which Picaxe are you using? If it is a 28X then input pin 1 and ADC 1 are two different pins. You need to connect the sensor to ADC 1.

Try using "sertxd" or "debug" to print the values that you read.

Wolfgang
 

ylp88

Senior Member
What is your light sensor like? Is it like a voltage divider with an LDR as one of the resistors?

ylp88
 

hippy

Technical Support
Staff member
[ Realised you said the problem is when you have the cable plugged in ]

When you unplug the serial cable in, does the LED stay on permanently, or does it go on and off depending upon light level ( ie, works as it should ) ?

I would suggest writing a small program that just flashes the LED on and off which you can run to get a better idea of what is happening. That will remove any problems which might be associated with the READADC or your sensor ...

- MainLoop:
- TOGGLE 4
- PAUSE 500
- GOTO MainLoop

Check if it works both with and without the serial cable connected.

Edited by - hippy on 9/30/2005 3:19:28 AM
 

BeanieBots

Moderator
Sounds like download cable interfering with adc which is cured by using the "enhanced download circuit". Try adding a schottky diode to the serin pin to clamp negative voltages. Alternatively, put any old diode in series between PC and download circuit. (pointy end towards 22k resistor).
Also do the obvious checks such as correct series resistor value for your light sensor.
 

jadesteffen

New Member
@ylp88:

Im simply using an Cad-sulfide photo cell
between input 1 and +6v
Should I be using a volatge divider??

@hippy:

when the cable is unplugged, the led stays on regardless of light level

I tried your code and it works with and with out the cable in.

@BeanieBots

I put a diode(pointy end = blackband right?) between pin 2 of the serial cable and the 22k resistor, but it still dosen't work.

What do you mean by "correct series resistor value"?


Edited by - jadesteffen on 9/30/2005 8:18:04 PM
 

manuka

Senior Member
Suspect part of the problem is the direct connection - use a voltage divider! Very approx. this voltage divider resistor should be the same value as your LDR when at the &quot;Illumination of interest&quot;. Typically 10k will do, but experiment! See a similar NTC setup pix <A href='http://www.picaxe.orcon.net.nz/picnksm.jpg ' Target=_Blank>External Web Link</a>. That diode idea is only really needed for fine work I've found. Stan
 

manuka

Senior Member
It's hence your hookup wiring- IS EVERYTHING CRUCIAL IN PLACE!? Maybe also some program oversight? Stan
 

BeanieBots

Moderator
I mean the resistor in series with your sensor. The sensor and the resistor must form a potential divider as pointed out by Stan.
If you use the &quot;enhanced download circuit&quot; AND the 10k resistor, I can think of no reason why it should not work.
I am not familiar with the exact type of sensor you have. What sort of voltages do you get for light and dark when the 10k resistor is fitted?
 

hippy

Technical Support
Staff member
Two things to try ( one already suggested ) ...

User SERTXD and the Programming Editor Terminal to see what values you are reading from the sensor -

- MainLoop:
- READADC 1,b0
- SERTXD(#b0,CR,LF)
- PAUSE 1000
- GOTO MainLoop

And temporarily replace the sensor with a 10K potentiometer wired across +V/0V with its wiper to the ADC pin.

You can also put a multimeter from 0V to the ADC input to check that the voltage being delivered there is what's expected and to see if it does change drastically when the serial cable is plugged-in or removed.
 

hippy

Technical Support
Staff member
It should still work that way ( providing there's also a pull-down resistor from the ADC pin to 0V ), all that will happen is that the value read will change in the opposite direction than if it were connected between that ADC pin and 0V.
 

jadesteffen

New Member
Thank you all. I finaly figured it out! I forgot the pull-down resistor?!
Sorry, as i said I'm a newbie to electronics.
It works fine now
 
Top