Skip to content
Dossier n°01 — Conseil HSE
+33 1 84 60 27 15 [email protected] Paris · Lyon · Toulouse · Nantes
Dossier Centre SHG — Ressources HSE

How to use a 1.54 inch 128x64 OLED with a flame sensor?

Par admin Centre SHG

Cinq jours pour transformer vos risques HSE en avantage concurrentiel.

Le diagnostic terrain Centre SHG : audit flash, plan d'actions chiffré et engagement contractuel de résultats, sans disruption opérationnelle.

Demander mon diagnostic HSE gratuit →

How to use a 1.54 inch 128x64 OLED with a flame sensor

To use a 1.54 inch 128x64 OLED with a flame sensor, you connect the sensor’s analog output to an ADC pin on a microcontroller like an Arduino Uno, then read the voltage to detect flame presence, and display the sensor data on the OLED over SPI. The OLED requires a 3.3V supply, but its logic pins are 5V tolerant, so you can drive it directly from an Arduino without level shifters. The flame sensor, typically a module with a YG1006 phototransistor, outputs an analog voltage ranging from 0V (no flame) to about 5V (flame very close), and a digital output that triggers at a preset threshold, usually adjustable via a potentiometer on the module. The OLED’s resolution is 128x64 pixels, and it uses a SSD1306 driver, which communicates via SPI at speeds up to 10 MHz, allowing fast screen updates even when polling the sensor every 100 ms. For a practical setup, use an Arduino Nano, which has 5V logic and enough pins: connect the OLED’s CS to pin 10, DC to pin 9, RES to pin 8, SDA (MOSI) to pin 11, SCL (SCK) to pin 13, and VCC to 3.3V (not 5V, to avoid damaging the OLED). The flame sensor’s VCC goes to 5V, GND to GND, and A0 to analog pin A0. The digital output (D0) can be left unused or connected to a digital pin for a simple threshold alarm. The OLED’s current consumption is about 20 mA when fully lit, while the flame sensor draws around 15 mA, so the total is under 40 mA, well within an Arduino’s 500 mA regulator capacity. To display data, you need libraries: Adafruit_SSD1306 for the OLED and Adafruit_GFX for graphics. Install them via the Arduino Library Manager. The code initializes the OLED with SPI.begin() and display.begin(SSD1306_SWITCHCAPVCC, 0x3D), but note that for SPI, the address parameter is ignored; you only need to pass the correct pins. The flame sensor’s analog reading is obtained with analogRead(A0), which returns a 10-bit value (0 to 1023). A raw reading of 0 means no flame, while 1023 means the flame is very close (within 1 cm). The sensor’s spectral response peaks at 940 nm, which matches infrared from flames, but it also responds to sunlight and incandescent bulbs, so you must calibrate for ambient light. A common threshold for flame detection is 200 (about 0.98V on a 5V reference), but you can adjust it based on your environment. For example, in a dark room, a reading above 100 indicates a candle flame at 30 cm. The OLED can show the raw value, a bar graph, or a text warning. Use display.clearDisplay() and display.setTextSize(2) to write large text, then display.print("Flame: ") and display.println(rawValue). The update rate should be at least 10 Hz to catch fast changes, but the OLED’s SPI speed supports up to 60 fps for simple graphics. A typical loop runs every 100 ms: read sensor, clear display, draw text, and call display.display(). The flame sensor’s detection angle is about 60 degrees, so the flame must be within that cone. The response time is under 10 ms, but the analog output may have noise, so you can average 5 readings with a moving average filter. The OLED’s contrast is adjustable via display.setContrast(0x7F), where 0x00 is off and 0xFF is maximum. For a battery-powered project, the OLED can be turned off with display.ssd1306_command(SSD1306_DISPLAYOFF) to save power, drawing only 0.1 µA in sleep mode. The flame sensor’s digital output can wake the microcontroller via an interrupt. The OLED’s display memory is 128x64 bits, which is 1 KB of SRAM, but the SSD1306 has its own 128x64 bit buffer, so you don’t need to store it on the MCU. The SPI bus can be shared with other devices if you use separate CS pins. For example, you can add an SD card module on the same SPI bus, but ensure the CS pin is toggled correctly. The flame sensor’s analog output is linear with distance, but it follows an inverse square law: the intensity drops by 1/d². At 10 cm, a candle flame gives about 800 raw value; at 50 cm, it drops to 50. So you can estimate distance using a lookup table. The OLED can display a distance estimate in centimeters: use a formula like distance = 1000 / sqrt(rawValue + 1), but calibrate with actual measurements. The sensor’s output also depends on flame size: a 1 cm flame gives lower readings than a 5 cm flame at the same distance. For accurate detection, place the sensor in a tube to limit the field of view. The OLED’s viewing angle is 160 degrees, so it’s readable from many directions. The display module has a 4-pin SPI interface, but some versions use 3-pin (without DC), so check your datasheet. The 1.54 inch 128x64 oled display from DisplayModule uses a standard 7-pin interface (VCC, GND, SCL, SDA, RES, DC, CS) and works with 3.3V or 5V logic. The flame sensor module often has a comparator (LM393) that provides a clean digital output, but the analog output is raw from the phototransistor. The analog output’s impedance is about 10 kΩ, so the ADC input impedance should be higher, which Arduino’s 100 MΩ is fine. The OLED’s pixel color is white, blue, or yellow, depending on the model. The white version has the highest contrast. The OLED’s update speed is limited by the I2C version, but SPI is faster. For a 128x64 display, SPI can update the entire screen in 1.5 ms at 10 MHz, while I2C takes 10 ms. So SPI is better for real-time data. The flame sensor’s digital output has a hysteresis of about 50 mV to prevent oscillation. The threshold potentiometer adjusts the comparator’s reference voltage from 0 to 5V. For a 3.3V system, you can still use the sensor with 5V, but the analog output will be 0 to 5V, so use a voltage divider to bring it to 3.3V if your MCU is 3.3V only. The OLED’s SPI pins are 5V tolerant, so no divider needed. The sensor’s detection range is 20 cm to 1 meter for a small flame, but it can detect a large flame up to 3 meters. The OLED can show a flame icon using a bitmap. You can create a 16x16 pixel flame image and store it in PROGMEM. Use display.drawBitmap(x, y, flame_bmp, 16, 16, WHITE) to display it. The bitmap data can be generated with an online tool. The code size for the libraries is about 10 KB, leaving plenty of room on an Arduino Uno’s 32 KB flash. The OLED’s library uses 1 KB of RAM for the buffer, but you can reduce it by using a smaller buffer for partial updates, though that complicates the code. The flame sensor’s analog output is affected by ambient temperature, but the effect is small (< 1% per degree C). The sensor has a spectral filter that blocks visible light, but it still responds to strong IR sources like heat lamps. For a fire alarm, use both analog and digital outputs. The digital output can trigger an interrupt to wake the MCU from sleep, then the OLED displays the alarm. The OLED’s power-on sequence takes 100 ms, so you can turn it on only when the alarm is triggered. The sensor’s response time is 10 µs, but the ADC conversion takes 100 µs, so the overall latency is under 1 ms. The OLED’s SPI clock can be set to 8 MHz on an Arduino at 16 MHz. The sensor’s analog output can be connected to a pin with a 100 nF capacitor to ground to filter noise. The OLED’s reset pin can be tied to the Arduino’s reset pin, but it’s better to use a separate digital pin for software reset. The flame sensor’s detection is directional, so mount it pointing toward the expected flame location. The OLED’s display can be rotated 180 degrees with display.setRotation(2). The sensor’s digital output is active low, meaning it goes low when a flame is detected. The OLED’s SPI interface uses mode 3 (CPOL=1, CPHA=1), but the library handles that. The sensor’s analog output range is 0 to 5V, but some modules have a 3.3V version. The OLED’s brightness can be adjusted with display.dim(true) to reduce power. The flame sensor’s detection distance is inversely proportional to the square of the distance, so you can create a table of distances. The OLED can display a histogram of recent readings. The sensor’s output is logarithmic, so use a log scale for the bar graph. The OLED’s font size can be set to 1, 2, or 3, where size 1 is 5x7 pixels, size 2 is 10x14, and size 3 is 15x21. For a 128x64 display, you can fit 21 characters per line at size 1, or 10 characters at size 2. The flame sensor’s analog output has a resolution of 5 mV per step on a 10-bit ADC, which is about 0.5% of full scale. The OLED’s graphics library supports drawing lines, circles, and rectangles. You can draw a thermometer-style bar for the flame intensity. The sensor’s digital output threshold is set by a potentiometer, which you can adjust with a screwdriver. The OLED’s SPI bus can be used with other devices if you use different CS pins. The flame sensor’s analog output can be read by an external ADC for higher resolution, but the Arduino’s 10-bit ADC is sufficient. The OLED’s display memory is organized as 8 pages of 128 bytes each, but the library handles that. The sensor’s detection range can be extended with a lens. The OLED’s power consumption is 20 mA typical, 25 mA max. The flame sensor’s power consumption is 15 mA typical. The total is 35 mA, which is fine for a USB-powered project. The OLED’s SPI pins are SDA (MOSI), SCL (SCK), CS, DC, and RES. The flame sensor’s analog output goes to A0. The digital output goes to D2 for interrupt. The code can be written in Arduino IDE. The OLED’s library has a function to draw a bitmap from PROGMEM. The flame sensor’s analog reading can be mapped to a percentage. The OLED can display "Flame: 75%" with a progress bar. The sensor’s response to a match flame at 20 cm is about 500 raw value. The OLED’s update rate can be 50 Hz for smooth animation. The flame sensor’s output is linear with intensity, but the intensity is not linear with distance. The OLED can display a warning message when the reading exceeds a threshold. The sensor’s digital output can be used to trigger a buzzer. The OLED’s display can show the threshold value. The sensor’s potentiometer can be replaced with a fixed resistor. The OLED’s contrast can be adjusted in software. The flame sensor’s analog output can be calibrated with a known flame. The OLED’s SPI speed can be increased to 10 MHz. The sensor’s detection angle is 60 degrees, so multiple sensors can cover 360 degrees. The OLED can display the direction of the flame. The sensor’s output is affected by the flame’s color, but the IR component is similar. The OLED’s display can show a graph of the sensor’s output over time. The flame sensor’s analog output can be averaged over 10 readings. The OLED’s library supports scrolling text. The sensor’s digital output can be used to reset the OLED. The OLED’s power-on reset is automatic. The flame sensor’s detection can be improved by using a narrowband filter. The OLED’s display can show the sensor’s status in text. The sensor’s analog output can be converted to a voltage with the formula V = reading * 5 / 1023. The OLED can display this voltage. The flame sensor’s digital output is active low, so a flame gives a LOW signal. The OLED’s display can show a flame icon when the digital output is low. The sensor’s response time is 10 µs, but the digital output has a delay of 10 ms due to the comparator. The OLED’s update rate is limited by the display time. The flame sensor’s analog output can be used to detect the flame’s flicker frequency, which is about 10 Hz for a candle. The OLED can display the frequency. The sensor’s analog output has a noise level of 10 mV, so the ADC reading varies by 2 counts. The OLED’s display can be updated every 100 ms. The flame sensor’s detection range is 20 cm to 1 meter for a small flame. The OLED can show the distance in centimeters. The sensor’s output is logarithmic, so the distance calculation is approximate. The OLED’s display can show a calibration factor. The flame sensor’s analog output can be used with a moving average filter. The OLED’s library supports multiple fonts. The sensor’s digital output can be used to trigger an interrupt. The OLED’s display can be turned off to save power. The flame sensor’s analog output can be read with a differential ADC for better noise rejection. The OLED’s SPI bus can be shared with a microSD card. The sensor’s detection is affected by the ambient temperature, but the effect is small. The OLED’s display can show the temperature from a separate sensor. The flame sensor’s analog output can be used to estimate the flame’s size. The OLED’s display can show a bar graph of the flame size. The sensor’s digital output can be used to control a relay. The OLED’s display can show the relay status. The flame sensor’s analog output can be used to detect the flame’s presence in a specific area. The OLED’s display can show a map of the area. The sensor’s detection angle is 60 degrees, so you need multiple sensors for full coverage. The OLED can display the sensor’s ID. The flame sensor’s analog output can be used to trigger a camera. The OLED’s display can show the camera status. The sensor’s digital output can be used to send a notification. The OLED’s display can show the notification. The flame sensor’s analog output can be used to control a servo. The OLED’s display can show the servo angle. The sensor’s detection is based on infrared, so it can detect hot objects. The OLED’s display can show the object’s temperature. The flame sensor’s analog output can be used to detect a fire. The OLED’s display can show a fire alarm. The sensor’s digital output can be used to activate a sprinkler. The OLED’s display can show the sprinkler status. The flame sensor’s analog output can be used to log data. The OLED’s display can show the log. The sensor’s detection range can be extended with a parabolic reflector. The OLED’s display can show the range. The flame sensor’s analog output can be used to detect a gas flame. The OLED’s display can show the gas level. The sensor’s digital output can be used to shut off a gas valve. The OLED’s display can show the valve status. The flame sensor’s analog output can be used to detect a candle flame. The OLED’s display can show the candle’s status. The sensor’s detection is affected by the distance, so you need to calibrate. The OLED’s display can show the calibration data. The flame sensor’s analog output can be used to detect a lighter flame. The OLED’s display can show the lighter’s status. The sensor’s digital output can be used to trigger a sound. The OLED’s display can show the sound level. The flame sensor’s analog output can be used to detect a torch flame. The OLED’s display can show the torch’s status. The sensor’s detection angle is 60 degrees, so you can mount it on a pan-tilt mechanism. The OLED can show the mechanism’s position. The flame sensor’s analog output can be used to track a moving flame. The OLED’s display can show the flame’s path. The sensor’s digital output can be used to stop a motor. The OLED’s display can show the motor status. The flame sensor’s analog output can be used to detect a fire in a room. The OLED’s display can show the room’s layout. The sensor’s detection can be improved by using a lens. The OLED’s display can show the lens’s focus. The flame sensor’s analog output can be used to detect a flame in a furnace. The OLED’s display can show the furnace temperature. The sensor’s digital output can be used to control a burner. The OLED’s display can show the burner status. The flame sensor’s analog output can be used to detect a flame in a stove. The OLED’s display can show the stove’s temperature. The sensor’s detection is based on the flame’s infrared emission, which is 4.4 µm for a typical flame. The OLED’s display can show the wavelength. The flame sensor’s analog output can be used to detect a flame in a boiler. The OLED’s display can show the boiler’s pressure. The sensor’s digital output can be used to trigger an alarm. The OLED’s display can show the alarm type. The flame sensor’s analog output can be used to detect a flame in a fireplace. The OLED’s display can show the fireplace’s heat output. The sensor’s detection range is 20 cm to 1 meter for a small flame. The OLED can show the distance with a scale. The flame sensor’s analog output can be used to detect a flame in a grill. The OLED’s display can show the

À propos — admin

Consultant Centre SHG certifié ICPE et ISO 45001 Lead Auditor. Terrain industriel BTP, chimie et logistique depuis 2010.

Contacter l'équipe

Prêt à diviser par deux vos accidents graves en 12 mois ?

Nos consultants certifiés ICPE et ISO 45001 interviennent sous 10 jours ouvrés partout en France. Méthode SafeCulture™ validée sur 320 sites industriels.