Search in The Electromania's Blog

Saturday 30 January 2016

Arduino - Fan RPM measurement using internal hall effect sensor (Hardware Interrupts and LCD)

I needed to measure rotational speed in RPM for one modified computer 3 pin fan with inbuilt Hall effect sensor.

This project gives quick intro to-

1) Using Interrupts of arduino boards (here arduino Due)
2) Interfacing Hall effect sensor of fan
3) Interfacing and displaying real time information on LCD display (here 16 x 2)
4) Implement basic logic in programming

There are many ways of measuring speed, using IR sensor, Photo diode, HES etc. 
The computer fans have internal hall effect sensor (HES) that can be used to pick up the ticks per revolution of rotor. The measurement algorithm can be also varied depending upon the required accuracy and response time. I am measuring fan speed approx in 1 sec interval using basic microcontroller interrupt driven algorithm, giving acurracy of few 10s or RPM, something I needed for my other project.

Hall effect sensor working principle (Source of image)

Hall effect sensor (HES) works on the principle of interaction of magnetic field with electrons flowing in the conductor and subsequent generation of secondary voltage known as Hall voltage. Read more here.

In three pin fans with internal hall effect sensor, generally yellow colored wire is output of HES. Most of the time it requires external pull-up resistor of few kohm values depending on supply voltage. Instead of external resistor, internal pull-up resistor of our arduino board pins can be used. digitalWrite(pinno, HIGH); in setup() function enables this internal pull-up resistor. With this HES output wire can be directly connected to interrupt pin (here pin 12) without using an external 10kohm pull-up resistor. I have used external pull-up resistor.

With every rotation of rotor, depending on type of fan and number of magnets attached to rotor, with every rotation of rotor, we get 1, 2 or 4 ticks as output signal from HES. We will pick up these ticks by interrupting our arduino program using "hardware interrupts". Interrupts help in letting our arduino do its regular job until some signal is received at interrupt pins. This lets us use arduino perform other tasks while waiting for signal at interrupt pins. 

I have used a RGB LED to provide quick idea about speed range, the LCD displays actual speed in RPM, values updated every second.

Code/Sketch is shown at the end of video or on github page here

Bill of materials:-

1) Arduino due board from Ali-express
2) Resistors - 10k and 470 ohm  (you can use any other resistors in similar ranges)
3) PC fan or any other motor with inbuilt hall effect sensor
4) LCD display with I2C interface  ( you can use parallel LCDs too, but pinout and code needs to be slightly modified)
About installing I2CLibrary and getting I2C address, check my video - 
5) Power supply as per used fan/motor  (here it is 12V DC)
6) 3 LEDs or single RGB LED, to use as optical indicator of fan RPM range

In next project i will interface OLED display instead of LCD and try to modify code for faster update and higher accuracy of RPM....

Thanks to -  for starting code

Wednesday 20 January 2016

Clock and calendar using Arduino due internal RTC and I2C LCD display

I wanted to make a clock and calendar since long time. Ordered RTC chip is taking more than two months to arrive, so finally decided to find way out and found beautiful RTC library by 
and I2C LCD library by .
Although apparently simple project, it took long time for me to make I2C LCD display work (tried a dozen LCD libraries), get data from inbuilt RTC of Arduino due and do some animated scrolling text on LCD.

This quick project introduces us to -

1) Arduino due internal real time clock RTC to be used as date and time display. No need of external RTC chip/board

2) Running I2C LCD display on arduino due using Arduino IDE version 1.6.6

3) Displaying fixed text and scrolling text

4) Fixing issue of only one character being displayed on LCD displays, especially using higher version arduino IDE.

Although generally LCD displays are easy to connect and get working, it took long time for me to make it work on new Arduino IDE 1.6.6 and Arduino due. Initially I was getting only blinking white dark screen, then only one character and then text spread randomly so on... after lot of digging into google, i came up with this scheme... thanks to those who have done bits and pieces of work that helped me to do this herculean but simple project :).

Pin connections are as given below. Please note that LCD display needs 5V supply and not 3.3V.
I hooked up LCD directly from Arduino due 5V power supply and connected SCL and SDA pics of I2C LCD driver directly to pin 21 and 20 respectively. I didnt use any 5V to 3.3V step down conversion, it worked without burning my Arduino Due :).

Note - If your LCD display shows only one or first character of complete string, do not panic, just go in libraries folder of your Arduino installation directory, open the LiquidCrystal_I2C.cpp file and change the return value from 0 to 1, 
#define printIIC(args) Wire.write(args)
inline size_t LiquidCrystal_I2C::write(uint8_t value) {
send(value, Rs);
return 1;   this should be 1 and not 0

* Final working Sketch/code is given at the bottom of this page or is available on my - Github page with explanation of important commands given as comments.

I am not very active on blog these days, for comments and suggestions please comment on my youtube video here .

Have fun... :)

* Links to Libraries etc-

-- RTC library

-- Library for I2C LCD display

-- Sketch for Arduino I2C address scanner 

-- I2C LCD driver board from ebay 

-- 1602 LCD display is part of Arduino uno starter kit from

Catch Electromania on-
Blog -






Contact Electromania


Email *

Message *