Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Programa: Medidor de corrente com sensor ACS712
- //Autor: Arduino e Cia
- #include <Wire.h>
- #include <U8glib.h>
- //Definicoes do display Oled
- U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE);
- //int valor = 0;
- String str;
- int tamanho;
- const int analogIn = A0;
- int mVperAmp = 66;
- int RawValue = 0;
- int ACSoffset = 2500;
- double Voltage = 0;
- double Amps = 0;
- void draw()
- {
- //Comandos graficos para o display devem ser colocados aqui
- u8g.drawRFrame(0, 16, 128, 48, 4);
- u8g.drawRFrame(0, 0, 128, 16, 4);
- u8g.setFont(u8g_font_8x13B);
- u8g.setColorIndex(0);
- u8g.setColorIndex(1);
- u8g.drawStr( 20, 13, "Corrente (A)");
- u8g.setFont(u8g_font_fur25);
- str = String(Amps);
- tamanho = str.length();
- u8g.setPrintPos(64 - (tamanho * 10), 53);
- u8g.print(Amps,3);
- }
- void setup(void)
- {
- Serial.begin(9600);
- Serial.println("Sensor de Corrente ACS712"); Serial.println("");
- Serial.println("");
- if ( u8g.getMode() == U8G_MODE_R3G3B2 ) {
- u8g.setColorIndex(255); // white
- }
- else if ( u8g.getMode() == U8G_MODE_GRAY2BIT ) {
- u8g.setColorIndex(3); // max intensity
- }
- else if ( u8g.getMode() == U8G_MODE_BW ) {
- u8g.setColorIndex(1); // pixel on
- }
- else if ( u8g.getMode() == U8G_MODE_HICOLOR ) {
- u8g.setHiColorByRGB(255, 255, 255);
- }
- }
- void loop(void)
- {
- Calcula_corrente();
- //Chama a rotina de desenho na tela
- u8g.firstPage();
- do
- {
- draw();
- }
- while ( u8g.nextPage() );
- delay(150);
- }
- void Calcula_corrente()
- {
- RawValue = analogRead(analogIn);
- Voltage = (RawValue / 1024.0) * 5000; // Gets you mV
- Amps = ((Voltage - ACSoffset) / mVperAmp);
- delay(2000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement