O'Reilly logo

Internet of Things Programming with JavaScript by Ruben Oliva Ramos

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Detecting fire with a sensor

If there's a fire in our home, it's vital to detect it; so in the next section, we will create a project that detects fire with a sensor.

In the following image, we see of the fire sensor module:

Detecting fire with a sensor

You can now either copy the code inside a file called Sensor_fire.ino, or just get the complete code from the folder for this project.

We define the variables for our program at the beginning:

int ledPin = 13;             
int inputPin= 2; 
int val = 0;                    

We define the output signals and the serial communication:

void setup() { 
pinMode(ledPin, OUTPUT);       
pinMode(inputPin, INPUT);      
Serial.begin(9600); 
} 

Now we display the value of the digital signal: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required