Raadi Koodka

Qiyaashaynta hadda iyadoo la isticmaalayo sensor-ka hadda ee Allegro ACS758 oo leh shaashad OLED SSD1306 ee Arduino

Qiyaashaynta hadda iyadoo la isticmaalayo sensor-ka hadda ee Allegro ACS758 oo leh shaashad OLED SSD1306 ee Arduino

Tilmaantan waxay ku hagaysaa habka lagu cabbiro hadda iyadoo la adeegsanayo dareemaha hadda ee Allegro ACS758 iyo muujinta natiijooyinka shaashadda OLED ee SSD1306. Mashruucu wuxuu ku lug yeelan doonaa akhrinta hadda ku socda wareegga iyo si muuqaal ah u matalida xogtaas shaashadda OLED, taasoo u oggolaanaysa la socodka fudud. Waxaad baran doontaa sida loogu xiro qaybaha, qorista koodka, iyo fahamka sida wax walba isku shaqeeyaan.

SSD1306 OLED display

Haddii aad rabto inaad fahamto koodka iyo shaqadiisa, hubi inaad eegto fiidiyowga si aad u hesho sharaxaad faahfaahsan (fiidiyowga 02:45).

Qalabka La Sharxay

Qaybaha ugu muhiimsan ee mashruucan waxaa ka mid ah dareemaha hadda ee Allegro ACS758 iyo shaashadda OLED ee SSD1306. ACS758 waa dareeme hadda oo Hall-effect ah kaas oo cabbira hadda ku socda koronto-qaade isagoo leh saxnaan sare wuxuuna bixiyaa danab soo-saaris u dhigma hadda. Wuxuu qaadi karaa hadda ilaa 200A wuxuuna ku shaqeeyaa 3.3V ama 5V.

Shaashadda OLED ee SSD1306 waa shaashad isku-kooban, tamar yar oo ku xidhiidha I2C. Waxaa badanaa loo isticmaalaa mashruucyada Arduino sababtoo ah fudaydka isku xirka iyo awoodda ay u leedahay inay muujiso garaafyada iyo qoraalka si cad. Marka la wada isticmaalo, qaybahani waxay abuuraan qalab awood leh oo lagula socdo hadda codsiyada kala duwan.

Faahfaahinta Xogta

Soo-saarahaAllegro Microsystems
Nambarka qaybtaACS758ECB-200U
Danabka Logic/IO3.3 V / 5 V
Danabka sahayda5 V
Hadda soo-saarka (kanal kasta)200 A
Hadda ugu sarreysa (kanal kasta)200 A
Hagaha soo noqnoqoshada PWMN/A
Heerarka caqabadaha gelinta0.3 V (hoose), 2.7 V (sare)
Hoos u dhaca danabka / RDS(on) / dheregsanaanta0.05 V
Xadka kulaylka-40 ilaa 125 °C
BaakadSOIC-8
Qoraalo / noocyoNoocyo laba-geesood ah iyo hal-geesood ah ayaa diyaar ah

  • Hubi jihada saxda ah ee dareemaha ACS758 si aad u hesho akhrin sax ah.
  • Isticmaal kulayl-qaade haddii aad ku shaqeyso meel u dhow xadka hadda ugu sarreysa si looga hortago kulaylka xad-dhaafka ah.
  • Kala goyn sahayda danabka ee dareemaha si loo helo shaqo deggan.
  • Hubi xiriirada fiilooyinka si looga fogaado gelinta sabeynaysa oo u horseedi karta akhrin khaldan.
  • Hagaaji soo-saarka dareemaha si loo hubiyo cabbirro hadda oo sax ah.

Tilmaamaha Xiritaanka

Arduino wriing for Allegro ACS758 current sensor with OLED SSD1306 128x32 and 128x64
Arduino wriing for Allegro ACS758 current sensor with OLED SSD1306 128x32 and 128x64

Si aad u xirto dareemaha hadda ee Allegro ACS758 iyo shaashadda OLED ee SSD1306, ku bilow isku xirka danabka. Ku xir pin-ka VCC ee ACS758 ee soo-saarka 5V ee Arduino-gaaga, oo ku xir pin-ka GND dhulka (GND) ee Arduino-ga. Pin-ka calaamadda soo-saarka (Vout) ee ACS758 waa in lagu xiraa pin-ka gelinta analogga ah ee A0 ee Arduino-ga.

Marka xigta, shaashadda OLED ee SSD1306, ku xir pin-ka VCC ee soo-saarka 5V ee Arduino-ga iyo pin-ka GND dhulka. Ku xir pin-ka SDA ee OLED-ka pin-ka SDA ee Arduino-ga (A4 inta badan looxyada Arduino) iyo pin-ka SCL ee OLED-ka pin-ka SCL (A5 inta badan looxyada Arduino). Hubi in dhammaan xiriiradu ay yihiin kuwo adag si loo helo shaqo lagu kalsoonaan karo.

Tusaalooyinka Koodka & Sharaxaad

#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)

Koodka, doorsoome VIN waxaa loo qoondeeyay pin-ka analogga ah ee A0, kaas oo akhrin doona danabka ka yimaada dareemaha ACS758. Doorsoomaha VCC wuxuu dejiyaa danabka sahayda, iyo doorsoomaha model wuxuu qeexaa nooca ACS758 ee la isticmaalayo, kaas oo saameeya xasaasiyadda iyo xisaabinta danabka soo-saarka.

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
}

Gudaha shaqada loop(), koodku wuxuu akhriyaa danabka cayriin ee ka yimaada dareemaha isagoo adeegsanaya analogRead(VIN) wuxuuna u beddelaa qiime hadda oo ku salaysan xasaasiyadda la qeexay. Tani waxay u oggolaanaysaa la socodka waqtiga dhabta ah ee hadda ku socda wareegga.

if(abs(voltage) > cutOff) {
    display.clearDisplay();
    robojaxText("Current:", 0, 22, 2, false);
}

Qodobkan shuruudda ah wuxuu hubinayaa in qiimaha saxda ah ee danabku uu ka weyn yahay xadka cutOff. Haddii ay run tahay, waxay nadiifisaa shaashadda waxayna ku cusboonaysiisaa OLED-ka akhrinta hadda. Tani waxay hubinaysaa in kaliya qiimayaasha hadda ee muhiimka ah la muujiyo, iyadoo laga hortagayo wasakhda shaashadda.

Muuujin / Waxa Lagu Filan Karaa

Markaad shubto barnaamijka, shaashadda OLED waxay muujin doontaa hadda la cabbirayo waqtiga dhabta ah. Haddii aysan jirin hadda socda, shaashaddu waxay muujin doontaa "No Current." Hubi in xiriiradu ay sax yihiin si looga fogaado arrimo sida rogaanshaha khaldan, kaas oo u horseedi kara akhrin aan sax ahayn (fiidiyowga 05:30).

Sawirro

SSD1306 OLED displaying text
SSD1306 OLED displaying text
SSD1306 OLED display
SSD1306 OLED display
ACS758-sensor-6-pins
ACS758-sensor-6-pins
ACS758-sensor-0
ACS758-sensor-0
ACS758-sensor-1
ACS758-sensor-1
ACS758-sensor-4
ACS758-sensor-4
Arduino wriing for Allegro ACS758 current sensor with OLED SSD1306 128x32 and 128x64
Arduino wriing for Allegro ACS758 current sensor with OLED SSD1306 128x32 and 128x64
110-Allegro ACS758 current sensor with SSD1306 OLED display for Arduino
Luqadda: C++
/*
 * 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);
}

Waad u baahan tahay

Kheyraadka & Tixraacyada

Wali wax kaydsan ah oo weli ma jiro.

Faylasha📁

Arduino Libraries (zip)

Waraaqa xogta (pdf)

  • Xaashida Xogta Muujinta SSD1306
    SSD1306 waa darawal OLED/PLED oo CMOS ah oo hal-chip ah oo leh kontaroolaha nidaamka muujinta graph-ka dot-matrix ee organic / polymer light emitting diode. Wuxuu ka kooban yahay 128 qaybood iyo 64 commons. IC-kan waxaa loogu talagalay nooca OLED panel-ka ee Common Cathode. SSD1306 waxay ku dhex jirtaa xakamaynta contrast, RAM-ka muujinta iyo oscillator, taas oo yaraynaysa tirada qaybaha dibadda ah iyo isticmaalka korontada. Waxay leedahay xakamaynta iftiinka 256-tallaabo. Xogta/Amarada waxaa laga soo diraa MCU-ga guud iyada oo loo marayo interface-ka Parallel ee 6800/8000 series ee la dooran karo, interface-ka I2C ama interface-ka Serial Peripheral. Waxay ku habboon tahay codsiyo badan oo yaryar oo la qaadan karo, sida muujinta hoose ee taleefanka gacanta, MP3 player iyo calculator, iwm.
    SSD1306_display_datasheet.pdf 1.79 MB

Faylka Fritzing

Buugga Isticmaalaha

Faylal kale

  • Alegro ACS Current Library
    Arduino library for Allegro ACS current sensor modules. Provides functions to read current measurements from ACS712 and similar sensors.
    robojax_Alegro_ACS_Current_library.zip 0.02 MB