New Picaxe user please help

Robbie-bob

New Member
I am trying to use an LDR as an input, and have read the analogue switches help sheet etc.
I have run a debug program to find the average max value for a room and a good low value for when the LDR is covered by a hand.
But I am having trouble when it comes to programming. I want it to light an LED when the value reads as below the average room value, but it seems to always read as below the average room value, however high I put the value, so the LED is always lit.
I am using an experimenter board at the moment with an 08M.
Please help!
Thanks
 

Coyoteboy

Senior Member
Post up your code and we'll look to see if we can spot the fault - its probably something you've overlooked.
 

BeanieBots

Moderator
Also worth describing your hardware in more detail.
What value resistor for the LDR/resistor potential divider, if any?
Which pins have what connected. Ideally, a diagram.
Answers to these questions and your code will very quickly find your problem.
 

Robbie-bob

New Member
Thanks,

the code I am using is
Code:
main: 
	readadc 1,b0 
	if b0 < 50 then top
	high 1 
	low 1  
	goto main 

top: 
	high 0 
	low 0
	goto main
I have also tried the codes used in the help sheets. I am using the experimeter board set up in the way it is in the datasheet.
Ultimatly, I want to make the random dice project activate whan a hand it waved over it, changing the light level on the LDR. I am using the experimenter board as, well, an experiment.
 

craig008

New Member
i would suggest putting a pause comand in between high and low. basicly it flashes on and off so fast the human eye can not see it, so you u know the human eye only works at approx 30fps which is why we need to slow mo camerea to do things for us at high speeds so we can slow it dowm to ours speed later and 4mhz its gonna flash faster than 30fps.

when i first got started flashing LEDs was the first thing i did and confused me too so your not the only one.
________
Marijuana indica
 
Last edited:

hippy

Technical Support
Staff member
A useful technique is to use SERTXD to report back to the Programming Editor what is happening -
Code:
Do
  ReadAdc 1,b0
  If b0 < 50 Then
    SerTxd("Input below 50 = ",#b0,CR,LF)
  Else
    SerTxd("Input above 50 = ",#b0,CR,LF)
  End If
Loop
Leave the download cable connected after downloading and press F8; everything sent using SERTXD will be displayed on the screen. The SERTXD's can be moved around code and are very handy for determining if code is executing and what values variables are. They take up space but can be deleted as the code starts to work how it is meant to.
 

craig008

New Member
you beat me to that one hippy, another way or best of all in conjustion with is to use a varible resistor instead of an LDR until is workng as it should
________
Marijuana Trichomes
 
Last edited:

hippy

Technical Support
Staff member
A pot's a very good idea, especially if a program does different things depending upon light level / resistance. There's nothing worse than trying to debug something when the input keeps changing from test to test.
 

Robbie-bob

New Member
I used the SerTxt code, but Im not sure what its telling me.
When I used the code and pressed F8, a new box appeared with loads of data appearing in rows. These rows were shorter if I cover the LDR though.
 

craig008

New Member
you may like to to try 13 and ten in place of the hippys CR and LF respectivly, they should do the same job but i would do it differently to hipp maybe like this

main:
readadc 1,b0
sertxd ("LDR Value = ",#b0,13,10)
if b0 < 50 then top
high 1
low 1
goto main

top:
high 0
low 0
goto main

this will allow you to see what values are actully being read in the the ADC it may be that the value of 50 never gets reached by ur LDR
________
DRUG TESTS
 
Last edited:

Robbie-bob

New Member
The SerText tells me that the LDR value seems to always be 0. Do you know why this might be? On the debug it ranged from about 60 in normal light to 8 when I covered the LDR
 

hippy

Technical Support
Staff member
I used the SerTxt code, but Im not sure what its telling me.
When I used the code and pressed F8, a new box appeared with loads of data appearing in rows. These rows were shorter if I cover the LDR though.
Is this "data" in anyway readable, meaningful or just gibberish ? Don't forget that we are not actually looking over your shoulder and can only second guess what's going on.

If the data is coming in too fast, you may want to add "PAUSE 500" within the loop.
 

Rickharris

Senior Member
I am trying to use an LDR as an input, and have read the analogue switches help sheet etc.
I have run a debug program to find the average max value for a room and a good low value for when the LDR is covered by a hand.
But I am having trouble when it comes to programming. I want it to light an LED when the value reads as below the average room value, but it seems to always read as below the average room value, however high I put the value, so the LED is always lit.
I am using an experimenter board at the moment with an 08M.
Please help!
Thanks
Lacking more information I guess you are not using the LDR as a potential divider but have connected it directly between the supply and the input - is that the case?
 

BeanieBots

Moderator
As you're using the experimenter board, I assume you are using the LDR that is already fitted to it.
A value of 0 suggests that you don't have the LDR linked to the right input.
Which PICAXE are you using.
If it's a 28 type, then the analog inputs are seperate to the digital inputs.
Double check you have a link from the LDR socket tothe analog input 0 socket.
It is labelled ADC0 and is close to the three push buttons.
If you are using an 08M, then 0 is output only and you will have to change your code and which pin you connect to.

Please, please, please always give as much information as possible when posting. We cannot see your setup. We only know what you tell us.
Jeremy has a crystal ball but he seems to be on holiday at the moment.
 

SD2100

New Member
Code looks a bit strange to me, you say that you are using an 08m and you are using pin1 for the LDR input and also using pin1 for output, so what is connected to what ???, if the LDR is connected to pin1 and is very low resistance to 0v then you set pin1 high things could get nasty even more so if you put a pause between high 1 and low 1.
Code:
main: 
	readadc 1,b0 
	if b0 < 50 then top
	high 1 
	low 1  
	goto main 

top: 
	high 0 
	low 0
	goto main
 
Top