Skip to the content.
Lab 2

Lab 2 Page

Summary

In this lab there were two main objectives that had to be met:
i. Setting up the display component of the base station using a 4-digit 7-segment display , some resistors and a shift register.
ii. Adding an IR light detection circuit to the existing robot. It can also detect the frequency of the IR LED.

Base-Station Display Setup

The 7-segment display has 16 pins, 8 at the top and 8 at the bottom. There are pins for each of the 7 segments as well as pins for the 4 digits. It is placed so that the center divider is in between the 8 pins at the top and bottom, to prevent short circuiting.

The pins controlling the digits are connected to transistors. The base of the transistors are then connected to a resistor and then to a digital pin on the Arduino. One digit corresponds to one pin on the Arduino. The segment pins of the 7-segment display were then connected to a resistor and then to shift register pins as specified in the lab handout. The resistors simply help limit the flow of current and prevents burnout from slight voltage changes.

Programming 7-Segment Display

The 7-Segment Display Code was mostly prewritten. There is a display function and a formula meant to determine the number to displayed on each digit based on the number to be displayed. There is a switch statement that comes with cases on what to input to the shift register based on the numbers 0-9. To then display the digits, the corresponding digit output pin on the Arduino is set to low

Debugging the 7-Segment Display

After setting up the 7-Segment Display and Flashing the Code, it failed to work. Debugging was a slow and painful process due to the amount of wiring involved in setting up the display. To test the segment pins of the shift register individually, the pins were connected to ground, causing the individual segments on the display for all the digits to turn on, based on what was connected to ground. After verifying that the shift register was working correctly and the LED display was also working correctly, we tested transistors and resistors and my partner found out the problem was a faulty wire later on.

Phototransistor Circuit Setup.

To begin with, one phototransistor was connected to the Arduino on the robot. From ground it was connected to a resistor and then to the Arduino Pin. The other end was connected to 5V. Not all pins on the Arduino can be used. This is because the inputs from the phototransistor have to serve as inputs to the Analog Comparator" Looking up the AC inputs on the datasheet, the pins we could use were then found.

Below are the phototransistors on the robot :

Phototransistor Circuit Programming and Testing

Using a signal generator, a resistor and an Infrared LED, an Infrared LED was turned on and given a frequency of 1KHz. To test whether the frequency was actually 1KHz, an oscilloscope was attached. We further set the signal generator to 9KHz, also observing with the signal Generator.

1 KHz on oscilloscope screen

9KHz on oscilloscope screen

After doing the above, we flashed the code onto the Arduino, then we placed the IR Led near the phototransistor. Based on Serial Monitor Output after using the code provided, we were able to verify the Phototransistor was working. With a few lines of code, we added some more functionality. Instead of a fixed DACREF value, a DACREF value was calculated at the setup part of the code, using the corresponding Ambient Light based on the signal from the Phototranstor. This signal is converted using different formulas to come up with the equivalent Voltage.

A screenshot of the serial monitor is shown below:

After doing this, the other Phototransistors were set up.The three currently seem to be reading IR light frequency correctly. However, the interrupt always seems to be triggered, causing measurements to be taken even below a certain threshold. It will be remedied soon.