Introduction

The Sun.  Our closest star resides about 150 million Km (93 million miles) from Earth and without it life itself would simply not be possible here. The Sun provides us with both heat and light, essential for our survival.

But the Sun has a bit of an evil side as well. In addition to visible light and heat it also emits radiation across a wide spectrum, some of it in the form of lethal X-rays and gamma rays.  Fortunately our planet has the Van Allen belts surrounding it, acting like a Star Trek type “shield” that protects us from this deadly radiation.

The Sun also emits light across a broad spectrum. At the low end is the Infrared light (which is perceived as heat), followed by the visible light that we are all familiar with.  And then there is Ultraviolet light at the high end.

Ultraviolet or UV light is filtered to a large degree by the Earth’s Ozone layer, a protective layer of gas in the upper atmosphere that absorbs UV radiation.  But the ozone layer is not a perfect filter and as a consequence some of the UV makes it through.

Humans can tolerate low levels of UV exposure just fine, in fact many of us seek out these UV rays as they are responsible for temporarily darkening the pigment of our skin – in other words a suntan!  But too much exposure to UV light can cause serious health problems ranging from third degree burns to skin cancer.

Whether you’re an avid outdoors person, a diehard sunbather or a parent who is concerned for their child’s welfare knowing the current UV light level can be very important.

Arduino UV Index Meter

Today in the workshop we will experiment with UV light, both producing it and detecting it.  We will then build a UV Index meter that is capable of accurately measuring the current UV level.

So grab your sunscreen and follow along!

Ultraviolet (UV) Light

In 1801 German physicist Johann Wilhelm Ritter observed paper soaked in silver chloride would turn dark when exposed to light rays above the violet end of the visible light spectrum.  He named these rays “oxidizing rays”, as opposed to the newly discovered “heat rays” which were below red at the bottom end of the visible light spectrum.

Now we refer to these areas of the spectrum by different names. The former “heat rays” are now known as “infrared” radiation, light radiation with a lower frequency than red light.  And the “oxidizing rays” are now referred to as “ultraviolet” radiation, light radiation with a higher frequency than violet.

The following chart illustrates the electromagnetic spectrum. Note that ultraviolet radiation is just above visible light in frequency or just below it in wavelength (wavelength is the inverse of frequency).

Electromagnetic Spectrum Chart

As UV light is above violet it is not visible to the human eye, although some birds can see part of the UV spectrum due to an additional color receptor in their eyes.

The UV Spectrum

The ultraviolet section of the electromagnetic spectrum extends from 400 nm to 100 nm, just below the X-ray section of the spectrum.  It is actually divided into three sections:

  • UVA – This is the range from 400 nm to 315 nm. The so-called “black lights” that are used for eerie lighting effects fall into this range. UVA is not absorbed by the ozone layer.
  • UVB – This is the range from 315 nm to 280 nm. The lights used in tanning booths usually are in this range. Most of the Sun’s UVB energy is absorbed by the ozone layer but some gets through.
  • UVC – This is the range from 280 nm to 100 nm. UV light in this range is used in sterilization procedures as its high energy kills bacteria. It is completely absorbed by the ozone layer and upper atmosphere.

UV Light Spectrum

Uses for UV Light

There are many practical applications for ultraviolet light, here are a few of them:

  • Germicidal UV Lamps – These are used for disinfection and sterilization in laboratories and in the food industry.  They are also used in water treatment plants.
  • Counterfeit Money Detectors – Many currencies use hidden dots and watermarks that can only be seen under UV light. Some credit cards, drivers licenses and passports also have secret UV images and the process is also used with artwork.
  • Pet Urine Detector – It may seem a bit humorous but urine is fluorescent and glows under ultraviolet light. These devices are handy if you suspect Fido has been a bad boy on the carpet!
  • Air Purification – A complex process that uses UVC light to kill bacteria in the air.
  • Bug Traps – UVA lights are used to attract insects into the trap where they are electrocuted by a wire grid. Entomologists also use UV traps to trap (but not kill) insects they wish to study.
  • Herpetology – Herpetology is the study of  amphibians and reptiles, in case you didn’t know that (I didn’t!).  Reptiles need UV light to produce vitamin D, which is why you see lizards basking in the Sun. In captivity this UV light is produced artificially.
  • Forensics – UV light is useful for identifying body fluids at a crime scene. Hopefully you will never need to do that!
  • Astronomy – As most UV light is blocked by the atmosphere space-based telescopes like the Hubble are used to view the universe in ultraviolet light.
  • Skin Therapy – Low-level exposure to UVA light is sometimes used to treat skin conditions like psoriasis.
  • Grow Lights – UV lights can be used to grow plants indoors, mimicking the energy they would normally receive from the Sun.
  • Curing Adhesives – Several adhesives use UV light to cure them and form a bond.  Some 3D printers use this method to cure the resin used in the printing process.

As you can see the uses of ultraviolet light are wide and varied.

Fluorescence

Fluorescence is the emission of light by a substance that has absorbed light or other electromagnetic radiation. Many items exhibit this property.

The most common and well known use of fluorescence is, of course, the fluorescent light.  Although these are gradually being replaced by more efficient LED lights they are still the most common type of lighting employed in office towers and public buildings.  They are also used in homes as CFL or Compact Fluorescent Lights, those twisty bulbs that became common about a decade ago.

A fluorescent lamp consists of a glass tube filled with mercury vapor. Electricity is applied to the vapor and causes it to ionize, resulting in the emission of photons of UV light. The tube has a phosphor coating on the inside, that phosphor is fluorescent and thus emits visible light when excited by the UV photons.

Interestingly some white LEDs also make use of this property. A blue light is emitted and strikes phosphors deposited on the chip itself. The combination of the blue light that shines through the phosphor and the green to red fluorescence from the phosphors produces white light.

Many common household items will fluoresce under UV light.  In the video associated with this article I show a few of them:

  • Tonic Water – This refreshing drink fluoresces blue due to the presence of quinine.
  • Highlighter Ink – Most brands contain pyranine which will fluoresce.

You can have a lot of fun going around your home with a UV lamp to see which items fluoresce!

Effects of UV Light on Humans

Ultraviolet light can affect humans in both a positive and negative way.

On a positive note sunshine is good for you, at least in moderation. UVB light causes the body to produce vitamin D which is essential for life. However you don’t need a lot of exposure to get the required vitamin D, according to the World Health Organization just 5 to 15 minutes a day twice a week in the summer months is sufficient.

Another byproduct of UVB exposure is serotonin, a chemical that promotes happiness and a sense of well being.

But once you exceed the small amount of exposure recommended by the WHO ultraviolet light can be dangerous.

First your eyes.  Excessive UV exposure can have very bad effects on your eye’s dioptric system and retina, which is why it’s a really bad idea to stare at the sun even during a solar eclipse. It also explains why sunglasses are a good idea, especially in winter in areas covered with highly reflective snow.

Next your skin. This is the most well known effect of UV light as exposure to UVB (and to some degree UVA) will give you a suntan or a sunburn.  The amount of skin discoloration will vary depending upon your genetic background, Caucasians are most sensitive to UV exposure and need to be careful when out in the Sun.

A more deadly effect of UV light is skin cancer.  While most research into this has focused on UVB light you can also be affected by exposure to UVA.  This is why sunscreen is a necessity, and why monitoring the UV level can be critical.

UV radiation damages collagen fibers and accelerates the aging of the skin, as well as depleting it of vitamin A.

So as you can see there is a fine line between not enough UV exposure and too much. This is why a form of UV measurement that the general public can understand is critical.

Which brings us to the UV Index system.

UV Index

The UV Index scale was developed by Canadian scientists in 1992, then adopted and standardized by the WHO in 1994.  

The UV Index is a linear scale, in other words a UV Index of 6 is twice the amount of ultraviolet light as a UV Index of 3.

UV Index Chart

In most areas of the world the UV Index ranges from 0 to 10, but it can get a lot higher than that.  Locations in the tropics often have UV levels exceeding 12 and high altitudes like mountaintops routinely register a UV Index of 20.

On December 29, 2003, a world-record UV index of 43.3 was detected at the mouth of Bolivia’s Licancabur volcano.  This is actually more like the UV Index on Mars which, despite being twice as far from the Sun as the Earth, has no ozone layer and is therefore subject to constant UV bombardment.

In the Artic and Antartic holes in the ozone layer form regularly due to reactions with polar stratospheric clouds, This has caused high UV levels in places like Australia where it is extremely problematic as Australia (and New Zealand) have populations whose ancestors came primarily from England and who thus did not have the right skin type to fend off UV rays.  People indigenous to these areas have evolved skin types that help protect them from UV exposure.

So now that we have examined what UV light is, what is is used for and what its effects on humans it’s time to get started with our experiments. Let’s begin by creating some ultraviolet light.

UV LEDs

Ultraviolet LEDs are, as one would suspect, LEDs that emit ultraviolet light.  Actually quite a few of them also emit visible light as their output extends from the violet to ultraviolet range of the spectrum.

UV LEDs are available in a wide range of spectral wavelengths ranging from 265 nm to 400 nm. This allows you to purchase UV LED’s to create UVA, UVB or UVC light and makes it possible for LEDs to be used in designs that would traditionally require more power-hungry traditional solutions.

Working with UV LEDs

As we have already discussed ultraviolet radiation can have harmful effects on humans and animals. Although most UV LEDs have a relatively low output they are still capable of doing damage to your eyes or even your skin with prolonged exposure.

The following safety precautions should be observed when working with UV LEDs or any UV energy source:

  • Avoid staring directly into the LED at close proximity.
  • Minimize your direct exposure to the UV light source.
  • Some UV LEDs work in the UVB or UVC band. These devices do not emit any visible light when working so some form of indication (i.e. monitoring current with a multimeter) is required to know that the LED is on.
  • If you construct items using UV LEDs be sure that they are handled safely and are kept out of the reach of children. All items containing UV LEDs should have warning stickers affixed to them.
  • Make others aware of your work with UV LEDs so they can observe appropriate safety precautions as well.

In the the video accompanying this article I use a few UVA LEDs that also emit some violet light. These are the safest variety to work with so unless you have a specific application that requires an exact wavelength they are ideal for experimenting purposes.  They are also the most common and inexpensive UV LEDs.

UV Light Warning Symbol

Otherwise working with a UV LED is identical to working with any LED. You’ll need to look at the spec sheets and calculate a value for a suitable current limiting resistor and of course hook it up in the correct polarity.  It’s as easy as that.

A few UV LEDs are handy to have around to use as a source of UV light for the sensor experiments we are about to do.  Unless of course you are working outside in the sunshine!

So now let’s move on to those sensor experiments.

SENS-43UV Analog Ultraviolet Light Sensor Module

The SENS-43UV Analog Ultraviolet Light Sensor Module is typical of UV sensor modules. It produces an analog output proportional to the amount of UV light it receives.  The device is sensitive in the 200-370 nm range which cover most of the UVA and UVB spectrum.

SENS 43UV UV Sensor Hookup

The output voltage can be measured and the UV index can then be derived from it, the manufacturer provides a reference sheet that you can use to determine the exact UV value.

There are many other analog UV sensors that work using the same principal. Some of them differ in terms of supply voltage so be sure to check that.

Measuring the SENS-43UV output with Arduino

Using the SENS-43UV with an Arduino is really like using any other analog device. You simply need to connect the sensors analog output to one of the Arduino’s analog inputs and measure the voltage.

One thing that you’ll quickly realize when using this sensor is that the output voltage is not very high. Unless you are measuring UV high in the Andes (or on the Licancabur volcano) you will likely never see an output of over 1 volt.

A standard Arduino (like an Uno) runs on 5 volts and uses its 5-volt power supply as a reference for the internal analog to digital converter (ADC) used on the analog input ports. It’s a 10-bit ADC so input voltage levels of 0 to 5 volts would be represented by readings of 0 to 1023.

If you are using an UV sensor that will never give out over a volt under normal conditions you are actually wasting a lot of accuracy with the above arrangement. A range of 0 to 1 volt will only use the digits between 0 and 204, leaving 820 unused digits.

To make better use of the Arduino’s internal ADC we will want to set it’s reference voltage lower, somewhere around 1 volt. That way the entire 1024 bits of resolution will be available for your sketch.

There are two ways to reset the reference voltage on an Arduino

  • The AREF pin on the Arduino is the Analog Reference pin. You can apply a reference voltage here to be used with the internal ADC.
  • You can do it in software.

The second method is a lot easier, the actual way of implementing it depends upon which model of Arduino you have.

The key to changing the analog reference voltage is to use the Arduino analogReference() command.

The command works as follows:

  • analogReference(DEFAULT) – the default analog reference of 5 volts (on 5V Arduino boards) or 3.3 volts (on 3.3V Arduino boards).
  • analogReference(INTERNAL) – a built-in reference, equal to 1.1 volts on the ATmega168 or ATmega328P and 2.56 volts on the ATmega8 (not available on the Arduino Mega).
  • analogReference(INTERNAL1V1) – a built-in 1.1V reference (Arduino Mega only).
  • analogReference(INTERNAL2V56) – a built-in 2.56V reference (Arduino Mega only).
  • analogReference(EXTERNAL) – use the voltage applied to the AREF pin.

Note that if you elect to apply a reference voltage to the Arduino it should not exceed its power supply voltage. In the case of our analog UV sensor that isn’t an issue.

You can use the SENS-43UV to construct a UV Index meter. The relationship between the analog output voltage and the UV Index is as follows:

  • UV1 – 227 mV
  • UV2 – 318 mV
  • UV3 – 408 mV
  • UV4 – 503 mV
  • UV5 – 606 mV
  • UV6 – 696 mV
  • UV7 – 795 mV
  • UV8 – 881 mV
  • UV9 – 976 mV
  • UV10 – 1170 mV (1.17 volts)

While this will make an excellent project I elected NOT to use it for my UV Index meter.  That’s because I found another sensor that makes things a lot easier and that doesn’t depend upon an accurate analog reference voltage.

Let’s look at that one now and build our UV Index meter.

SI1145 UV IR Visible Sensor

The SI1145 is a unique sensor with a unique method of operation. As its full description would imply it is not only measures UV light but is also capable of measuring IR light. Actually it also works with visible light as well.

The “unique method of operation” that the SI1145 uses is that it really doesn’t have an actual UV sensor! Instead it looks at the amount of visible and IR light it receives from the Sun and uses a formula to calculate the UV index, right down to two decimal points.

SI1145 UV IR Visible Sensor Pinouts

The SI1145 communicates with its host processor via the I2C bus, making it simple to interface the device with all sorts of microcontrollers and microcomputers.  It’s a natural for both an Arduino or a Raspberry Pi.

Let’s hook one up to an Arduino.

SI1145 with Arduino

As the SI1145 uses the I2c Bus it is very simple to hook it up to an Arduino.  The following diagram shows just how easy it is.

SI1145 Arduino Hookup

In order to work with the SI1145 you’ll need to install a new library into your Arduino IDE. The Adafruit SI1145 Library makes working with this sensor extremely easy. It can be installed directly from your Library Manager as follows:

  1. Open the Arduino IDE.
  2. Click the Sketch menu item.
  3. Expand the Include Library sub-menu.
  4. Select Manage Libraries from the sub-menu.
  5. The Library Manager will open.
  6. In the Library Manager filter your search by typing “SI1145” into the “filter your search” box.
  7. In the resulting libraries select the Adafruit SI1145 Library and click the More Info link.
  8. The Install button will appear on the right side of the library entry.
  9. Click the Install button to install the Adafruit SI1145 library.
  10. Close the Library Manager.
  11. The Adafruit SI1145 Library is now installed into your Arduino IDE.

Once the library is installed we can use one of the sample sketches included with it to test our SI1145 sensor.

  1. If you’ve closed the Arduino IDE open it again.
  2. Click the File menu item.
  3. Expand the Examples sub-menu.
  4. Scroll down to the Examples from Libraries section.
  5. Expand the Adafruit SI1145 Library sub-menu.
  6. Select si1145test from the sub-menu.
  7. The test sketch wil be loaded in to the Arduino IDE.

The sketch is fairly straightforward.

 

It starts by including the Arduino Wire Library. This is the built-in library for communicating on the I2C bus.  Of course the Adafruit SI1145 library is also included in the sketch.

An object called “uv” is created using the Adafruit SI1145 library.

In the Setup routine the serial monitor is initialized at 9600 baud. Make sure that the serial monitor on your Arduino IDE is also set to the same speed, if not then change either the code or the serial monitor speed setting to make them match.

A line is then printed to the serial monitor to indicate that the test is beginning.

The final section of the Setup routine initializes the SI1145 sensor.  If the sensor fails to initiate a message is displayed. If it’s successful then “OK “ is printed to the serial monitor and the Setup routine finishes.

In the Loop we first print a separator line to distinguish our readings better.

We then use the readVisible function of the SI1145 object to print the visible light level to the serial monitor.  The readIR function is used in a similar fashion to print the infrared light level.

The commented section that appears next is to allow the sensor rto be used as a proximity sensor. This requires the addition of an infrared LED. We will not be exploring this function so leave the code here commented.

Finally we use the readUV function to get the UV Index reading. In order to format the reading correctly it must be divided by 100. The resulting value is assigned to the UVIndex variable and is printed to the serial monitor.

After a one second delay the loop repeats itself.

Hook up the SI1145 to the Arduino, load the code and give it a test. You’ll need a source of UV light to see if it is working, I used some UV LEDs in the video accompanying this article. Other UV sources like black lights and grow lights will probably give off enough UV to see if the sensor is responding. But of course the best test is to use actual sunlight.

Now that we have seen how the SI1145 works let’s start putting together our Arduino UV Index Meter.

Arduino UV Index Meter

We’ve seen how we can get a UV reading using the SI1145 and an Arduino and display the results on the serial monitor. That’s a bit inconvenient for using the sensor outdoors so we will need a display, preferably one that can be seen easily in daylight.

For our Arduino UV Index Meter I have chosen to use an LCD display with an I2C connection.  This is a very economical method of adding a display and it is extremely simple to wire it up thanks to the I2C connection.  It’s pretty easy to see it, even under direct sunlight, and it draws very little current so that battery power is feasible for our design.

Here is how the UV Index Meter is hooked up, note how easy it is thanks to the I2C connection.

Arduino UV Meter Hookup

The code for running this is also pretty simple, a lot of it will look familiar after seeing the test sketch.  The main additions to the code are to drive the LCD display.

If you’d like more information about using LCD displays I’ve already done an article and video that covers the subject in depth. Check out Using LCD Displays with Arduino and the associated video.  The article also covers the installation of the NewLiquidCrystal Library for I2C which is required to use the LCD display.

Here is the sketch for our UV Index Meter:

 

The sketch begins by including the required libraries. After that the connections to the LCD display on the I2C adapter are defined.

The variable i2c_add is the I2C address of the LCD display adapter. In this sketch it is set to 0x3F as that matches the adapter I was using. Your I2C adapter may have a different address, if so you will need to change the value assigned to this variable accordingly. Another very common address for LCD I2C adapters is 0x28.

As with the demo sketch we define an object for the UV sensor called “uv”.

In setup we simply initialize both the LCD display and the SI1145 UV Index sensor.

The loop is very similar to the test sketch. The UV level is read and assigned to the float UVindex which is then displayed on the top line of the LCD display.

On the bottom line of the display I elected to print out some text to describe the UV Index reading. You can change this if you wish, keep in mind you have a maximum of 16 characters to play with.

After a one second delay the loop repeats itself.

The result is that the LCD display will show the current UV Index reading.

UV Index Meter with Temperature and Humidity Display

Our UV Index Meter is already a useful instrument and is capable of accurately measuring the UV Index to help keep you safe in the Sun.  But I thought it might be nice if we could also measure temperature and humidity on our meter.

Adding this function is pretty easy and again I’m going to make use of an I2C sensor.

The AM2320 is a temperature and humidity sensor that looks identical to the popular DHT11 and DHT22 devices that we have used before. However it has one important difference – it is an I2C bus device.

Connecting the AM2320 into our circuit is as easy as adding the LCD display was, it is literally wired in parallel to the SI1145 and LCD display as illustrated here:

Arduino UV Meter with Temperature and Humidity Hookup

The pinouts on the AM2320 are as follows, reading from left to right:

  • Power – 5 Volts DC
  • SDA – I2C Data line
  • GND – Ground
  • SCL – I2C Clock line

Once you have everything wired up it’s time for some code. Here is the sketch I put together for our new and improved UV Index Meter with Temperature and Humidity.

 

Once again we will need to add a library to the Arduino IDE to work with our AM2320 temperature and humidity sensor. Actually you may need to add two libraries.

The good folks at Adafruit have once again provided a library to use with our sensor, aptly named the Adafruit AM2320 Library. This library is actually dependant upon another Adafruit library, the Adafruit Unified Sensor Library.

Both of these libraries can be installed using the Library Manager, just as you did when you installed the SI1145 Library.

Our sketch contains a lot of reused code from the previous iteration of the UV Index Meter. I’ll go over the new entries now.

In addition to the libraries we included in the original sketch we will also include the two new Adafruit libraries we just installed. Note that while the Unified Sensor library is included in the sketch it is not directly referenced. It needs to be there as the AM2320 library is dependant upon it.

In addition to the objects that we define for the UV sensor and LCD display we also define an object called am2320 for the temperature and humidity sensor.

In the setup routine we initialize the UV sensor, LCD and AM2320. I also added a few lines to populate the display with a “Please Wait” message for a couple of seconds. This allows the sensors time to get some data, the temperature and humidity sensor in particular requires a second to get its first reading.

The loop is similar to the loop in the previous sketch. I reformatted the text to get the UV reading and level onto the top line, leaving the bottom line for display of the temperature and humidity.

Getting the temperature and humidity values from the AM2320 is easy, just use the readTemperature and readHumidity functions.

Note that the temperature is output in Celsius, which is what I wanted anyway. If you would prefer Fahrenheit then it’s a simple matter of doing the math – just multiply by 1.8 and add 32.

Once you have the sketch loaded fire it up. You should have an accurate UV Meter with Temperature and Humidity display.

Now grab your shades and some sunscreen and head outside and give it a test!

Conclusion

The UV Index meter you just constructed can be a valuable tool in protecting yourself from the harmful effects of the Sun’s rays.

I’m actually planning on building an even more advanced meter, with a fancier display and several additional features. As I write this it is September, meaning summer im my part of the world (Canada) is drawing to a close, so it’s a project I want to have ready for the next season.  I’ll be sure to keep you updated.

So play it safe in the sunshine, your skin and eyes will thank you for it.

Resources

Code for this article – All of the sketches used in this article.

Ultraviolet – Wikipedia article on Ultraviolet Light and Radiation

What is Ultraviolet Radiation? – A good resource from the Government of Canada

What is Ultraviolet Light? – Another excellent article on UV light by Live Science

UV Index Scale – The United States Environmental Protection Agency site that explains the UV Index.

Understanding UV LEDs and Precautions – ECN Magazine has a detailed article about selecting and using UV LEDs.

SI1145 – Specifications for the SI1145 UV Visible IR sensor

Adafruit SI1145 Library – The Adafruit Library for the SI1145 on github

 

Summary
Arduino UV Index Meter – Measuring UV Light
Article Name
Arduino UV Index Meter – Measuring UV Light
Description
Learn about Ultraviolet light and build an Arduino-based UV Index meter using the SI1145 UV sensor.
Author
Publisher Name
DroneBot Workshop
Publisher Logo
Arduino UV Index Meter – Measuring UV Light
Tagged on:     

Leave a Reply