Posts | Comments

Planet Arduino

Archive for the ‘tutorials’ Category


Hands on: the Arduino Yún’s Bridge

Announcements, arduino, Arduino Yún, tutorial, tutorials, Yun Commenti disabilitati su Hands on: the Arduino Yún’s Bridge 

arduino yun - handson

The other day, we gave you an overview of the Yún’s hardware. Today, we are going to talk about the Bridge library, describing how it facilitates communication between the two processors. The Arduino Yún has two different processors on-board: an Atheros AR9331 running Linino (a customized OpenWRT GNU/Linux distribution maintained by Dog Hunter) linked through its serial port with an Atmel ATMega32U4 (the same processor as the Leonardo).
The Bridge concerns itself with communication between these two parts of the Yún.

The Bridge is made of two different parts
One part, written in Python, runs on the GNU/Linux processor and has three functions:

  1. it executes programs on the GNU/Linux side, when asked by Arduino.
  2. it provides a shared storage space, useful for sharing data like sensor readings between the Arduino and the Internet
  3. it receives commands coming from the Internet and passes them directly to the Arduino

The other part of Bridge is the library that runs on the 32U4. The library allows you to access the Linino parts of Bridge through your sketches.

The awesomeness of the Bridge
With the Bridge you can do some awesome things by communicating between the 32U4 and the AR9331 processors. Some examples could be commanding and controlling your sketch over the internet from a remote location, accessing remote APIs to get data for your sketch to process, or executing programs or scripts too complex to write in an Arduino sketch.

For example, if your shop is on the other side of the house, and you wanted to know if it was comfortable enough to work in there, you can connect a LDR sensor and thermistor to your Yún, which is also connected to your home wireless network. Your sketch can access the board’s shared storage to publish the readings every second to a webpage running on the AR9331. By accessing the URL http://arduino.local/data/get you can call up those readings, letting you know if it’s bright enough but not too hot to get to work on your next project.

Your sketch could also store the sensor readings on a Google Drive spreadsheet or publish them on Facebook. The Temboo library relies on the Bridge to access all the internet based services and APIs provided by Temboo.

Using Bridge, you would no longer need to upload a new version of a sketch to change text on an LCD screen: your sketch can use the shared storage to read the text to display, changing it remotely from a browser using REST based calls. If the text to be displayed is identified by the label “lcd_text”, accessing the URL http://arduino.local/data/put/lcd_text/Hello%20World will show “Hello World” on the LCD.

Finally, you can send your own command to your sketch remotely. You can create a firmata-like access to every single pin of the board, so that calling URL http://arduino.local/arduino/digital/13 will report the current state of pin 13, while http://arduino.local/arduino/digital/13/1 will turn it on. We’ve actually made such a sketch as part of the examples: you’ll find it in the upcoming Arduino IDE release.

Here’s one of the examples that come with the library, the TemperatureWebPanel. It gets the current reading of a temperature sensor and displays it on a web page in your browser. It demonstrates a number of Bridge’s more advanced features like Process (for executing Linux processes), the YunServer and YunClient (for server and client communication), and the ability to upload additional files for serving up to connected clients.

In “setup()”, start the Bridge with “Bridge.begin()”. This ensures the Python part of the Bridge on the GNU/Linux processor is up & running. Next, toggle pins to use a TMP36 temperature sensor so that it can be plugged directly into the board’s headers. YunServer is part of Bridge that enables Linino to pass URLS formatted with “/arduino/” to the 32U4. To listen to commands from connected clients, you need to start the server by calling “server.begin()”. “server.listenOnLocalhost()” forwards all local server communication to port 5555. Process allows you to call Linux commands through your sketch. Here, you’ll execute the shell command “date” by calling “startTime.runShellCommand(“date”)”, which will report the date and time the sketch started running.

In “loop()”, the sketch listens for incoming client connections (requests from the Internet) by creating an instance of YunClient. You can read incoming commands with “client.readString()”. If a connected client sends the command “temperature”, the Bridge executes the “date” command on GNU/Linux to report the time of the reading, then reads the sensor on A1 and calculates the temperature. The date and temperature information is combined into a HTML formatted string and sent back as a response.

Sketches for the Yún can now contain all the files needed to create a web application that can talk to your sketches through a browser. In the TemperatureWebPanel directory on your computer, there is another folder named “www”. This folder contains a basic webpage and a copy of zepto.js, a minimized version of jQuery.

You need a micro SD card plugged in to your Yún with a folder named “arduino” at the root. Inside the “arduino” folder, there must be a directory called “www”. You need to upload the sketch via WiFi to transfer the contents of the local “www” folder. You cannot transfer files via USB. Once uploaded, you can open your favorite browser and go to http://arduino.local/sd/TemperatureWebPanel. There you’ll see the browser reporting back the sensor readings, with the time information and total number of requests.

The browser calls the url http://arduino.local/arduino/temperature in the background. URLs that start with “/arduino/” are special: everything from the “t” of “temperature” is sent to the sketch via Bridge. You can send any command you like, as long as your sketch understands them.

The next post about the Yún will focus on Temboo and how the Arduino Yún can easily grab all sorts of data and interact with tons of web-based services. Stay tuned!


How to make a pneumatic flight simulator

arduino, duemilanove, flight, pneumatic, simulator, tutorials, video Commenti disabilitati su How to make a pneumatic flight simulator 


Arduino-Pneumatic Flight Simulator

Dominick Lee is a programmer, inventor who created the  “LifeBeam Flight Simulator“, a pneumatic-powered dual-axis motion flight simulator  using Arduino Duemilanove. After a few months of diligent work and the help of some generous collaborators he was able to mix physics, robotic and aviation into a motion platform that can make full rotations tilting at about 40 degrees.

The LifeBeam Flight Simulator is a full setup of equipment that runs simultaneously and collaboratively. The data is first sent from the Graphics or “Gaming PC”  through a custom software program that acquires game data. The game data is scaled and converted into specific coordinates for the roll and pitch (X and Y) axis. The program sends out the final signal which is received by an Arduino (Duemilanove). The Arduino has a complex program on it that combines the serial commands and parses certain values to calculate a voltage which is then converted into PWM and sent to a low-pass filter which smoothes the PWM into analog voltage. The analog voltage is connected to a Pneumatic Valve Amplifier which controls the pneumatic cylinders to make the platform move accordingly.

After watching the video below you can read the whole documentation on Instructables and make one yourself!




DIY Bicycle Computer with Arduino – auch auf Deutsch

arduino, bike, counter, german, tutorial, tutorials, video Commenti disabilitati su DIY Bicycle Computer with Arduino – auch auf Deutsch 

DIY bike computer videotutorial

This month we are going to work outdoor because Max is going to show us how  to make a DIY computer to customize our bicycle, collecting data of distances and speed. Watch the video tutorial in german language below and take a look at the schematics and the code.  Looking forward to your hacks!


Diesen Monat geht es ab nach Draußen, denn Max zeigt uns wie man einen DIY Computer für ein Fahrrad bauen kann, welcher Daten über die Strecke und die Geschwindigkeit mit einem Arduino UNO ermittelt. Seht euch das deutschsprachige Video an und schaut euch den Schaltplan, die Komponenten und den Code an. Wir freuen uns auf eure Hacks!


Arduino Starter Kit video tutorials now released in Creative Commons

arduino, rs components, StarterKit, tutorial, tutorials, video, YouTube Commenti disabilitati su Arduino Starter Kit video tutorials now released in Creative Commons 


Last year to celebrate the launch of the new Arduino Starter KitRS Components in collaboration with Arduino,  produced  10 video tutorials featuring Massimo Banzi showing how to create cool projects with the redesigned release of the Kit and all its components.


Today RS Components announced on their Twitter and Google+ that the Arduino video tutorials are now marked with a Creative Commons license, that means that you can remix and reuse them as you like.

We created a Playlist on Arduino official Channel and soon we’ll add also German and French subtitles.



Jugando a SuperTux Cart con Arduino Esplora – Video tutorial

arduino, Esplora, Spanish, supertux, tutorial, tutorials, video, videogame Commenti disabilitati su Jugando a SuperTux Cart con Arduino Esplora – Video tutorial 

videotutorial supertux spanish

(en español a continuación)

Last April we launched the first of a series of video tutorial in german language with the aim of exploring cool projects with Arduino boards. Now we are happy to announce we are starting a collaboration with Pablo Murillo from Arduteka to create video tutorials in spanish language to be published  on the official Arduino channel on Youtube.

Starting today you can enjoy a step-by-step tutorial to understand how use your Arduino Esplora  as a customized computer gamepad to play any of your videogames.

The code is configured to be suitable for SuperTuxKart, our favorite  open-source racing game!


El pasado abril se lanzó el primero de una serie de video tutoriales en Alemán, con el objetivo de explorar nuevos proyectos interesantes a desarrollar con Arduino. Hoy estamos felices de anunciar que empezamos una colaboración con Pablo Murillo de Arduteka para crear video tutoriales en Español, que se publicará en el canal oficial de Arduino en Youtube.

A partir de hoy se puede disfrutar de un tutorial paso a paso para entender cómo usar Arduino Esplora como un gamepad personalizado para jugar en cualquiera de sus videojuegos.

El código está configurado para ser utilizado con SuperTuxKart, nuestro juego de carreras de código abierto favorito!


Pimp up your camera with Arduino timelapse video tutorial – auch auf Deutsch

arduino, Image(s), tutorial, tutorials, video Commenti disabilitati su Pimp up your camera with Arduino timelapse video tutorial – auch auf Deutsch 

timelapse videotutorial


Last month we launched the first of a series of tutorials hosted on our Youtube Channel and created by Max of MaxTechTV in german language.

Today we are publishing the second video called “Pimp-up your camera with an Arduino timelapse“. The video explains how to connect an Arduino UNO with you camera and shoot pictures, for example, every 1, 5, 10 seconds to create wonderful videos of slow processes that would normally appear subtle to the human eye.

Enjoy the tutorial below and share with us the results of your experimentations!


Letzten Monat haben wir das erste einer Reihe von Video-Tutorials auf unserem YouTube Kanal veröffentlicht. Erstellt werden die Tutorials von Max von MaxTechTV für all diejenigen von euch, die Deutsch sprechen.

Heute veröffentlichen wir das zweite Video mit dem Titel “Erstelle tolle Zeitrafferaufnahmen mit deiner Kamera & Arduino”. Das Video erklärt wie man einen Arduino UNO mit einer Kamera verbindet um mit dieser in bestimmten Abständen, wie z.B. 1, 5 oder 10 Sekunden, ein Bild aufzunehmen. So kann man beeindruckende Videos von langsamen Prozessen erstellen, die dem menschlichen Augen sonst verborgen bleiben würden.Viel Spaß mit dem Tutorial und teilt mit uns die Ergebnisse eurer Experimente!




A cheap WiFi interface for Arduino

ethernet, router, shield, tutorials, wifi, wireless Commenti disabilitati su A cheap WiFi interface for Arduino 

In this tutorial, Luca shows how to add WiFi connectivity to your Arduino boards without using a WiFi shield. Instead, he has combined a standard Ethernet shield with a commercial (and quite cheap) WiFi router:

I found the TL-WR702N nano router by TP-LINK that, with a cost of about 20€ on eBay, can work also as a wireless client: in this mode the router acts like a “bridge” between the device connected to its ethernet port and a Wi-fi network.

After a simple setup, where Luca configured the router as a WiFi client, the Arduino board has become accessible from the wireless network. Enjoy! :)

[Via: Luca's blog]


Sensing Humidity With The SHT15 + Arduino

arduino, Humidity, SHT15, tutorials Commenti disabilitati su Sensing Humidity With The SHT15 + Arduino 

The SHT15 is a digital humidity sensor that outputs a fully calibrated humidity reading. And… because what we are measuring is actually relative humidity, and relative humidity being relative to temperature, the SHT15 has a builtin digital thermometer. This makes things much easier to work with than sensors without a thermometer onboard. You can pick one up from sparkFun here.

Hooking it up

The SHT15 uses a two-wire connection for communication that is similar to, but not, I2C. So we wont be able to use the Arduino’s dedicated lines for this. The down side is it is a bit slower to get readings from, the plus side is that you can connect it to any 2 digital pins you want. We are using pins 2 and 3 on our arduino.

BEFORE YOU SOLDER IT UP… Note that this board can not be washed! So if you are using flux, or solder that you normally clean up, don’t (They actually recommend to use “no-clean” solder just so you don’t have to worry about it). And be extremely careful not to get it wet at all.

AFTER YOU SOLDER IT UP… To get a clean reading, the sensor needs to be stored at >75% humidity for at least 12 hours to allow the polymer to re-hydrate (just what the doc says). If you don’t, your SHT15 may read an offset that slowly disappears if exposed to ambient conditions. Alternatively the re-hydration process may be performed at ambient conditions (>40% Humidity) for 5 + days.

Im not exactly sure how you do that… But someone noted that they put it in a ziplock with a wet towel (not touching) for 12H.


The code for this is a bit wacky (as with most digital sensors), but it is split up pretty nicely, and is as easy to read as it can be.

Note that the readings are a bit slow to return a value (100+ ms).

//Based of the wiring code at

int SHT_clockPin = 3;  // pin used for clock
int SHT_dataPin  = 2;  // pin used for data

void setup(){
  Serial.begin(9600); // open serial at 9600 bps

void loop(){
  //these can take a bit to get the values (100ms or so)
  float temperature = getTemperature();
  float humidity = getHumidity();

  Serial.print(" | ");


float getTemperature(){
  //Return Temperature in Celsius
  SHT_sendCommand(B00000011, SHT_dataPin, SHT_clockPin);

  int val = SHT_getData(SHT_dataPin, SHT_clockPin);
  SHT_skipCrc(SHT_dataPin, SHT_clockPin);
  return (float)val * 0.01 - 40; //convert to celsius

float getHumidity(){
  //Return  Relative Humidity
  SHT_sendCommand(B00000101, SHT_dataPin, SHT_clockPin);
  int val = SHT_getData(SHT_dataPin, SHT_clockPin);
  SHT_skipCrc(SHT_dataPin, SHT_clockPin);
  return -4.0 + 0.0405 * val + -0.0000028 * val * val; 

void SHT_sendCommand(int command, int dataPin, int clockPin){
  // send a command to the SHTx sensor
  // transmission start
  pinMode(dataPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  digitalWrite(dataPin, HIGH);
  digitalWrite(clockPin, HIGH);
  digitalWrite(dataPin, LOW);
  digitalWrite(clockPin, LOW);
  digitalWrite(clockPin, HIGH);
  digitalWrite(dataPin, HIGH);
  digitalWrite(clockPin, LOW);

  // shift out the command (the 3 MSB are address and must be 000, the last 5 bits are the command)
  shiftOut(dataPin, clockPin, MSBFIRST, command);

  // verify we get the right ACK
  digitalWrite(clockPin, HIGH);
  pinMode(dataPin, INPUT);

  if (digitalRead(dataPin)) Serial.println("ACK error 0");
  digitalWrite(clockPin, LOW);
  if (!digitalRead(dataPin)) Serial.println("ACK error 1");

void SHT_waitForResult(int dataPin){
  // wait for the SHTx answer
  pinMode(dataPin, INPUT);

  int ack; //acknowledgement

  //need to wait up to 2 seconds for the value
  for (int i = 0; i < 1000; ++i){
    ack = digitalRead(dataPin);
    if (ack == LOW) break;

  if (ack == HIGH) Serial.println("ACK error 2");

int SHT_getData(int dataPin, int clockPin){
  // get data from the SHTx sensor

  // get the MSB (most significant bits)
  pinMode(dataPin, INPUT);
  pinMode(clockPin, OUTPUT);
  byte MSB = shiftIn(dataPin, clockPin, MSBFIRST);

  // send the required ACK
  pinMode(dataPin, OUTPUT);
  digitalWrite(dataPin, HIGH);
  digitalWrite(dataPin, LOW);
  digitalWrite(clockPin, HIGH);
  digitalWrite(clockPin, LOW);

  // get the LSB (less significant bits)
  pinMode(dataPin, INPUT);
  byte LSB = shiftIn(dataPin, clockPin, MSBFIRST);
  return ((MSB << 8) | LSB); //combine bits

void SHT_skipCrc(int dataPin, int clockPin){
  // skip CRC data from the SHTx sensor
  pinMode(dataPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  digitalWrite(dataPin, HIGH);
  digitalWrite(clockPin, HIGH);
  digitalWrite(clockPin, LOW);
Unless otherwise stated, this code is released under the MIT License – Please use, change and share it.

The Big Easy Stepper Motor Driver + Arduino

arduino, motor, Step Motor, Stepper, Stepper Motor, tutorials Commenti disabilitati su The Big Easy Stepper Motor Driver + Arduino 

Stepper (or step) motors are really cool. They are perfect for automation or any time you need a motor to turn to a specific point, at a specific speed, in a specific direction. And, unlike typical motors, steppers are able to do all of this, and hold their position when they are not moving – The trade off is that they cant move as fast, and you have to power them at full power all the time, but you get total control in return.

Steppers have a minimum amount they can move known as a step. You can feel these steps if you slowly turn your stepper by hand. The most common steppers have 200 steps per revolution, so all movement is in 1.8º increments (360º / 200). Controlling them can get tricky at first, so today we are doing an article on using the Big EasyDriver Stepper Motor Driver. The big easyDriver is the big brother of the easy driver we wrote about last year. It is able to take a lot more abuse and power, so it isn’t as easy to destroy as the easy driver, can power much larger motors, and it also gives you a little more control by letting you change the microstepping setting.

Motor Voltage / Current

A lot of people ask about what voltage they should use to power their motor. Well, when using a stepper driver, you are powering the driver, not the motor. The driver will take over powering the motor for you.

It is best to power the driver with the highest voltage you can ( up to 35V max for this driver ). This will allow the motor to spin faster than if powered at a lower voltage. Exactly why this is is pretty complex, but if you want to know more about it, you should really read this: Gecko Drive – Step Motor Basics

On the bigEasy driver is a mini potentiometer to control the current to the motor. This varies between 0ma and 2A (2000ma). You want to set it to whatever your motor is rated to. Too high, and you could burn the motor up, too low, you wont get all the power out of your motor. Note: The arrow indicators on the current adjustment potentiometer are backwards. Keep this in mind when adjusting the current limits. If you are running a higher power motor, you will probably want to put a heat sink on the driver as well.

Hooking it up

Even though there are some 30 pins on the Big Easy Driver, we only need a few to get this up and running. In fact, a good deal of the pins are actually just duplicates that are spaced out differently.

The barebones setup:

Power the driver with 8-35v – If using a wall adapter, make sure the adapter has at least enough current for the motor. A higher current/amperage rating is better, and just means it wont burn out. (The Big Easy Driver can supply up to 2 amps)
Connect the 3 control wires from the “gnd”, “dir”, and “step” of the Big Easy Driver to the Arduino as shown.
Connect the stepper motor to the driver – For me the red/green were one pair, and the blue/yellow was another. If this does not work for you, see the section below on finding your motors coil pairs.


For the arduino code for the driver, im going to be using AccelStepper Library. This is an amazing library that I use for all my stepper needs now. It is even does acceleration and deceleration, supports multiple drivers at once, and most importantly it is non blocking. Meaning, you can be moving your motor as you are reading from a sensor, or turning on lights etc.

The library even keeps track of the position of the motor. So if you tell it to go to 10,000 – It knows it is at 9,00 already, so it moves an additional 1000 steps. Then you can tell it to go home, and it will go back 10,000 steps to 0.

I highly recommend you download the full library from the author. The version I have here is barebones with none of the examples. It is just here because I believe if you post code, you should post everything you need to make it work

To make this code work, before you load the code, or even open the Arduino program, we need to place the “AccelStepper” folder into your Arduino Library. If you don’t know where that is by default, Look to the right.
If you click the download button to the right of “Arduino” you can download the whole thing as a zip, so you dont need to copy all the files.

Default Library Folder Location

On your Mac:: In (home directory)/Documents/Arduino/libraries
On your PC:: My Documents -> Arduino -> libraries
On your Linux box:: (home directory)/sketchbook/libraries

Additional Information

Finding Your Motors Coil Pairs

This driver only needs 4 wires from your stepper. If you have a 4 wire stepper, awesome! If you have a 6 wire stepper, it will be slightly trickier. But no matter what, we need to find the 2 main coils inside of the motor. And if you get it wrong, the motor will just twitch or not move, but you wont break it.

4 wire motor

Using an ohmMeter, pick one wire at random, and test it with the others until you find a pair that shows resistance of a few ohms (1 – 200ohms most often). Those 2 are your “pair A”. Make sure the other 2 wires have the same resistance on them, (if not, it may be broken) and that is your “pair B”. With the two pairs of wires, there isnt a backwards, so just plug wires from “pair A” into the “A” on the driver, and “pair B” into “B”.

6 wire motor

Checking the documents on the motor is the easiest, but if you dont have it, read on.

6 wire motors have two coils in them just like 4 wire motors. But 6 wire motors also have extra wires that connects to the middle of each coil (centers). So each coil actually has 3 wires, a center and two ends. We don’t use coil center wires, we just need the 4 coil ends (2 from each coil).

Basically, We need to find ends of the two coils. The ends of the coils will have twice the resistance as the center to an end. So we need two pairs of wire that have the highest resistance in the group.

The easiest way to find out the right 4 wires is to look at the documentation for the motor, but if you dont have that, you can with some testing, find the right ones.

To find the correct 2 wires, we need to locate the 3 wires from each coil. Start by just picking one at random, and using an ohmMeter, test the resistance with the others until you find the 2 connected to that wire. (3 of them will show no connection because they are part of the other coil). Now, these 3 are for coil “A”. Now, take these 3 wires and test the resistance between any 2 of them until find the 2 that have the highest resistance. These are the two ends of that coil “A”. Do the same for the other 3 wires to locate the ends of coil “B”.

With the two pairs of wires, there isnt a backwards. So just plug wires from coil A into the A on the driver, and the two from coil B into b.

8 wire motor

There is no way to do this without looking at the documentation.


Most stepper drivers offer something called microstepping, and the Big Easy Driver is no exception. As I mentioned before, steppers have that minimum movement called a step. Microstepping breaks down that step into smaller micro steps. Microstepping allows for smoother, quieter, more accurate control, at slower speeds.

When using microstepping, a step motor will require more “step pluses” to move the motor. For instance if you are using 16 microsteps (the default on the Big Easy Driver) per step, a 200 step motor would require 3200 “step pluses” to make a full revolution. Just take note when you wonder why telling it to step 200 steps barely rotates the motor.

Microstepping will reduce the maximum speed / torque of the motor (about 30% less), so it is a trade of speed vs smooth. Because of this, many high end drivers switch to full stepping (no microstepping) at higher speeds, and technically, you could do that with the big easyDriver, but it’s too complex for me to figure out, so I wont be covering that.

Adjusting the microstepping

The Big Easy Driver defaults to 16 step microstepping mode. If you want to reduce that, you can do so by pulling the MS1, MS2, and MS3 pins HIGH (connecting them to 5V) or LOW (connecting them to GND). Check out the chart on the side to see how make the adjustments.


Sensing Humidity With The HIH-4030 + Arduino

arduino, Humidity, Sensor, tutorials Commenti disabilitati su Sensing Humidity With The HIH-4030 + Arduino 

Humidity is weird. Even though we experience it all the time, it’s not something we can normally guess with any accuracy. This is probably because when we talk about humidity, we are talking about relative humidity. Relative humidity is relative to temperature, so a change in temperature alone is enough to change the relative humidity. This makes guessing the humidity extremely hard.

Well luckily measuring relative humidity is pretty simple with the HIH-4030. The HIH-4030 is a low-power, analog output sensor.

Hooking It Up

Hooking up the HIH-4030 to your arduino is super simple, just power it with 5V / Ground, and connect the out to an analog pin on the arduino. You may be able to run it with 3.3v, I haven’t tried it. But if you do, you need to change the “supplyVolt” value in the code from 5.0 to 3.3.


Note that because determining relative humidity requires knowing an accurate temperature, you are going to want to use this in conjunction with a thermometer. To simplify things for you, the code just has a hard coded temperature that we pass to a function to get the humidity. You will want to replace that value with the value from your thermometer.

Also note that the sensor is sensitive to light, so for best performance, shield it from bright light.

Suggested Thermometers (with article):

//From the bildr article

int HIH4030_Pin = A0; //analog pin 0

void setup(){

void loop(){

  //To properly caculate relative humidity, we need the temperature.
  float temperature = 25; //replace with a thermometer reading if you have it
  float relativeHumidity  = getHumidity(temperature);


  delay(100); //just here to slow it down so you can read it

float getHumidity(float degreesCelsius){
  //caculate relative humidity
  float supplyVolt = 5.0;

  // read the value from the sensor:
  int HIH4030_Value = analogRead(HIH4030_Pin);
  float voltage = HIH4030_Value/1023. * supplyVolt; // convert to voltage value

  // convert the voltage to a relative humidity
  // - the equation is derived from the HIH-4030/31 datasheet
  // - it is not calibrated to your individual sensor
  //  Table 2 of the sheet shows the may deviate from this line
  float sensorRH = 161.0 * voltage / supplyVolt - 25.8;
  float trueRH = sensorRH / (1.0546 - 0.0026 * degreesCelsius); //temperature adjustment 

  return trueRH;
Unless otherwise stated, this code is released under the MIT License – Please use, change and share it.

  • Newsletter

    Sign up for the PlanetArduino Newsletter, which delivers the most popular articles via e-mail to your inbox every week. Just fill in the information below and submit.

  • Like Us on Facebook