Industrial manufacturing
Industrial Internet of Things | Industrial materials | Equipment Maintenance and Repair | Industrial programming |
home  MfgRobots >> Industrial manufacturing >  >> Manufacturing Technology >> Manufacturing process

Build a Fast, Reliable Fire Detection System with Samsung SAMIIO, Arduino UNO & Raspberry Pi

This tutorial guides you through creating a compact IoT fire detection system that streams flame sensor readings to Samsung SAMIIO via WebSockets, using an Arduino UNO and Raspberry Pi.

We’ll employ a simple, off‑the‑shelf IR flame sensor, upload a lightweight sketch to the Arduino, and run a Node.js script on the Raspberry Pi that forwards the data to SAMI.

Prerequisites

For this tutorial you should be familiar with the basic SAMI APIs.

Architecture

The diagram below illustrates the high‑level flow:

Software components:

Download the software now.

If you don’t have a Raspberry Pi, you can still follow the steps. Connect the Arduino to a computer with internet access and run the Node.js script on that machine instead.

Step 1: Create and connect a new device type

  1. Sign into the SAMI Developer Portal. If you don’t have a Samsung account, create one now.
  2. Click “+ New Device Type”.
  3. Name the device type “Flame Sensor” and assign a unique identifier such as “com.example.iot.flame”.
  4. Click “Create Device Type” and proceed to the device types page.

Now create a Manifest for the “Flame Sensor” device type.

  1. In the left column, click “Flame Sensor”.
  2. Navigate to “Manifest” and click “+ New Version”.
  3. Enter onFire as the Field Name and choose Boolean as the Data Type.
  4. Click “Save” and then “Next: Actions”.
  5. Bypass Actions for this tutorial and click “Save New Manifest”.

A Simple Manifest is automatically approved. Do not publish this device type, as it is intended solely for tutorial purposes.

Finally, connect a new Flame Sensor device via the User Portal:

  1. Sign into the SAMI User Portal.
  2. On the dashboard, click to connect a new device.
  3. Choose the “Flame Sensor” device type you just created.
  4. Click “Connect Device…”. You’ll return to the dashboard.
  5. Click the settings icon of the added device. In the pop‑up, select “GENERATE DEVICE TOKEN…”.
  6. Copy the device ID and device token displayed – you’ll need them in the code.

Step 2: Set up the Arduino

Wire the IR flame sensor to the Arduino as shown in the diagram above. Then upload the following sketch (read_flame_sensor.ino) using the Arduino IDE. The sketch reads the sensor every 5 seconds (adjustable) and sends the digital value to the serial port. In SAMI, “0” indicates fire detected; “1” means no fire.

/* read_flame_sensor.ino */
// Delay between reads
const int delayBetweenReads = 5000; // 5 seconds
// Flame detector sensor pin
const int flameDigitalPinIn = 2;

void setup() {
  // Initialize serial communication at 9600 baud
  Serial.begin(9600);
  pinMode(flameDigitalPinIn, INPUT);
}

void loop() {
  // HIGH (1) = no fire, LOW (0) = fire detected
  int flameDigitalReading = digitalRead(flameDigitalPinIn);
  Serial.println(String(flameDigitalReading));
  delay(delayBetweenReads);
}

Step 3: Set up the Raspberry Pi

Connect the Raspberry Pi to a monitor, mouse, and keyboard. Ensure it has a working Ethernet or Wi‑Fi connection and that the OS is up to date:

  1. $ sudo apt-get update
  2. $ sudo apt-get upgrade

If Node.js is not yet installed, install the ARM‑compatible version and then add the required packages via npm:

  1. $ npm install serialport
  2. $ npm install ws

Connect the Arduino’s serial port to a USB port on the Raspberry Pi.

Download the Node.js script (send_data_to_sami.js) and replace the placeholder values for device_id and device_token with the credentials you copied earlier.

/* send_data_to_sami.js */
var webSocketUrl = "wss://api.samsungsami.io/v1.1/websocket?ack=true";
var device_id = "YOUR_DEVICE_ID";
var device_token = "YOUR_DEVICE_TOKEN";

var isWebSocketReady = false;
var ws = null;

var serialport = require("serialport");
var SerialPort = serialport.SerialPort;

var sp = new SerialPort("/dev/ttyACM0", {
  baudrate: 9600,
  parser: serialport.parsers.readline("\n")
});

var WebSocket = require('ws');

/**
 * Gets the current time in milliseconds
 */
function getTimeMillis(){
  return parseInt(Date.now().toString());
}

// Establish WebSocket connection and register device
ws = new WebSocket(webSocketUrl, {
  headers: {
    "Authorization": `Bearer ${device_token}`
  }
});

ws.on("open", () => {
  isWebSocketReady = true;
  register();
});

function register() {
  var registerMsg = {
    "topic": "sami/device/register",
    "data": {
      "deviceId": device_id
    }
  };
  ws.send(JSON.stringify(registerMsg));
}

sp.on("data", (data) => {
  if (isWebSocketReady) {
    var message = {
      "topic": "sami/device/telemetry",
      "data": {
        "onFire": data.trim() === "0"
      }
    };
    ws.send(JSON.stringify(message));
  }
});

Once the script is running, your flame sensor readings will be streamed to SAMI in real time.

For more detail, refer to the full tutorial: Make a fire detector in minutes with Samsung SAMIIO, Arduino UNO and Raspberry Pi.

Manufacturing process

  1. Build a Robot with Raspberry Pi and Python: A Complete Guide
  2. Build an Internet‑Controlled Video‑Streaming Robot with Arduino & Raspberry Pi
  3. Control Your Roomba Create 2 Using Arduino and Android: A Step-by-Step Guide
  4. Build a 4x4x4 LED Cube with Arduino Uno & 1Sheeld – Interactive LED Project
  5. Create Musical Tones with Arduino: A Step‑by‑Step Guide
  6. Remote Car Control Using Arduino Uno & Bluetooth: A Step‑by‑Step Guide
  7. Build a Raspberry Pi 3 & Arduino Laptop: Step‑by‑Step Guide
  8. Build Stunning Web-Driven LED Animations with Raspberry Pi & Arduino
  9. Build an Arduino LCD Thermometer Using LM35/36 Temperature Sensor
  10. Efficiently Program ATtiny85 Using Arduino Uno: A Cost‑Effective Multi‑Sensor Solution