Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Reference:
- // https://circuitdigest.com/microcontroller-projects/interfacing-flame-sensor-with-arduino
- // https://circuitdigest.com/microcontroller-projects/arduino-frequency-counter-circuit
- // https://www.instructables.com/Arduino-Frequency-Counter/
- // https://github.com/Bodmer/TFT_eSPI/blob/master/examples/160%20x%20128/TFT_Print_Test/TFT_Print_Test.ino
- // Uses IR Infrared Flame Sensor Module 4 Pin
- #include "Arduino.h"
- #include <TFT_eSPI.h> // Graphics and font library for ILI9341 driver chip
- #include <SPI.h>
- // Pin Assignments
- #define IR_Pin 2
- // Variables
- unsigned long H_cycle;
- unsigned long L_cycle;
- unsigned long Freq;
- char str_Freq[32];
- TFT_eSPI tft = TFT_eSPI(); // Invoke TFT library
- void setup(){
- // Initalize GPIO pins
- pinMode(IR_Pin, INPUT);
- // Initalize Serial port
- Serial.begin(9600);
- // Initalize TFT
- tft.init();
- tft.setRotation(1);
- tft.fillScreen(TFT_BLACK);
- }
- void loop (){
- Freq = 0;
- //tft.fillScreen(TFT_BLACK);
- H_cycle = pulseIn(IR_Pin,HIGH); // read signal at high state
- L_cycle = pulseIn(IR_Pin,LOW); // read signal at low state
- if((H_cycle + L_cycle) != 0){
- Freq = 1000000 / (H_cycle + L_cycle); // covert H + L cycles in Micro seconds to Frequency
- }
- // format output string
- snprintf_P(str_Freq, sizeof(str_Freq), PSTR("Freq: %u Hz"), Freq);
- // output string to serial port
- Serial.println (str_Freq);
- // output string to tft display
- tft.setCursor(0, 0, 4);
- tft.setTextColor(TFT_GREEN,TFT_BLACK);
- tft.println("IR Meter");
- tft.println("");
- tft.println(str_Freq);
- //delay(3000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement