Skip to main content

Arduino Code to connect a flame sensor and gas sensor

The code below is uded to interface arduino with a flame sensor and a gas sensor together:

int redLed = 12;

int greenLed = 13;

int smokeA0 = A0;

int flamePin = 11;

int Flame = HIGH;

int sensorThres=100;

void setup() 

{

  pinMode(redLed, OUTPUT);

  pinMode(greenLed,OUTPUT);

  pinMode(flamePin, INPUT);

  pinMode(smokeA0,INPUT);

  Serial.begin(9600);

}


void loop() 

{

  int analogSensor = analogRead(smokeA0);

  Flame = digitalRead(flamePin);

  if (Flame== LOW)

  {

    Serial.println("Fire!!!");

    digitalWrite(redLed, HIGH);

  }

  else

  {

    Serial.println("No worries");

    digitalWrite(redLed, LOW);

  }

  Serial.print("Pin A0: ");

  Serial.println(analogSensor);

  // Checks if it has reached the threshold value

  if (analogSensor > sensorThres)

  {

    digitalWrite(greenLed, HIGH);

  }

  else

  {

    digitalWrite(greenLed, LOW);

  }

  delay(100);

}

Comments

Popular posts from this blog

PN Sequence Generator Circuit Design in Multisim

 I tried doing a PN Sequence generator using a shift register in Multisim but it didn't work. However this one with d flip flops and xor gate did work somewhat. Here is the circuit.       Components Required:      1. 4D Flip Flops      2. XOR Gate      3. Function Generator for Clock Pulses      4. Oscilloscope       Circuit Design  :        Output:- Red Square waves- Clock Pulses Blue waves- PN sequence Hope this helps!

How to plot a Continuous Time Sequence and Discrete Time Sequence in Matlab

1. For Continuous Time Sequence:        Use the function:  plot(X-axis, Y-axis)          For example to plot a parabolic function p(t)=  At^2 for t>=0                                                                                    0        for t<0           Code:           %UNIT PARABOLIC FUNCTION t=linspace(-20,20,20);      %range of X-asis A=1;                  %amplitude of the function for A=1 it is called unit parabolic function p=[t>=0].*(A.*t.^2)/2;      %parabola equation as defined above subplot(1,2,1);                ...

DFT Circular Convolution by Overlap Add Method in Matlab

  Matlab Code:       clc; close all ; x=input( 'Enter the input sequence: ' ); h=input( 'Enter the impulse sequence: ' ); n=length(x); m=length(h); z=1; for i=1:4     if i~=4         for j=1:m             X(i,j)=x(((i-1)*m)+1+(j-1));         end         for j=m+1:5             X(i,j)=0;         end     else         for j=1:5             if j==1                 X(i,j)=x(n);             else       ...