Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // frequencimetro de 60Hz
- // Voltimetro
- #include <LiquidCrystal.h>
- LiquidCrystal lcd(13,12,11,10,9,8);
- long freq, tempo, TOld, TNew;
- #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()
- {
- Serial.begin(9600);
- pinMode(2,INPUT);
- lcd.begin(20, 2);
- lcd.setCursor(3,0);
- lcd.print("FREQUENCIMETRO");
- Serial.print("FREQUENCIMETRO");
- attachInterrupt(0, frequencia, RISING);
- }
- void loop()
- {
- voltagem();
- delay(20);
- }
- //=============================== VOLTAGE ========================================//
- void voltagem()
- {
- voltage_peak_value = 0;
- for(sample_count = 0; sample_count < 500; sample_count ++)
- {
- adc_value = analogRead(A1);
- if(voltage_peak_value < adc_value)
- voltage_peak_value = adc_value;
- else;
- delayMicroseconds(1);
- }
- dc_voltage_V0 = voltage_peak_value * 0.00488;
- ac_voltage_V0 = (dc_voltage_V0 / 1.414) * range500_mul;
- lcd.setCursor(0,0);
- Serial.print("V");
- lcd.setCursor(3,0);
- Serial.println(ac_voltage_V0);
- }
- //=============================== FREQUENCY ========================================//
- void frequencia()
- {
- tempo = micros();
- TOld = tempo - TNew;
- TNew = tempo;
- freq = (10000000/TOld)+5; // +5 correção de erro de divisão
- lcd.setCursor(7,1);
- Serial.print(freq/10);
- lcd.setCursor(13,1);
- Serial.println("Hz");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement