Allegro ACS758 capteur de courant avec écran LCD et protection contre les surintensités pour Arduino
Dans ce tutoriel, nous apprendrons comment utiliser le capteur de courant Allegro ACS758 avec un écran LCD pour afficher les relevés de courant et mettre en œuvre une protection contre les surintensités. Cette configuration permet de surveiller le courant et de déconnecter la charge automatiquement si celui-ci dépasse une limite prédéfinie. Le projet combine matériel et logiciel pour créer un système de surveillance du courant fonctionnel.

En suivant ce guide, vous serez en mesure de câbler correctement les composants et de comprendre la logique de programmation du code. Pour une explication plus visuelle, consultez la vidéo associée (à 00:00).
Le matériel expliqué
Les composants clés de ce projet comprennent le capteur de courant Allegro ACS758, un afficheur LCD1602 avec interface I2C, et une carte Arduino. Le capteur ACS758 mesure le courant qui le traverse et fournit une tension proportionnelle au courant. Le LCD1602 affiche les mesures de courant et les messages d'état, tandis que l'Arduino traite les données et commande le relais pour la protection contre les surintensités.
Le capteur ACS758 fonctionne selon un principe appelé détection par effet Hall, qui lui permet de mesurer le courant sans contact électrique direct. La tension de sortie varie en fonction de l'intensité du courant le traversant, offrant un moyen sûr et efficace de surveiller les charges électriques.
Détails de la fiche technique
| Fabricant | Allegro MicroSystems |
|---|---|
| Numéro de pièce | ACS758 |
| Tension logique / E/S | 3.3V / 5V |
| Tension d'alimentation | 5 V |
| Courant de sortie (par canal) | 200 A max |
| Courant de crête (par canal) | 200A |
| Recommandations sur la fréquence PWM | Sans objet |
| Seuils logiques d'entrée | 0,5 × VCC (bidirectionnel) |
| Chute de tension / RDS(on)/ saturation | Sans objet |
| Limites thermiques | 150 °C |
| Paquet | montage sur circuit imprimé |
| Notes / variantes | Plusieurs modèles disponibles pour différentes plages de courant |
- Assurez une dissipation thermique adéquate si l'appareil fonctionne près des limites maximales.
- Utilisez des condensateurs de découplage pour stabiliser la tension d'alimentation.
- Vérifiez que le relais utilisé peut supporter le courant de charge maximal.
- Soyez prudent avec le câblage pour éviter les courts-circuits.
- Parmi les pièges courants figurent les entrées flottantes ; assurez-vous que toutes les connexions sont bien établies.
- Surveillez la surchauffe du capteur lors d'une utilisation prolongée.
Composants nécessaires
- Capteur de courant ACS758
- relais 12 V 100 A
- LCD1602 avec I2C (4 fils)
- Transistor 2N2222 ou 2N3904
- 1 kΩ 1/4 W ou toute résistance de puissance
- Alimentation pour relais
- Alimentation pour votre charge
- Plaque d'essai
- Fils de connexion
Instructions de câblage

Pour câbler le capteur de courant Allegro ACS758 et l'écran LCD1602, commencez par connecter le capteur ACS758. Connectez leVCCbroche du capteur à la broche 5V de l'Arduino. LeGNDLa broche doit être connectée à une broche de masse sur l'Arduino. LeSLa broche (signal) du capteur doit être connectée à la broche d'entrée analogique.A0sur l'Arduino.
Ensuite, pour le LCD1602, connectez leVCCbroche sur la broche 5V de l'Arduino et leGNDÉpingler au sol. LeSDALa broche de l'écran LCD doit être connectée à laA4la broche (SDA) de l'Arduino, tandis que leSCLla broche devrait se connecter àA5La broche (SCL) de l'Arduino. Enfin, connectez un module relais à la broche numérique2pour contrôler la charge en fonction des mesures de courant.
Exemples de code et guide pas à pas
Dans le code Arduino, nous commençons par définir des identifiants clés tels queVIN, qui représente la broche d'entrée analogique connectée au capteur ACS758. LerelayPinest configuré pour la commande du relais, tandis quemaxCurrentdéfinit le seuil de protection contre les surintensités.
#define VIN A0 // define the Arduino pin A0 as voltage input (V in)
const int relayPin = 2; // set a digital pin for relay
const float maxCurrent = 15.00; // set maximum Current
Lesetup()La fonction initialise l'écran LCD et configure la broche du relais en sortie. Elle affiche également un message de bienvenue sur l'écran LCD, informant l'utilisateur du capteur de courant utilisé.
void setup() {
pinMode(relayPin, OUTPUT); // set relayPin as output
Serial.begin(9600); // initialize serial monitor
lcd.begin(); // initialize the LCD
lcd.backlight(); // Turn on the blacklight
lcd.print("Robojax");
}
Dans leloop()Dans la fonction, nous lisons en continu la tension du capteur et calculons le courant. Si le courant dépasse la valeur maximale, le relais est activé pour déconnecter la charge. Cette logique garantit que le système se protège contre les surintensités.
void loop() {
float voltage_raw = (5.0 / 1023.0) * analogRead(VIN); // Read the voltage from sensor
float current = voltage / FACTOR; // Calculate current
if (current >= minCurrent) {
if (current <= maxCurrent) {
digitalWrite(relayPin, LOW); // turn the relay OFF to allow current
} else {
digitalWrite(relayPin, HIGH); // turn the relay ON to disconnect current
}
}
}
Démonstration / À quoi s'attendre
Une fois que tout est câblé et que le code est téléversé, l'écran LCD affichera les valeurs de courant. Si le courant dépasse le seuil définimaxCurrent, le relais s'activera, déconnectant la charge. Vous pouvez tester cela en augmentant progressivement le courant de charge et en observant les changements sur l'écran LCD et dans le moniteur série. Veillez à éviter les connexions de polarité inversée, car cela peut endommager les composants (dans la vidéo à 10:15).
/*
*
* Arduino Sketch for Allegro ACS758 Current Sensor with LCD1602 & I2C module and current protection
* This sensor can measure current at a range of up to 200A. It has overcurrent protection with a relay to disconnect the load if
* the current reaches beyond the limit.
* It operates with 3.3V or 5V.
* This sketch requires you to watch the following 2 videos before using this code:
* 1- ACS758 Sensor https://www.youtube.com/watch?v=SiHfjzcqnU4
* 2- LCD1602 with I2C https://www.youtube.com/watch?v=q9YC_GVHy5A
* 3- Combined 1 and 2 in one video https://www.youtube.com/watch?v=tug9wjCwDQA
* 4- Allegro ACS with Robojax Library (latest video and code) https://youtu.be/sB6EULTix2k
*
* Written by Ahmad Shamshiri on Tuesday, June 26, 2018 at 17:56 in Ajax, Ontario, Canada
* for Robojax.com
* You can watch a detailed video on the ACS758 Current sensor at: https://youtu.be/SiHfjzcqnU4
* This code has been explained in this video: https://youtu.be/GE4I10IZ1jY
* This code has been downloaded from Robojax.com
*/
#define VIN A0 // define the Arduino pin A0 as voltage input (V in)
const int relayPin = 2;// set a digital pin for relay
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)
const float maxCurrent = 15.00;// set maximum Current
int maxCurrentWait = 6000;// wait time before current is connected
float minCurrent = 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
The sensitivity array holds 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
// ======== start of LCD1602 with i2C settings
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
// ======= END of LCD1602 with i2C settings
void setup() {
//Robojax.com ACS758 Current Sensor
pinMode(relayPin,OUTPUT);// set relayPin as output
Serial.begin(9600);// initialize serial monitor
Serial.println("Robojax Tutorial");
Serial.println("ACS758 Current Sensor");
Serial.println("with LCD1602 & I2C");
// initialize the LCD,
lcd.begin();
// Turn on the blacklight and print a message.
lcd.backlight();
lcd.clear();
lcd.print("Robojax");
lcd.setCursor (0,1); // go to start of 2nd line
lcd.print("ACS758 Current Sensor");
delay(2000);
lcd.clear();
}
void loop() {
//Robojax code ACS758 with LCD1602 and I2C
float voltage_raw = (5.0 / 1023.0)* analogRead(VIN);// Read the voltage from sensor
voltage = voltage_raw - QOV + 0.007 ;// 0.007 is a value to make voltage zero when there is no current
float current = voltage / FACTOR;
if( current >= minCurrent){
if(current <= maxCurrent)
{
Serial.print("Current Limit: ");
Serial.print(maxCurrent,3);// print voltage with 3 decimal places
Serial.print("A, I: ");
Serial.print(current,2); // print the current with 2 decimal places
Serial.println("A");
//start of loop Robojax code ACS758 with LCD1602 and I2C
lcd.clear();
lcd.setCursor (0,0); // set to line 1, char 0
lcd.print("Current: ");
lcd.setCursor (9,0); // go to start of 2nd line
lcd.print(current);
lcd.setCursor (15,0); // go to start of 2nd line
lcd.print("A");
lcd.setCursor (0,1);
lcd.print("I Limit: ");
lcd.setCursor (9,1); // go to start of 2nd line
lcd.print(maxCurrent);
lcd.setCursor (15,1); // go to start of 2nd line
lcd.print("A");
lcd.backlight();
//end of loopcode Robojax code ACS758 with LCD1602 and I2C
digitalWrite(relayPin,LOW);// turn the relay OFF to allow the current.
}else{
// the lines bellow will execute if current reaches above the maxCurrent value
digitalWrite(relayPin,HIGH);// turn the relay ON to disconnect the current.
Serial.print("Max Reached:");
Serial.print(maxCurrent,3);// print the maxCurrent
Serial.println("A");
Serial.print("Disconnected ");
//start of loop Robojax code ACS758 with LCD1602 and I2C
lcd.clear();
lcd.setCursor (0,0); // set to line 1, char 0
lcd.print("I Max: ");
lcd.setCursor (8,0); // go to start of 2nd line
lcd.print(maxCurrent);
lcd.setCursor (15,0); // go to start of 2nd line
lcd.print("A");
lcd.setCursor (0,1);
lcd.print("Disconnected");
lcd.backlight();
//end of loopcode Robojax code ACS758 with LCD1602 and I2C
delay(maxCurrentWait );// wait for maxCurrentWait seconds
}
}else{
Serial.println("No Current");
lcd.clear();
lcd.setCursor (0,0);
lcd.print("No Current");
digitalWrite(relayPin,LOW);// turn the relay OFF to allow the current.
}
delay(500);
}
Ce dont vous pourriez avoir besoin
-
Amazon
-
Amazon
-
Amazon
-
AliExpressAchetez 10 pièces de LCD1602-I2C sur AliExpresss.click.aliexpress.com
-
AliExpressAchetez un LCD1602 sur AliExpresss.click.aliexpress.com
-
BanggoodAchetez un écran LCD1602 sur Banggoodbanggood.com
Ressources et références
-
Externe
-
Externe
-
ExterneAchetez un LCD1602 sur AliExpresss.click.aliexpress.com
-
Externe
-
ExterneAchetez un écran LCD1602 sur Banggoodbanggood.com
Fichiers📁
Fiche technique (pdf)
-
Fiche technique du capteur de courant ACS758
robojax_ACS758_current_sensor_datasheet.pdf1.03 MB