Measuring Current Using an Allegro ACS758 Current Sensor with an SSD1306 OLED Display for Arduino
This tutorial will guide you through the process of measuring current using the Allegro ACS758 current sensor and displaying the results on an SSD1306 OLED display. The project will involve reading the current flowing through a circuit and visually representing that data on the OLED screen, allowing for easy monitoring. You'll learn how to connect the components, write the code, and understand how everything works together.


If you're looking to understand the code and its functionality, be sure to check the video for more detailed explanations (in video at 02:45).
Hardware Explained
The main components of this project include the Allegro ACS758 current sensor and the SSD1306 OLED display. The ACS758 is a Hall-effect current sensor that measures the current flowing through a conductor with high accuracy and provides an output voltage proportional to this current. It can handle currents up to 200A and operates at either 3.3V or 5V.
The SSD1306 OLED display is a compact, low-power display that communicates via I2C. It is commonly used in Arduino projects due to its ease of integration and ability to display graphics and text clearly. Together, these components create a powerful tool for monitoring current in various applications.
Datasheet Details
| Manufacturer | Allegro Microsystems |
|---|---|
| Part number | ACS758ECB-200U |
| Logic/IO voltage | 3.3 V / 5 V |
| Supply voltage | 5 V |
| Output current (per channel) | 200 A |
| Peak current (per channel) | 200 A |
| PWM frequency guidance | N/A |
| Input logic thresholds | 0.3 V (low), 2.7 V (high) |
| Voltage drop / RDS(on) / saturation | 0.05 V |
| Thermal limits | -40 to 125 °C |
| Package | SOIC-8 |
| Notes / variants | Bidirectional and unidirectional models available |
- Ensure proper orientation of the ACS758 sensor for accurate readings.
- Use a heat sink if operating near maximum current limits to prevent overheating.
- Decouple the power supply to the sensor for stable operation.
- Check wiring connections to avoid floating inputs that may lead to erroneous readings.
- Calibrate the sensor output to ensure accurate current measurements.
Wiring Instructions

To wire the Allegro ACS758 current sensor and SSD1306 OLED display, start by connecting the power. Connect the VCC pin of the ACS758 to the 5V output on your Arduino, and connect the GND pin to the ground (GND) on the Arduino. The output signal pin (Vout) from the ACS758 should be connected to the analog input pin A0 on the Arduino.
Next, for the SSD1306 OLED display, connect the VCC pin to the Arduino's 5V output and the GND pin to ground. Connect the SDA pin of the OLED to the Arduino's SDA pin (A4 on most Arduino boards) and the SCL pin of the OLED to the SCL pin (A5 on most Arduino boards). Ensure all connections are secure for reliable operation.
Code Examples & Walkthrough
#define VIN A0 // define the Arduino pin A0 as voltage input (V in)
const float VCC = 5.0; // supply voltage 5V or 3.3V
const int model = 2; // enter the model (see below)
In the code, the variable VIN is assigned to analog pin A0, which will read the voltage from the ACS758 sensor. The VCC variable sets the supply voltage, and the model variable defines which ACS758 model is being used, which affects sensitivity and output voltage calculations.
void loop() {
float voltage_raw = (5.0 / 1023.0) * analogRead(VIN); // Read the voltage from sensor
float current = voltage / FACTOR; // Calculate the current based on voltage
}
Within the loop() function, the code reads the raw voltage from the sensor using analogRead(VIN) and converts it to a current value based on the defined sensitivity. This allows real-time monitoring of the current flowing through the circuit.
if(abs(voltage) > cutOff) {
display.clearDisplay();
robojaxText("Current:", 0, 22, 2, false);
}
This conditional statement checks if the absolute value of the voltage is greater than the cutOff limit. If true, it clears the display and updates the OLED with the current reading. This ensures that only significant current values are shown, preventing clutter on the display.
Demonstration / What to Expect
When you run the program, the OLED display will show the current being measured in real-time. If there is no current flowing, the display will indicate "No Current." Ensure that the connections are correct to avoid issues such as reversed polarity, which could lead to inaccurate readings (in video at 05:30).
/*
* Arduino Sketch for Allegro ACS758 Current Sensor with SSD1306 OLED Display
* can be used with 128x64 or 128x32 OLED displays with SSD1306 chip
* this sensor can measure current at a range of up to 200A
* It operates with 3.3V or 5V
* This video requires you to watch the following 2 videos before using this code:
* 1- ACS758 Sensor https://www.youtube.com/watch?v=SiHfjzcqnU4
* 2- SSD1306 OLED Display https://www.youtube.com/watch?v=UmYiHTOz-5k
*
* View the video instructions for this code at https://youtu.be/aHg9UrK9s9c
* Written by Ahmad Shamshiri for Robojax Video channel www.Robojax.com
* Date: June 24, 2018, at 21:44 in Ajax, Ontario, Canada
* Permission granted to share this code given that this
* note is kept with the code.
* Disclaimer: This code is "AS IS" and for educational purposes only.
* This code has been downloaded from https://robojax.com
*
*/
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2
#define LOGO16_GLCD_HEIGHT 64
#define LOGO16_GLCD_WIDTH 128
static const unsigned char PROGMEM logo16_glcd_bmp[] =
{ B00000000, B11000000,
B00000001, B11000000,
B00000001, B11000000,
B00000011, B11100000,
B11110011, B11100000,
B11111110, B11111000,
B01111110, B11111111,
B00110011, B10011111,
B00011111, B11111100,
B00001101, B01110000,
B00011011, B10100000,
B00111111, B11100000,
B00111111, B11110000,
B01111100, B11110000,
B01110000, B01110000,
B00000000, B00110000 };
#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
///*** ACS758 settings starts
#define VIN A0 // define the Arduino pin A0 as voltage input (V in)
const float VCC = 5.0;// supply voltage 5V or 3.3V. If using PCB, set to 5V only.
const int model = 2; // enter the model (see below)
float cutOffLimit = 1.00;// reading cutt off current. 1.00 is 1 Amper
/*
"ACS758LCB-050B",// for model use 0
"ACS758LCB-050U",// for model use 1
"ACS758LCB-100B",// for model use 2
"ACS758LCB-100U",// for model use 3
"ACS758KCB-150B",// for model use 4
"ACS758KCB-150U",// for model use 5
"ACS758ECB-200B",// for model use 6
"ACS758ECB-200U"// for model use 7
sensitivity array is holding the sensitivity of the ACS758
current sensors. Do not change.
*/
float sensitivity[] ={
40.0,// for ACS758LCB-050B
60.0,// for ACS758LCB-050U
20.0,// for ACS758LCB-100B
40.0,// for ACS758LCB-100U
13.3,// for ACS758KCB-150B
16.7,// for ACS758KCB-150U
10.0,// for ACS758ECB-200B
20.0,// for ACS758ECB-200U
};
/*
* Quiescent output voltage is a factor of VCC that appears at the output
* when the current is zero.
* For bidirectional sensors it is 0.5 x VCC
* For unidirectional sensors it is 0.12 x VCC
* For model ACS758LCB-050B, the B at the end represents Bidirectional (polarity doesn't matter)
* For model ACS758LCB-100U, the U at the end represents Unidirectional (polarity must match)
* Do not change.
*/
float quiescent_Output_voltage [] ={
0.5,// for ACS758LCB-050B
0.12,// for ACS758LCB-050U
0.5,// for ACS758LCB-100B
0.12,// for ACS758LCB-100U
0.5,// for ACS758KCB-150B
0.12,// for ACS758KCB-150U
0.5,// for ACS758ECB-200B
0.12,// for ACS758ECB-200U
};
const float FACTOR = sensitivity[model]/1000;// set sensitivity for selected model
const float QOV = quiescent_Output_voltage [model] * VCC;// set quiescent Output voltage for selected model
float voltage;// internal variable for voltage
float cutOff = FACTOR/cutOffLimit;// convert current cut off to mV
//**** ACS758 settings ends
void setup() {
Serial.begin(9600);
// by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3D (for the 128x64)
// init done
}
void loop() {
//Robojax.com ACS758 Current Sensor values start
float voltage_raw = (5.0 / 1023.0)* analogRead(VIN);// Read the voltage from sensor
voltage = voltage_raw - QOV + 0.003 ;// 0.007 is a value to make voltage zero when there is no current
float current = voltage / FACTOR;
if(abs(voltage) > cutOff ){
Serial.print("V: ");
Serial.print(voltage,3);// print voltage with 3 decimal places
Serial.print("V, I: ");
Serial.print(current,2); // print the current with 2 decimal places
Serial.println("A");
display.clearDisplay();
robojaxText("V:", 0, 0, 2, false);
String voltageS = String(voltage);// get voltage and convert it to string for display
robojaxText(voltageS +"V", 20, 0, 2, false);
robojaxText("Current:", 0, 22, 2, false);
String currentS = String(current);// get current and convert it to string for display
robojaxText(currentS +"A", 0, 40, 3, false);
display.display();
}else{
Serial.println("No Current");
display.clearDisplay();
robojaxText("No Current", 0, 0, 2, false);
display.display();
}
//Robojax.com ACS758 Current Sensor values end
delay(500);
}
/*
* robojaxText(String text, int x, int y,int size, boolean d)
* text is the text string to be printed
* x is the integer x position of the text
* y is the integer y position of the text
* size is the text size, 1, 2, 3 etc
* d is either true or false. Use true to display immediately.
*/
void robojaxText(String text, int x, int y,int size, boolean d) {
display.setTextSize(size);
display.setTextColor(WHITE);
display.setCursor(x,y);
display.println(text);
if(d){
display.display();
}
delay(100);
}
|||您可能需要的东西
-
亚马逊从亚马逊购买SSD1306 OLEDamzn.to
-
亚马逊在亚马逊上购买 OLED 128x32amzn.to
-
全球速卖通从AliExpress购买SSD1306 OLED 128x32s.click.aliexpress.com
资源与参考
尚无可用资源。
文件📁
Arduino 库(zip 格式)
-
SSD1306-OLED-Adafruit_SSD1306-master
robojax-SSD1306-OLED-Adafruit_SSD1306-master.zip0.02 MB
Fritzing 文件
-
OLED Mono 0.56 inch 128x32
OLED Mono 0.56 inch 128x32.fzpz0.01 MB -
SSD1306 0.96英寸 128x64 I2C 单色OLED显示屏
SSD1306 0.96in 128x64 I2C Monochrome OLED Display.fzpz0.01 MB
用户手册
-
SSD1306 OLED 手册
robojax-SSD1306-OLED-manual.pdf1.79 MB