Light sensitive dimmer- Please help!

gbrown74

New Member
I am a new teacher trying to introduce the picaxe to my school. Currently I am trying to help an a-level student build a prototype product. I have used the picaxe years ago but I am struggling to remember and we haven't got much time. I would greatly appreciate any advice on how to make it work.

We are trying to create a switch using some LDR's which will adjust the volume of a buzzer/radio. The idea is to have a line of 3 LDR's, when the hand is stroked over them in one direction the volume goes up, in the other direction down. The script will have to identify a sequential drop in light for each LDR. I have attempted to write a script which I think is ok- Please let me know if not. I also need to find out how to include a greater margin of difference than "<" I am not sure if <b1-10 will work.

main:
readadc 1,b0
readadc 2,b1
readadc 3,b2

variable b0
if b0<b1 then loud
if b2<b1 then quiet
goto main

loud:
if b1<b0 and b1<b2 then louder
else goto main

louder:
(turn volume up gently)
if b2<b0 and b2<b1 then (turn up volume more)
else goto main

quiet:
if b1<b2 and b1<b0 then quieter
else goto main

quieter:
(turn volume down gently)
if b0<b2 and b0<b1 then (turn volume down more)
else goto main


Also how could I use it to change the volume of a radio/stereo. I will use a buzzer if it is too complicated.
 

lanternfish

Senior Member
You probably only need two LDR's to sense the direction of the hand movement. This will simplify your code.

There is a motorised pot available relatively cheaply. The motor could be driven via and H-bridge and the pot wired in as the volume control pot.
 

boriz

Senior Member
Yep. Two LDRs. You read them just like a quadrature encoder.

You can simply use the SERVO command with servo-velcro-volume control coupling.
 

Andrew Cowan

Senior Member
You can simply use the SERVO command with servo-velcro-volume control coupling.
To expand on that, it consists of mounting a servo to the volume knob using velcro.

As the servo turns, gravity pulls it vertical, which moves the knob, thus changing the volume.

A
 

boriz

Senior Member
Simple answer is ... "Well you tell me. Does it work?". I'm a big fan of experimental iteration.

What you are describing is very much like an ‘optical incremental rotary encoder’. Just make sure that you place the LDRs close enough together that at some point they are both shaded when a hand passes over.

Some food for thought:

http://abrobotics.tripod.com/Ebot/using_encoder.htm

http://engknowledge.com/rotary_optical_incremental_encoder.aspx

http://www.********.com/forum/index.php?topic=12805.0

Note. Most of this info relates to digital inputs, but you can easily apply it to the sort of analogue signals you will get from LDRs.

A while ago, I derived my own routine to decode quadrature from a hacked mouse encoder. See: http://www.picaxeforum.co.uk/showpost.php?p=96949&postcount=4

Maybe you can adapt that.
 
Top