Introduction to Computer Systems
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
ELEC1601 Introduction to Computer Systems
Exercise 3 using Physical Equipment
Sample video
The Shield-bot Sensor Shield
In the simulation exercise, you first learnt about the light sensor, and then how it could be used as
an input to control the servo motors. The model your design was based on was that as a wall
moved closer, the sensor would receive more light.
To enable the Shield-Bot to navigate, you will instead use an infra-red (IR) LED as a "headlight"
and pair it with an IR receiver to detect the light being reflected off walls and objects. Similar to the
visible light sensor, as a wall moves closer, the IR receiver will detect more reflected IR light.
Some additional details if you are interested: IR light is an invisible light whose wavelength spans
800 – 1000 nanometres (nm). The wavelength of visible light ranges from 400 nm (blue light) to
700 nm (red). IR is commonly used to transmit data such as in TV remote control and wireless
keyboard/mouse. Just like visible light, IR light also bounces off walls and almost any solid
material. Hence it can be used to detect walls or solid obstacles when an IR receiver is placed
facing the same direction as the IR source.
To make things easier for you, we have designed a sensor shield for the Shield-bots that already
has three pairs of IR LEDs (sources) and IR receivers (sensors) installed. This is mounted on top
of your Shield-bot over the top of the small breadboard so that it is connected directly to the
Arduino. This means that you do not need to construct any physical circuits during the lab this
week and can focus on developing code that you will be using later in your Project. If you want
some background information about how these LEDs and receivers are configured, you can find
the original Shield-bot assembly guide here .
The below image shows a representation of the sensor shield. The green LED will light up if your
sensors have power. The three grey components are the IR receivers which will detect IR light
being reflected off objects in front of your robot and off walls on either side. The IR LEDs are
mounted on the underside of the board, directly below the IR receivers. The red LEDs are free for
you to use however you wish, but we recommend that you use them as a visual indicator that your
robot has detected an obstacle with the corresponding IR LED/receiver.
For the first exercises, you will only be using the centre, or mid IR LED/receiver pair. You can see
from the table printed on the board in the image above that the IR LED is connected to digital Pin
6, the IR receiver/sensor is connected to digital Pin 7, and the red LED is connected to analog Pin
A1. The schematic below shows how these components are connected to the Arduino pins.
Part 1: Calibrating an IR Sensor (This is loosely related to
Simulation Exercise 3 Part 1
1.1 Detection
Infrared detection takes three steps:
A. Flash the IR LED on/off at 38 kHz using the tone()
command.
B. Delay for a millisecond or more to give the IR receiver time to send a low signal in
response to sensing 38 kHz IR light reflecting off an object.
C. Check the state of the IR receiver using digitalRead(). Note that digitalRead() will return 0 if
IR light is detected (object within range) or 1 if no IR light is detected.
D. Light the red LED if the IR receiver returned a low signal (IR detected).
You will note that the receiver response is digital, not analog. This means that you only know
whether IR light was detected or not. You don't know how strong the reflected light is. This is
important on our robot because it means that you know whether an object is within detection
range, but you don't know exactly how close it is.
Here is an example of the three steps applied to the centre/mid IR LED (pin 6) and IR receiver (pin
7).
tone(6, 38000); // Flash IR LED at 38 kHz
delay(1); // Wait 1 ms
noTone(6); // Stop the LED flashing after delay time has passed
int ir = digitalRead(7); // IR receiver -> ir variable