A light seeker using the Velleman K8055 interfacing board

Seeking the light

Setup

A long time ago - in fact in the days when the BBC micro was still the latest thing in computer technology - Fischer Technik produced a computerized buggy, which was widely used in education. The little light seeker on the left was one of the projects suggested in the handbook. The project uses a geared motor connected to a vertical spindle on which is mounted a simple LDR.

There is also a micro switch mounted in such a way, that it is activated twice for every turn of gear shaft. The activator is the little red drum on the the same axle as the worm gear on the left.

This handy little addition enables the programmer to predict the position of the motor. For instance, in my set-up, a complete rotation of the shaft  produces 40 pulses.

The motor is connected via my two-motor controller described elsewhere in these pages to the Velleman K8055 board. The switch is connected to digital input 1 and the LDR is connected to  analogue input 1. The complete setup is shown below on the right.

The complete systemA word of warning here. The two internal potentiometers are still connected to the analogue inputs even when the internal link is disconnected. This affects the sensitivity of the ADC. My program allows you to monitor the brightness of the surrounding. Adjust the top potentiometer for the best reading.




Below on the left is shown a sneaky way of getting the 5V supply for the LDR, which obviously has to be connected to the analogue input via a voltage divider. I took my supply from the five volt pins which supply the internal voltage for the analogue inputs.

On the right is the circuit diagram of the system.

The diagram
 

Getting 5 Volt

The program

The program allows you to point the LDR to any convenient point - i.e. the darkest point in the room. You do this by using the keys 1,2 and 3 as left, right and stop. The number of pulses is displayed as well as the amount of the LDR. This can vary from 0 (bright) to 255(dark). Adjust the little potentiometer for best results.

Pressing 'A' will switch to automatic. The LDR will rotate full circle whilst measuring the light level and counting the pulses from the switch. It will then turn back and stop. It should now be pointing at the brightest part of the room. This is not a continuous process, if the light level changes nothing more will happen until you press 'A' again.

Below is an archive with the program file and an executable, should you not own BB4W.

light_seeker_files.zip

Here is a link to the YouTube video of the project



      10
   20 REM Lightseeker
   30 REM Version 2.0
   40 REM Point towards the light
   50 REM Jochen Lueg
   60 REM Limavady, January 2012
   70
   80
   90 PROCK8055_init
  100 SYS K8055_CloseDevice%
  110 SYS K8055_OpenDevice%,0
  120 ON ERROR PRINT REPORT$;"  ";ERL :SYS K8055_ClearAllDigital%:SYS K8055_CloseDevice%:STOP
  130 PROCinit
  140 COLOUR 128
  150 CLS
  160 COLOUR15
  170 REM
  180 REM Digital output 5 for On/Off, 6 for left right
  190 REM Digital input 5 pulses as motor turns
  200 REM
  210 REM   Analogue 1  bright = 0   dark = 200
  220 PRINT
  230 PRINT
  240 PRINT"  1 ...............  Left"
  250 PRINT"  2 ...............  Right"
  260 PRINT"  3 ...............  Stop"
  270 PRINT
  280 PRINT"  C ...............  Reset counter"
  290 PRINT"  A ...............  Search light"
  300 PRINT
  310 PRINT"  S ...............  Leave program"
  320
  330
  340 REPEAT
  350   K$=INKEY$(0)
  360   IF K$="C" OR K$="c" Count%=0
  370   IF K$="1" PROCturn_motor(1)
  380   IF K$="2" PROCturn_motor(2)
  390   IF K$="3" PROCturn_motor(0)
  400   IF K$="a" OR K$="a" PROCauto
  410   PROCread_ports
  420 UNTIL K$="S" OR K$="s"
  430
  440 SYS K8055_ClearAllDigital%
  450 SYS K8055_CloseDevice%
  460 END
  470
  480
  490 DEFPROCturn_motor(m%)
  500
  510 IF m%=1 THEN
  520   SYS K8055_SetDigitalChannel%,5
  530   SYS K8055_ClearDigitalChannel%,6
  540   PRINTTAB(2,13)"Motor turning left "
  550   M$="left"
  560 ENDIF
  570
  580 IF m%=2 THEN
  590   SYS K8055_SetDigitalChannel%,5
  600   SYS K8055_SetDigitalChannel%,6
  610   PRINTTAB(2,13)"Motor turning right"
  620   M$="right"
  630 ENDIF
  640
  650 IF m%=0 THEN
  660   SYS K8055_ClearDigitalChannel%,5
  670   SYS K8055_ClearDigitalChannel%,6
  680   PRINTTAB(2,13)"Motor stopped      "
  690   M$="stop"
  700 ENDIF
  710
  720 ENDPROC
  730
  740

750 DEFPROCread_ports
  760 SYS K8055_ReadDigitalChannel%,1 TO Pulse%
  770 IF Pulse%=1 AND Flag%=0 THEN
  780   IF M$="right" Count%+=1:Flag%=1
  790   IF M$="left" Count%-=1:Flag%=1
  800 ENDIF
  810 IF Pulse%=0  Flag%=0
  820 SYS K8055_ReadAnalogueChannel%,1 TO Light%
  830 PRINTTAB(2,15);Count%;"    ";"    ";Light%;"    "
  840 IF M$="right" AND Count%>40 Count%=0
  850 IF M$="left" AND Count%<0 Count%=40
  860 ENDPROC
  870
  880
  890 DEFPROCauto
  900 LOCAL Bright%,Pos%
  910 Bright%=255
  920 Count%=0
  930 PROCturn_motor(2)
  940
  950 REPEAT
  960   PROCread_ports
  970   IF Light%<Bright% Bright%=Light%:Pos%=Count%
  980 UNTIL Count%>39
  990 PROCturn_motor(0)
 1000 IF Count%<>Pos% THEN
 1010   PROCturn_motor(1)
 1020   REPEAT
 1030     PROCread_ports
 1040   UNTIL Count%=Pos%
 1050   PROCturn_motor(0)
 1060 ENDIF
 1070 ENDPROC
 1080
 1090
 1100 DEFPROCinit
 1110 SYS K8055_ClearAllDigital%
 1120 M$="stop"
 1130 Count%=0
 1140 Flag%=0
 1150 ENDPROC
 1160
 1170
 1180 DEFPROCK8055_init
 1190 REM  Typing errors in routine name do not generate an error message - they just hang up the program.
 1200 SYS"LoadLibrary","K8055D.dll" TO K8055_Board%
 1210 SYS"GetProcAddress",K8055_Board%,"OpenDevice" TO K8055_OpenDevice%
 1220 SYS"GetProcAddress",K8055_Board%,"ReadAnalogChannel" TO K8055_ReadAnalogueChannel%
 1230 SYS"GetProcAddress",K8055_Board%,"SetAllDigital"  TO K8055_SetAllDigital%
 1240 SYS"GetProcAddress",K8055_Board%,"CloseDevice" TO K8055_CloseDevice%
 1250 SYS"GetProcAddress",K8055_Board%,"ClearAllDigital" TO K8055_ClearAllDigital%
 1260 SYS"GetProcAddress",K8055_Board%,"ClearDigitalChannel" TO K8055_ClearDigitalChannel%
 1270 SYS"GetProcAddress",K8055_Board%,"SetDigitalChannel" TO K8055_SetDigitalChannel%
 1280 SYS"GetProcAddress",K8055_Board%,"OutputAnalogChannel" TO K8055_OutputAnalogChannel%
 1290 SYS"GetProcAddress",K8055_Board%,"ClearAnalogChannel" TO K8055_ClearAnalogChannel%
 1300 SYS"GetProcAddress",K8055_Board%,"ClearAllAnalog" TO K8055_ClearAllAnalog%
 1310 SYS"GetProcAddress",K8055_Board%,"WriteAllDigital" TO K8055_WriteAllDigital%
 1320 SYS"GetProcAddress",K8055_Board%,"ReadDigitalChannel" TO K8055_ReadDigitalChannel%
 1330 ENDPROC
 1340


Return to the interfacing index

Back to the Roe Valley index page
  Return sign