LM393 Flame sensor

In this example we are going to connect the Raspberry Pi or alternate board to flame sensor.

Programming for this sensor works on exactly the same principle as the HC-SR501 infrared sensor and the F85 vibration sensor except the signal from this sensor comes inverted.  As in it will send 1 when everything is all right and zero if it sees flame.

This one  gave very reliable readings when doing the lighter test with it.

The LM393 comes in 3 pin version and as 4 pin version. The difference is that 3 pin version has one digital output, while the 4 pin version has digital output and analog output.
The I had for this example had only digital output.

LM393 Flame sensors, 3 and 4 pin versions

DISCLAIMER

We do not take any responsibility for possible errors in the guide or errors that you might do wiring it up. Incorrect wiring can result in damaged sensor or damaged Raspberry Pi.

Pieces we use:

First thing is connecting the sensor:


Flame sensor


This sensor comes with good markings so its very easy to wire it.

Warning

When measuring up this sensor then it shows the digital output will have same voltage as the input. Meaning you  have to connect 3.3 V to the input when using with the Raspberry Pi.

The potentiometer on the board allows you to adjust the sensitivity of the DO output. (The potentiometer does not affect AO output if AO output is present).

The board has PWR_LED and a DO_LED. 

Note that variant of this sensor also exists that has additionally AO pin which is analog output.

The sensor will have the PWR_LED showing that it is turned on,  and the DO_LED lights up when it sees flame, making it send LOW signal, while when there is no flame it will be sending HIGH.

If AO output is present then the AO will have higher value the higher the infrared intensity in the surrounding environment is.


Spec on this sensor is:

If you are not familiar with working with a breadboard or on how to place a cobbler on the breadboard then click here bellow

Breadboard

Raspberry Pi pin layout

If you need more information about the GPIO headers on Raspberry Pi or other boards then click bellow.

Raspberry Pi Pin guideOrange Pi One Pin guideOrange Pi Pin guide for most H3 modelsOrange Pi Zero 3 Pin  guideOrange Pi 5 Plus Pin guideRock 64 Pin guide

Raspberry Pi pin layout

The Xojo Code

Private mLineRequest As Gpiod.LineRequest

And then Opening event for the Window:

Sub Opening() Handles Opening
  try
    using Gpiod
    
    var chip as Chip = Chip.Open("/dev/gpiochip0")
    
    var lineRequest as LineRequest = RequestInputLine(chip, 5, "flame-sensor")
    
    lineRequest.RequestReadEdgeEventsAsync(5, true, AddressOf LineMonitorCallback)
    
  catch e as GpiodException
    MessageBox(e.Message)
  end try
End Sub

Helper function to set up the line

Public Function RequestInputLine(chipHandle as Gpiod.Chip, lineOffset as UInt32, consumer as String) As Gpiod.LineRequest
  using Gpiod
  
  // Exceptions will be caught by the caller method
  
  var reqCfg as RequestConfig = nil
  
  var setting as new LineSetting()
  setting.Direction = Gpiod.Direction.INPUT
  setting.EdgeDetection = Gpiod.LineEdge.FALLING
  setting.Bias = Gpiod.LineBias.PULL_UP
  
  var lineCfg as new LineConfig()
  lineCfg.AddLineSetting(array(lineOffset),setting)
  
  if consumer <> "" then
    reqCfg = new RequestConfig()
    reqCfg.Consumer = consumer
  end if
  
  return chipHandle.RequestLines(reqCfg, lineCfg)
End Function

Callback for our events:

Public Sub LineMonitorCallback(edgeEvent as Gpiod.EdgeEvent)
  lstEvents.AddRow(if(edgeEvent.EventType = Gpiod.EdgeEventType.RISING_EDGE, "Rising", "Falling"))
  lstEvents.CellTextAt(lstEvents.LastRowIndex, 1) = edgeEvent.LineOffset.ToString()
  lstEvents.CellTextAt(lstEvents.LastRowIndex, 2) = edgeEvent.LineSequenceNumber.ToString
  lstEvents.CellTextAt(lstEvents.LastRowIndex, 3) = edgeEvent.TimestampNs.ToString()
End Sub

Getting the code

You can find this example code at Example code for GPIO guides.