Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Código original do Rodrigo
- // http://labdegaragem.com/forum/topics/frequencimetro-e-voltimetro
- #include <LiquidCrystal_I2C.h>
- #include <Wire.h>
- LiquidCrystal_I2C lcd(0x20,20,4);
- //Frequencia
- long tempo, freq;
- int pulsos;
- boolean pulso;
- //Tensão
- #define resistance_R500 1000000
- #define resistance_V2 10000
- #define caliberation_V2 1.05
- #define range500_mul (resistance_R500 / resistance_V2) * caliberation_V2
- #define resistance_R2 1000
- int adc_value = 0;
- int voltage_peak_value = 0;
- float voltage_average_value = 0;
- float dc_voltage_V0 = 0;
- int ac_voltage_V0 = 0;
- unsigned long sample_count = 0;
- void setup()
- {
- pulso=HIGH;
- pinMode(2,INPUT);
- Serial.begin(9600);
- }
- void loop()
- {
- tempo = millis();
- Serial.println(tempo);
- if(digitalRead(2)==HIGH)
- {
- if(pulso==HIGH)
- {
- pulsos = pulsos + 1;
- }
- pulso=LOW;
- }
- else
- {
- pulso=HIGH;
- }
- if(tempo%1000==0)
- freq = (pulsos/2.0);
- else;
- delayMicroseconds(10);
- voltage_peak_value = 0;
- for(sample_count = 0; sample_count < 5000; sample_count ++)
- {
- adc_value = analogRead(A1);
- if(voltage_peak_value < adc_value)
- voltage_peak_value = adc_value;
- else;
- delayMicroseconds(10);
- }
- dc_voltage_V0 = voltage_peak_value * 0.00488;
- ac_voltage_V0 = (dc_voltage_V0 / 1.414) * range500_mul;
- Serial.print("FREQUENCIMETRO: ");
- Serial.print(freq);
- Serial.print("Hz ");
- Serial.print("VOLTIMETRO: ");
- Serial.println(ac_voltage_V0);
- pulsos=0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement