DIY Weather Station with Intel Galileo

dht11-sensorYour own DIY weather station is very useful if you for example want to optimize the growing process of your plants.

It gives you the possibility of getting real-time data or statistics about things the soil moistness, or the temperature around your plants.

In this tutorial, I will show you how to build your own DIY weather station using the Intel Galileo and a few sensors.

You’ll learn how to install a webserver on your Intel Galileo and how to customize it into showing all the sensor measurements you want to have available.

You can get the Intel Galileo from Amazon.

To follow this tutorial, you need to have your Intel Galileo running Linux from an SD-card. And you need either a WiFi card installed, or an ethernet cable to connect to a router.

In addition, you need the following components:

Getting started with Intel Galileo Board

Step 1: Connect Intel Galileo to a network

Connect your Intel Galileo to a router with Internet access via WiFi or ethernet cable. Connect your computer to the same network.

Now you need to find the IP address of your Galileo. You can do this by logging into the router’s admin page and check the list of connected devices. More ideas on finding the IP of your Intel Galileo here: IntelAcademic_IoT_03_Networking.pdf

My Galileo got the IP address

Step 2: Get up and running with SSH

Next, to be able to configure your DIY weather station, log in with SSH from the terminal like this (if using Linux or Mac):

ssh [email protected]

If you don’t know how to use SSH, check out one of these links:

Step 3: “Hello World!” from the web server

Next, you’re going to install a web server that will display the sensor values on a web page. This will be the heart of your DIY weather station.

To do this, you’re going to start by setting up a simple “Hello World” web server using Node.js as explained in one of Intel’s IoT lessons.

First, create an empty file called ‘hello.js’. Use ‘vi’ or another editor to add the code below into the file ‘hello.js’. Replace X.X.X.X with the IP address of your Galileo:

‘Vi’ can be confusing for first-timers. Here’s a quick guide:

var http = require('http');

    function (req, res) {
        res.writeHead(200,{'Content-Type': 'text/plain'});
        res.end('Hello World\n');
).listen(1337, ‘X.X.X.X');

console.log(‘Server running at http://X.X.X.X:1337/');

Then launch the web server by typing the command on your Galileo (through ssh):

node hello.js

After a couple of seconds, you should see the message:
‘Server running at http://X.X.X.X:1337/’

Then test your server from a PC on the same network, by opening a browser window with the address http://X.X.X.X:1337 (Exchange X.X.X.X with the IP of your Galileo)

You should see the text “Hello World”:

Intel Galileo webserver showing Hello World

Step 4: Display data from a file

Now, you want to display data from a file instead. This way, you can later create a program that writes sensor data to this file.

First, create a sample file ‘sensor-data.txt’, with the following content:

Temperature: 99
Air Humidity: 88
Soil Humidity: 77
Rain: 66

Then, create a new file ‘sensor-webserver.js’ with the following code, and replace X.X.X.X with your Galileo’s IP-address:

// Code from

var http = require('http');
var fs = require("fs");
var fileName = "/home/root/webserver/sensor-data.txt";

http.createServer(function (req, res) {
    fs.readFile(fileName, function (err,data) {
        if (err) {
}).listen(1337, ‘X.X.X.X');

console.log(‘Server running at http://X.X.X.X:1337/');

You should see the sample data you entered into the text-file:

Intel Galileo web server showing 'fake' sensor data

Now it’s starting to look like a proper DIY weather station!

Step 5: Connect the sensors for your DIY weather station

Connect your sensors to your Intel Galileo board. If you are unsure how, check out these tutorials:

Intel Galileo DIY Weather Station

Step 6: Write sensor values to file

It wouldn’t be a DIY weather station without any sensors that can sense the weather.

So, now it’s time to get real sensor data onto your web server. Since you already are showing data from a file in your web server, all you need to do is to write your sensor data to that file.

Upload the following code to your Intel Galileo:

#include "DHT.h"

#define DHTIN 2
#define DHTOUT 3
#define DHTTYPE DHT11 // DHT 11

//Define pins for the rain and soil sensors:

int sensorPinSoil = A0; // seleccionar el pin de entrada para el sensor de suelo
int sensorPinRain = A1; // seleccionar el pin de entrada para el sensor de lluvia

//Filename to write to
String fileName = "/home/root/webserver/sensor-data.txt";

void setup() {

    //Initialize the sensor

void loop() {

    String toBeWritten;
    char charBuf[1024];
    float humidity_value = 9999.0;
    float temperature_value = 9999.0;
    float soil_humidity_value = 9999.0;
    float rain_value = 9999.0;

    // Reading temperature or humidity takes about 250 milliseconds!
    // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
    humidity_value = dht.readHumidity();
    // Read temperature as Celsius
    temperature_value = dht.readTemperature();

    // Check if any reads failed and exit early (to try again).
    if (isnan(humidity_value) || isnan(temperature_value)) {
        Serial.println("Failed to read from DHT sensor!");
        humidity_value = 9999.0;
        temperature_value = 9999.0;

    // leer los valores de los sensores:
    soil_humidity_value = analogRead(sensorPinSoil);
    rain_value = analogRead(sensorPinRain);

    Serial.println("\nSensor readings:\n");
    Serial.print("Humidity: ");
    Serial.print(" %\t");
    Serial.print("Temperature: ");
    Serial.println(" *C ");
    Serial.println("Logging readings to file...\n\n");

    // Need to build a string that is to be written to file

    toBeWritten = "'****************************";
    toBeWritten.concat("\n Temperature (Celsius): ");
    toBeWritten.concat("\n Humidity: ");
    toBeWritten.concat("\n Rain: ");
    toBeWritten.concat("\n Soil Humidity: ");
    toBeWritten.concat("\n ");

    // Adding commands to execute on the linux system
    // echo '........' > /home/root/webserver/sensor-data.txt

    String command = "echo ";
    command.concat("' > ");
    command.toCharArray(charBuf, 500);

    // Wait 10 seconds between each reading

Step 7: Launch your DIY weather station

Everything is ready to go.

Test your server from a PC on the same network, by opening a browser window with this address:

http://X.X.X.X:1337 (Exchange X.X.X.X with the IP of your Galileo)

Intel Galileo DIY Weather Station Output

Voila! Your Intel Galileo DIY weather station is working. Feel free to add more sensors and customize the output in whatever way you like it.

Check out more Intel Galileo tutorials here

More Circuits & Projects Tutorials

3 thoughts on “DIY Weather Station with Intel Galileo”

  1. SyntaxError: Unexpected end of input
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:935:3

    i get this if i try to use ur code to read files form sd card, is there any library that have to be installed?

    • Sometimes when you do copy-paste from a website, you get this invisible signs that makes the compiler behave strangely. That’s my first guess.


Leave a Comment