IAN LANG ELECTRONICS

Happy birthday to me, happy birthday to me, my wife gave me a box of electronic sensors and there's more than thirty.

 

Thirty-seven to be precise, all hooked up on to neat little circuit boards ready to be plugged into an Arduino. Ooh, it is nice. The first one I tried is the subject of this article and it's a flame detector module by name but what it actually does is detect bright sources of light in the infra-red range 760 - 1100 nm and so it can be set off by bright light sources too. If it is twiddle the pot ant-clockwise a bit until it stops.

Go Back

A Flame Detection Module

flamdec

That's the bunny on the left there looking a tad bigger than  life-size and you can see that it consists of a photo-transistor, a multi-turn potentiometer, a lot of resistors, two LEDs and a chip. That chip is in fact a comparator, and it glories in the name of an LM393.

 

You have a ref voltage going in determined by the pot, and a voltage produced via the photo-transistor and one of the resistors, and it looks at the difference between the two and if it's sufficient in subtraction there's an output.

In point of fact you do not need an Arduino for this but since this is the Arduino section I've hooked it on to one to see what happens. Here's a short little video then:

So let's see the schematics and the code:

 

flamy

This is not a complicated construction as we are basically joining two printed circuit boards together and sticking an LED on. You can see that the module has four pins, the top one is the analogue out which I'm not using for this game, next down is GND and accordingly it goes the GND pin (or one of them, there's three on an Uno), and the next one after that is the 5V supply. The meat here is in the bottom pin on the diagram, because that's the digital output, and of course being digital it can either be 0 or 1 (0 being low volts and 1 being high). That's the impoertant bit in the following code. The LED is attached to pin 3 and via a resistor of 580 ohms or so it finds a path to ground; when pin 3 is high it shines and when pin 3 is low it doesn't. Here's the code that makes it work and you can get this in a text file by clicking the link on the left:

flamy1

#define flame 2

 

void setup() {

Serial.begin(9600);

pinMode (3,OUTPUT);

}

 

void loop() {

 

 Serial.println();

 //Serial.print("Digital output is: ");

 //Serial.print(digitalRead(flame));

if (digitalRead(flame)>0){Serial.println("Flame on");digitalWrite(3,1);}

else{digitalWrite(3,0);}

 

}

 

It's not a complex bit of code this one, so let's canter through line-by-line leisurely and see what it does. It begins with:

 

#define flame 2

 

This is something I don't normally do. #define means assigns a value to a named variable, and in this case it's the value of 2 to the variable flame. #define can lead to problems, but the advantage is that if you have a constant value such as a pin number you can change that value in the code at one go rather than going through the entire code changing things. in this case it's 2 because that's the pin number on the Arduino Uno into which I've stuck the digital output of the detector module. You'll notice it's outside the functions (setup and loop) which makes it a global variable (ie one that can be seen by all functions). The next bit is the setup function, which runs once when the power is  applied or the Arduino is reset. It goes:

 

Serial.begin(9600);

 

The serial monitor on your Arduino IDE is an extremely handy tool when you are testing a new piece of hardware or debugging some code. Here it's set to transfer at 9600 baud and I used it to see what the digital and analogue outputs were doing. The next line is:

 

pinMode (3,OUTPUT);

 

There's a built-in resistance on Arduino pins because they default to input. If you leave them as input and try to drive an output current through you'll have that resistance still there and the practical upshot is you won't have the juice to drive an LED. Setting it to output like this means 40mA can go through; that's more than enough.

 

Next we move on to the loop, which as the name implies goes on running round and round forever, or at least until the power goes off. It starts with three serial print lines:

 Serial.println();

 //Serial.print("Digital output is: ");

 //Serial.print(digitalRead(flame));

 

Serial.print() is a command to the Arduino to knock out through the serial port and via the USB connection to the IDE serial monitor any text or data we care to look at.   Serial.println(); means move to a new line (so we can see the data) and the next two are crossed as comments using the // symbol.

 

 //Serial.print("Digital output is: ");

 //Serial.print(digitalRead(flame));

 

If you scrub out // in both lines and reupload, in the serial monitor it will say either "Digital output is: 0" or "Digital output is: 1" depending on whether it's active or not.

 

Now we get to the meaty bit. The photo-transistor's attuned to infra-red more than white light and so the more IR it gets the more conductive it becomes disturbing the balance of the voltage divider and altering the voltage that reaches the comparator. When there's a sufficient voltage the comparator puts out 5V and when there isn't it doesn't. The Uno reads this at pin 3 as either low (0V) or high (5V). So we instruct it such:

 

if (digitalRead(flame)>0){Serial.println("Flame on");digitalWrite(3,1);}

else{digitalWrite(3,0);}

 

and breaking that down:

 

 

if (digitalRead(flame)>0

 

The only way it can be greater than 0 is to be 1, and so what we are saying is if you see a 1 (ie there's 5V at pin 3) do this:

 

{Serial.println("Flame on");    knock out the phrase "Flame on" to the serial monitor and

 

digitalWrite(3,1);}

 

switch pin 3 on - which will cause the LED to shine.

 

else is a complement to if and tells the Arduino what to do if the if statement's condition is not true, in this case that is if pin 3 = 0. It does this:

 

{digitalWrite(3,0);}

 

which switches the LED off.

 

That proves it works, but if there's  a raging inferno about to happen  somewhere I want to be warned about it by something more than a little LED hoping I happen to be looking in that direction. Granted I don't like the cold, but anything approaching 2000 degrees and flamey that's not seperated from me by a good distance and a great volume of air or vacuum is not my idea of a good time either. My motto is: in the event of a workplace fire, follow the screaming and blurry thing that looks vaguely like me and try to keep up.

 

So we need some audibility. We need a whacking big siren. The problem with a whacking big siren is that you need a whacking big voltage to drive it. So we are going to use in this experiment a horribly loud siren that works on 9V and can be heard a good distance off; it's not up to the noisiness of an industrial siren but you can use in domestic situations. It's horribly loud at 1m and so do not get your ears too close to it (or any other for that matter)  as you'll get a sharp pain to your lugs and may go deaf too.

 

So we are going to turn to a trusty old standby that we keep around lang towers for just such occasions, and it's a two-tone alarm I bought from Maplin several years ago. Maplin call it the KU60Q and there it is below.

 

 

 

 

 

 

 

siren

It's got five leads and the red and black ones are the power supply whilst if you join any two of the others together you get a different tone out of the siren. It's actually  horribly loud at 9V and unbearable at 12V and therein lies the problem because we want to run the detector at 5V and the alarm at 9V.

 

This is where a microcontroller makes life much easier for us as we can feed the Arduino 9V and the onboard regulator will slap it down to 5V for the detector. Moreover we can use the 9V feed, take a distribution from it before it gets to the Arduino and feed that to the siren. We cant do that directly though. We need either a transistor or a relay, or both, and I'm going for the relay because later we could develop it for anything up to 30V DC and 10A (300W) if we wanted which we couldn't with a transistor system except at great expense. The first method we are going to use is the wrong one.

More >