ACTIVITIES

Testing the Touch Sensors

Calibrating for Botball (touch sensors)

Beginning to use the LEGO Touch Sensor

Using the Touch Sensors to Control Motors

Calibrating the LEGO Sensor for Botball

 CYBER LAB SENSOR ACTIVITIES

Photodiode

Infrared

Range

Encoder

Touch is a very important sense for human beings. It is equally important for your robot. These sensors allow the robot to feel its way through rooms or game tables in a crude, yet effective manner. Touch sensors may be the simplest sensors on your robot to understand. The switch is either on or off, just like turning your bedroom light on or off. The KIPR robot kit contains several digital contact sensors. All of these sensors return a 0 when untouched and a 1 when activated. They require only a slight force to activate them. The lever switch is activated when the lever is pushed downward. The post switch is activated when the post is pushed in toward the base, or in any sideways direction. The small button switch is activated when the button is pushed in towards the body of the switch. These sensors are most commonly used as part of a bumper system or as limit switches for an actuator. Also included are activities for the LEGO touch sensor. The LEGO touch sensor consists of a yellow push button in the shape of a 2x3 brick.

 

 

 

Figure 1. Three touch sensors modified for the HandyBoard

ACTIVITY #1: TESTING THE TOUCH SENSORS

BACK TO THE TOP

In this activity, you will load the code for HandyBoard digital ports 7-15 and test all of the touch sensors. Activity #1 is an exercise designed to familiarize users with computer code for digital sensors and how to activate them using the HandyBoard. Click here for a quick IC and NQC tutorial

Materials Needed: HandyBoard setup, touch sensors, Interactive C software,

Procedure (a): Loading the digital sensor code

1. Connect your computer to the serial interface box with the 9 to 24 pin PC or Mac cable. Connect the serial port box to the HandyBoard with the 4 pin telephone cable. Turn the HandyBoard on.
2. Open up the application Interactive C (IC).
3. Under "File" in IC, open a new text editor by choosing "New." Write or cut and paste the sample program code below into the new IC text box:

 void main() {

printf("Press START ...\n");
while (peek(0x7fff)&0x80);
beep();

printf("Press STOP ...\n");
while (peek(0x7fff)&0x40);
beep();

printf("Digital ins; Stop to end\n");
sleep(0.5);
while (!stop_button()) {
int i;
printf("Digital inputs: ");
for (i=15; i>6; i--)
if (digital(i)) printf("1");
else printf("0");
printf("\n");
msleep(100L);
}
}

4. Save this file as digital.c and then download the file to the HandyBoard. If your download was successful, turn the HandyBoard off and on again. The LCD screen should be displaying the message "Press START"

Procedure (b): Testing the touch sensors

5. Layout the three touch sensors: button, multidirectional button, and the bar lever.
6. Attach the button to port 7, attach the multidirectional button to port 9, and attach the bar lever to port 11.
7. Press START
8. Press STOP
9. You should see the message "Digital inputs: 000000000". Each of the 9 zeros represents ports 7 through 15.
10. Test each sensor by pushing the buttons or lever.
11. Test each port with all of the different touch sensors.

LEGO Touch Sensors

The Botball kit contains two LEGO touch sensors (Figure 2.). Dave Baum says, "The touch sensor is the simplest of the LEGO sensors; it consists of a small push-button built into the end of the 2x3 brick. Multiple touch sensors may be connected in parallel, or when more than one touch sensor is connected to the same input sensor port on the RCX. When used this way, the RCX would be able to detect when any of the sensors were pressed, but would not be able to distinguish which of the sensors was actually pressed (Baum, 2000). Below are a few general activities that will familiarize you with this sensor. Other activities can be found on LEGO Mindstorm websites and other publications.

ACTIVITY #2: CALIBRATING FOR THE BOTBALL GAME

BACK TO THE TOP

Now that you have tested the photodiode and seen how it operates, it's time to learn how to calibrate the light sensor for the Botball game. In this activity, you will learn how to calibrate the photodiode sensor using a 60-watt light bulb. You will also be introduced to the 2000 Botball competition IC program. The program provided is for the HandyBoard using one light sensor and two touch sensors.

Materials Needed: HandyBoard setup, one photodiode sensor, two touch sensors, two motors, two motor connectors, a light bulb or flash light, a PC or Mac computer, Interactive C software.

Procedures: Calibration

1. Attach the HandyBoard to the serial port interface box and to the computer. Open up
the Interactive C software.
2. Once the computer is reading the HandyBoard, open up the program bb-exmpl-ic.c
This file is located in the IC for BB 2000 file. If you do not have the Botball software,
you can copy or cut and paste the program below.
3 Read through the bb-example-ic.c program.
4 Attach the photodiode to analog port number 6.
5 Attach the two touch sensors to digital ports 13 and 15.
6 Attach the two motors and connectors to motor ports 1 and 3.
7 Download the bb-example-ic.c program to the HandyBoard.
8 Turn the HandyBoard off and back on again.
9 You should see the message "light on press start."
10 To calibrate the HandyBoard using the photodiode, turn on the light bulb or flash light.
11 Press the start button and point the sensor at the light source.
12 Now you should see a message, " light off press stop."
13 Place the photodiode in the palm of your hand and close it tightly
14 Press the stop button and you should hear a humming sound. This means the HandyBoard is waiting for the sensor to see the light.
15 Open your palm, the sensor will see the light and your motors will start.
16 Press the touch sensors and watch the motors rotate forwards and backwards.

Program: bb-example-ic.c

 /* This program is for a robot with a light sensor and two touch sensors, one in the front and one in back. The robot is calibrated by pressing Start when the light is on and Stop when the light is off. The robot then hums until the light turns back on. It then moves forward until the bumper hits, then backs up until the rear bumper goes off. This repeats until 90 seconds have elapsed. The robot then turns off.
*/
int light, front_bump, rear_bump;

void main() /* this task starts when run is pressed */
{
int light_on;
int light_off;
int light_mid;
int pid,i;

start_process(monitor_sensors()); /* Initialize the sensor modes */
beep(); /*starting sound */
printf("light on press start\n");
while (!start_button())
{
light_on = light;
}
beep(); /* lights on have been stored */
printf("light off press stop\n");
while (!stop_button())
{
light_off = light;
}
beep(); /* lights off have been stored */
light_mid=(light_on + light_off)/2;
while (light<light_mid)
{
tone(220.0,0.02); /*hum while waiting for light */
}
pid=start_process(Botball()); /* the light is on, start moving */
for(i=0;i<9;i++)
{
printf("Time = %d\n",10*i);
sleep(10.0); /* wait 90 seconds then turn everything off */
}
kill_process(pid);
beep();
ao();
printf("Game over!\n");
}

/* this task just moves the robot back and forth, reversing
direction every time it bumps into something. */
void Botball()
{
int go_forward;
while (1) /*this loop goes forever until stopped by main */
{
if (front_bump==1) go_forward=0; /*forward bumper hit */
if (rear_bump==1) go_forward=1; /*rear bumper hit */
if (go_forward==1)
{
fd(1);
fd(3);
}
else
{
bk(1);
bk(3);
}
}
}

void monitor_sensors()
{
while(1)

{
light=255-analog(6);
front_bump= digital(13);
rear_bump = digital(15);
}
}

Questions: What is the definition of calibration? What is the purpose of calibrating a robot or other scientific equipment? What are other scientific instruments that need to be calibrated before an experiment can be performed?

ACTIVITY #3 BEGINNING TO USE THE LEGO TOUCH SENSOR

BACK TO THE TOP

This nice digital sensor is very well designed to connect to other LEGO pieces. The actual sensor is located within a 2x3 LEGO brick. There are a number of different methods for attaching the sensor and a number of different bumper designs to meet your application needs. In this activity, you will learn more about the touch sensor and what readings look like on the RCX screen.

Figure 2. LEGO touch sensor

MATERIALS NEEDED: RCX setup, one LEGO touch sensor, one LEGO motor connector, NQC software, Mac or PC computer

PROCEDURE:

1. Attach the motor connector wire to the touch sensor. Make sure you have a metal on metal connection.

2. Now, attach the other end of the connector wire to the RCX processor. The sensor ports on the RCX processor are 1, 2 and 3 (Motor ports are A, B, and C, LEGO sensors will not work in these ports).

3. Attach the light sensor to port number 3.

4. Turn our RCX processor on. If you see four 00.00 on the left side of the little man icon, your Firmware is loaded and you can program using NQC. If you do not see 00.00 you need to download the Firmware.

5. Pick up the sensor and look at the end. You will see a yellow button, which is the activation switch. Push the switch.

6.Push the view button on the RCX processor. You should see an arrow pointing at the number 1. You will also see a numerical value on the RCX screen. Push the view button until the arrow is pointing at port number 3.

7. What is the light reading you see on the screen? Push the button. Now, what is the reading? Is this an analog or digital sensor?

ACTIVITY #4 USING THE TOUCH SENSORS TO CONTROL MOTORS

BACK TO THE TOP

One of the primary uses of the touch sensor is to control the motors of your robot. In this activity, you will be introduced to NQC code that employs the use of touch sensors and their control of the rotational direction of the motors.

MATERIALS NEEDED: RCX setup, one light sensor, two touch sensors, two LEGO motors, four LEGO motor connectors, two 16 tooth gears

PROCEDURE

1. Connect the light sensor to port 1. Connect the touch sensors to ports 2 and 3. Connect the motors to ports A and C.
2. Place one gear on each motor axle. This will allow us to see the axle rotate.
3. Turn on the RCX processor. Is your Firmware loaded? How do you know?
4. Open up your NQC software. You can test the sensors and motors with the PC version of NQC.
5. Open up a new NQC program window by selecting "New." Write or cut and paste the program below into the new window.
6. Connect your IR tower to your computer. Place the RCX in front of the tower and download the program.
7. To start the program, press the Run button on the RCX processor. Press touch sensor in port 2.
8. Now, press the touch sensor in port 3. This should start the motors moving. Press the touch sensors to change the motors' rotational direction.

 task main() /* this task starts when run is pressed */
{
int light_on;
int light_off;
int light_mid;

SetSensor(SENSOR_1,SENSOR_LIGHT); /* Initialize the sensor modes */
SetSensor(SENSOR_2,SENSOR_TOUCH);
SetSensor(SENSOR_3,SENSOR_TOUCH);
PlaySound(4); /*starting sound */
while (SENSOR_2==0)
{
light_on = SENSOR_1;
}
PlaySound(2); /* lights on have been stored */
while (SENSOR_3==0)
{
light_off = SENSOR_1;
}
PlaySound(3); /* lights off have been stored */
light_mid=(light_on + light_off)/2;
while (SENSOR_1<light_mid)
{
PlayTone(220,2); /*hum while waiting for light */
}
start Botball; /* the light is on, start moving */
Wait(9000); /* wait 90 seconds then turn everything off */
stop Botball;
Off(OUT_A+OUT_B+OUT_C);
}

/* this task just moves the robot back and forth, reversing
direction every time it bumps into something. */
task Botball()
{
int go_forward;
while (true) /*this loop goes forever until stopped by main */
{
if (SENSOR_2==1) go_forward=0; /*forward bumper hit */
if (SENSOR_3==1) go_forward=1; /*rear bumper hit */
if (go_forward==1)
{
OnFwd(OUT_A);
OnFwd(OUT_C);
}
else
{
OnRev(OUT_A);
OnRev(OUT_C);
}
}
}

 

ACTIVITY #5 CALIBRATING THE LEGO SENSOR FOR THE BOTBALL GAME

BACK TO THE TOP

In this activity, you will learn how to calibrate for light variation using the light sensor and the RCX processor. You will learn an application using the sensor and will also be introduced to NQC programming.

MATERIALS NEEDED: RCX setup, one light sensor, two bump sensors, two LEGO motors, four LEGO motor connectors, two 16 tooth gears

PROCEDURE

1. Connect the light sensor to port 1. Connect the bump sensors to ports 2 and 3. Connect the motors to ports A and C.
2. Place one gear on each motor axle. This will allow us to see the axle rotate.
3. Turn on the RCX processor. Is your Firmware loaded? How do you know?
4. Open up your NQC software. You can test the sensors and motors with the PC version of NQC.
5. Open up a new NQC program window by selecting "New." Write or cut and paste the program below into the new window.
6. Connect your IR tower to your computer. Place the RCX in front of the tower and download the program.
7. The easiest way the run this program is in a well lit room with a light switch or by using a bright flash light.
8. To start the program, press the Run button on the RCX processor. Press bump sensor in port 2. This tells the light sensor to read the lighting conditions that will start the motors moving. If you are using a flash light, point it directly at the light sensor diodes.
9. Now, turn the light source off and press the bump sensor in port 3. This tells the RCX processor to wait for the first light reading to appear.
10. Now turn the light source back on. This should start the motors moving. Press the bump sensors to change the motors' rotational direction.

 

task main() /* this task starts when run is pressed */
{
int light_on;
int light_off;
int light_mid;

SetSensor(SENSOR_1,SENSOR_LIGHT); /* Initialize the sensor modes */
SetSensor(SENSOR_2,SENSOR_TOUCH);
SetSensor(SENSOR_3,SENSOR_TOUCH);
PlaySound(4); /*starting sound */
while (SENSOR_2==0)
{
light_on = SENSOR_1;
}
PlaySound(2); /* lights on have been stored */
while (SENSOR_3==0)
{
light_off = SENSOR_1;
}
PlaySound(3); /* lights off have been stored */
light_mid=(light_on + light_off)/2;
while (SENSOR_1<light_mid)
{
PlayTone(220,2); /*hum while waiting for light */
}
start Botball; /* the light is on, start moving */
Wait(9000); /* wait 90 seconds then turn everything off */
stop Botball;
Off(OUT_A+OUT_B+OUT_C);
}

/* this task just moves the robot back and forth, reversing
direction every time it bumps into something. */
task Botball()
{
int go_forward;
while (true) /*this loop goes forever until stopped by main */
{
if (SENSOR_2==1) go_forward=0; /*forward bumper hit */
if (SENSOR_3==1) go_forward=1; /*rear bumper hit */
if (go_forward==1)
{
OnFwd(OUT_A);
OnFwd(OUT_C);
}
else
{
OnRev(OUT_A);
OnRev(OUT_C);
}
}
}



Back to the Top

Back to the Cyber Lab Home Page

Back to the Main Activity Page

Please send any questions or comments to Here

 photodiode

 Infrared

 range

 touch

 encoder

 


Go to The Botball Home Page