The following information is for the EMANT300, EMANT380

Exercise 5 - Analog Input (Measure Light Intensity)

Objective

  • Learn Analog Input
  • Learn more about Class and Object

In this exercise, we will measure the light intensity using a Photodiode and the EMANT3X0, a Data Acquisition Module.

Class, objects, methods, properties

We will use cars to illustrate the above concepts.

  • Cars have registrations numbers to differentiate one car from another.
  • Cars can be described by their make or their color
  • Cars can be driven forward and in reverse.

We have two cars, SFL8772 is a Grey Toyota while SCU7056 is a Gold Honda.

In Visual Basic terminology, we would say that

  • Car is a class
  • SFL8772 and SCU7056 are objects and instances of the Car Class.
  • SFL8772.Color = Grey; SCU.Color = Gold

Color is property of the Car Class

  • SFL8772.Make = Toyota;
    SCU.Make = Honda

Make is another property of the Car Class

  • SFL8772.Drive(forward);
    SCU7056.Drive(reverse)

Drive is a method of the Car Class.

  • To identify the property, we put a dot or '.' between the object and the property and assign an appropriate value.
  • The difference between method and property is that a method is associated with a task.
  • A method may or may not require parameters like forward or reverse to be passed.

In your previous exercises, you have used the Console class and the methods ReadLine and Writeline to allow your program to interact with the user using the computer monitor and keyboard.

To perform Data Acquisition, we have provided a class called EMANT300 which works with the EMANT3X0 DAQ Modules and allows your program to interact with the physical world.

  1. Open the Visual Basic solution VB_2010_Solution.sln.
  2. Set the ReadLight project as the startup project.
  3. View the project code by opening the project's Module1.vb
  4. If you are using the EMANT380 Bluetooth DAQ, change the parameter to False and COM5 to the COM port you are using, See exercise 1 step 4.
    DAQ.Open(False,"COM5")
  5. Every project contains a References folder for identifying physical assemblies the code in the project uses. In order to use the Emant300 class, the program must reference the assembly Emant300.dll. Click Project->Show All Files You should see the Emant300 assembly included in the References folder.
  6. Press Ctrl+F5 to Start without Debugging to run your light measurement program.
  7. Press any key to return to the development environment.
  8. Run the program several times. Cover the Photodiode with your hand to observe the change in light intensity measured.

Program 5.1 Measure Light Intensity

Imports Emant Module Module1 Sub Main() Dim volt, lux As Double Dim DAQ As Emant300 = New Emant300 DAQ.Open(True,"COM5") volt = DAQ.ReadAnalog(Emant300.AIN.AIN0, Emant300.AIN.COM) lux = 1333 * volt Console.WriteLine(lux) DAQ.Close() End Sub End Module

Enumerations

Enumerations are strongly typed of constants that help to make programming more meaningful and safe. In this example, the analog inputs for the EMANT300 module are fixed by hardware. The corresponding enumeration is

Member name

Description

AIN0

AIN0 – Analog Input 0

AIN1

AIN1 – Analog Input 1

AIN2

AIN2 – Analog Input 2

AIN3

AIN3 – Analog Input 3

AIN4

AIN4 – Analog Input 4

AIN5

AIN5 – Analog Input 5

COM

AINCOM – Common Analog Input

DIODE

DIODE – Temperature Sensing Diode

Create the EMANT300 object

Dim DAQ As Emant300 = New Emant300

An instance of EMANT300 is created and called DAQ. The variable DAQ is the equivalent of the car registration number. All future references to this object will use this name. See the EMANT Class Reference manual for more information.

Open method

DAQ.Open() DAQ.Open(False,"COM5")

Open is a method that instructs the program to connect to the DAQ module that is physically connected to USB port. If you are using the EMANT380 Bluetooth DAQ, the Com Port must be specified and the Find parameter set to False.

Photodiode

On the light application adaptor board, the light sensor is the BPW34. It has extremely high resistance when reverse biased. This resistance is reduced when light of an appropriate frequency shines on the junction. Hence, a reverse biased diode can be used as a light detector by monitoring the current running through it. Coupled to a 10 Kohm resistor, and given the specification of the BPW34 a simple relationship between lux (light intensity) and voltage is given by

lux = 1333 * Vo

VOis connected to the AIN0 and GND (COM) of the EMANT3X0 DAQ module.

Read Analog Voltage

volt = DAQ.ReadAnalog(Emant300.AIN.AIN0,Emant300.AIN.COM)

The analog voltage across AIN0 and GND (COM) is read. Emant300.AIN.AIN0 and Emant300.AIN.COM are the respective enumeration. The voltage is converted to Lux and then displayed on the console output.

Close method

DAQ.Close()

Finally the DAQ connection is closed. To ensure that your programs end correctly, always call the Close method before you exit your programs.

Imports Directive

Imports Emant

Allow unqualified reference to Emant300. If you don't include this Imports directive, all references to the Emant300 and its object will have to full

Dim DAQ As Emant.Emant300 = New Emant.Emant300

is shortened to

Dim DAQ As Emant300 = New Emant300

Build this project from scratch

End of Exercise 5