Lab 4

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

ACS712 Class Reference

ACS712 Class Reference

A Hall-Effect sensor for measuring current levels in a given path. More...

#include <ACS712.h>

Public Member Functions

 ACS712 (PinName _pin, float voltDivRatio=1, short type=5)
 Create a hall-effect sensor of the specified type.
float read ()
 Read the value of the measured current in amps.
 operator float ()
 Read the value of the measured current in amps Allows the ACS712 object to be used in a float context.

Detailed Description

A Hall-Effect sensor for measuring current levels in a given path.

Can be used as a current detector

Example:

 // Periodically read current levels in a circuit and
 // send output to PC terminal

 #include "mbed.h"
 #include "ACS712.h"

 // Connect the sensor analog output pin to mbed's AnalogIn pin
 ACS712 dev(p18);
 // Connect mbed to pc's USB port
 Serial pc(USBTX, USBRX);

 int main() {
      pc.printf("Sensor Log: \n\n\r");
      while (1) {
          // Read current from sensor and output to pc terminal
          pc.printf("Sensor Value: %2.2f A\n\r", dev);
          wait(0.200);
      }
 }

Definition at line 30 of file ACS712.h.


Constructor & Destructor Documentation

ACS712 ( PinName  _pin,
float  voltDivRatio = 1,
short  type = 5 
)

Create a hall-effect sensor of the specified type.

Parameters:
_pinmbed AnalogIn pin where the analog output of sensor is connected
voltDivRatioresistor voltage division ratio at output of the sensor
typetype of ACS712 sensor used
Note:
Supported types of sensors:

Definition at line 69 of file ACS712.h.


Member Function Documentation

operator float (  )

Read the value of the measured current in amps Allows the ACS712 object to be used in a float context.

Returns:
current value in amps

Definition at line 55 of file ACS712.h.

float read (  )

Read the value of the measured current in amps.

Returns:
current value in amps

Definition at line 88 of file ACS712.h.