mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.1.1 AnalogUVSensor
This commit is contained in:
parent
5625713596
commit
0f5a750eb0
@ -2,6 +2,10 @@ compile:
|
|||||||
# Choosing to run compilation tests on 2 different Arduino platforms
|
# Choosing to run compilation tests on 2 different Arduino platforms
|
||||||
platforms:
|
platforms:
|
||||||
- uno
|
- uno
|
||||||
- leonardo
|
# - due
|
||||||
- due
|
# - zero
|
||||||
- zero
|
# - leonardo
|
||||||
|
- m4
|
||||||
|
- esp32
|
||||||
|
# - esp8266
|
||||||
|
# - mega2560
|
@ -1,12 +1,14 @@
|
|||||||
//
|
//
|
||||||
// FILE: AnalogUVSensor.h
|
// FILE: AnalogUVSensor.h
|
||||||
// AUTHOR: Rob Tillaart
|
// AUTHOR: Rob Tillaart
|
||||||
// VERSION: 0.1.0
|
// VERSION: 0.1.1
|
||||||
// DATE: 2021-09-25
|
// DATE: 2021-09-25
|
||||||
// PURPOSE: AnalogUVSensor library
|
// PURPOSE: AnalogUVSensor library
|
||||||
//
|
//
|
||||||
// HISTORY:
|
// HISTORY:
|
||||||
// 0.1.0 2021-09-25 initial version
|
// 0.1.0 2021-09-25 initial version
|
||||||
|
// 0.1.1 2021-10-17 update build-ci, readme.md
|
||||||
|
// refactor, plotter example
|
||||||
|
|
||||||
|
|
||||||
#include "AnalogUVSensor.h"
|
#include "AnalogUVSensor.h"
|
||||||
@ -34,6 +36,7 @@ void AnalogUVSensor::begin(uint8_t analogPin, float volts, uint16_t maxADC)
|
|||||||
float AnalogUVSensor::read(uint8_t times)
|
float AnalogUVSensor::read(uint8_t times)
|
||||||
{
|
{
|
||||||
uint32_t sum = 0;
|
uint32_t sum = 0;
|
||||||
|
if (times == 0) times = 1;
|
||||||
for (int i = 0; i < times; i++)
|
for (int i = 0; i < times; i++)
|
||||||
{
|
{
|
||||||
sum += analogRead(_analogPin);
|
sum += analogRead(_analogPin);
|
||||||
@ -50,7 +53,8 @@ float AnalogUVSensor::mV2index(uint16_t milliVolt)
|
|||||||
if (milliVolt < 227) return 0.0 + (1.0 * milliVolt - 50.0) / (227.0 - 50.0);
|
if (milliVolt < 227) return 0.0 + (1.0 * milliVolt - 50.0) / (227.0 - 50.0);
|
||||||
// linear interpolation between 1..11
|
// linear interpolation between 1..11
|
||||||
// formula derived with spreadsheet.
|
// formula derived with spreadsheet.
|
||||||
return 0.0104865310 * milliVolt - 1.289154988;
|
if (milliVolt < 1200) return 0.0104865310 * milliVolt - 1.289154988;
|
||||||
|
return 12;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
//
|
//
|
||||||
// FILE: AnalogUVSensor.h
|
// FILE: AnalogUVSensor.h
|
||||||
// AUTHOR: Rob Tillaart
|
// AUTHOR: Rob Tillaart
|
||||||
// VERSION: 0.1.0
|
// VERSION: 0.1.1
|
||||||
// DATE: 2021-09-25
|
// DATE: 2021-09-25
|
||||||
// PURPOSE: AnalogUVSensor library
|
// PURPOSE: AnalogUVSensor library
|
||||||
//
|
//
|
||||||
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
|
|
||||||
#define ANALOG_UVSENSOR_LIB_VERSION (F("0.1.0"))
|
#define ANALOG_UVSENSOR_LIB_VERSION (F("0.1.1"))
|
||||||
|
|
||||||
|
|
||||||
class AnalogUVSensor
|
class AnalogUVSensor
|
||||||
|
@ -1,7 +1,16 @@
|
|||||||
|
|
||||||
|
[![Arduino CI](https://github.com/RobTillaart/AnalogUVSensor/actions/workflows/arduino_test_runner.yml/badge.svg)](https://github.com/RobTillaart/AnalogUVSensor/actions/workflows/arduino_test_runner.yml)
|
||||||
|
[![Arduino-lint](https://github.com/RobTillaart/AnalogUVSensor/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/AnalogUVSensor/actions/workflows/arduino-lint.yml)
|
||||||
|
[![JSON check](https://github.com/RobTillaart/AnalogUVSensor/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/AnalogUVSensor/actions/workflows/jsoncheck.yml)
|
||||||
|
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/AnalogUVSensor/blob/master/LICENSE)
|
||||||
|
[![GitHub release](https://img.shields.io/github/release/RobTillaart/AnalogUVSensor.svg?maxAge=3600)](https://github.com/RobTillaart/AnalogUVSensor/releases)
|
||||||
|
|
||||||
|
|
||||||
# AnalogUVSensor
|
# AnalogUVSensor
|
||||||
|
|
||||||
Arduino library for analogue UV sensor
|
Arduino library for analogue UV sensor
|
||||||
|
|
||||||
|
|
||||||
## Description
|
## Description
|
||||||
|
|
||||||
![Foo](https://www.tinytronics.nl/shop/image/cache/catalog/products/product-003601/uv-light-sensor-module-200-370nm-80x80w.jpg)
|
![Foo](https://www.tinytronics.nl/shop/image/cache/catalog/products/product-003601/uv-light-sensor-module-200-370nm-80x80w.jpg)
|
||||||
@ -28,42 +37,55 @@ The sensor has an analogue output that is roughly linear with the UV-index (sunl
|
|||||||
| 1.170> | 11 |
|
| 1.170> | 11 |
|
||||||
|
|
||||||
From this table the formula is derived (spreadsheet) which is pretty linear between UV 1 and 11.
|
From this table the formula is derived (spreadsheet) which is pretty linear between UV 1 and 11.
|
||||||
|
Between 0 and 1 there seems to be a curve / other linear relation.
|
||||||
|
|
||||||
|
|
||||||
### Notes
|
### Notes
|
||||||
|
|
||||||
Note: The sensor is not calibrated and the table is indicative for sunlight (assumption!)
|
Note: The sensor is not calibrated and the table is indicative for sunlight (warning assumption!)
|
||||||
and therefore not suitable for e.g. medical or industrial usage.
|
and therefore not suitable for e.g. medical or industrial usage.
|
||||||
|
|
||||||
Note: UV radiation will not go through glass, so inside you will most likely always read zero.
|
Note: UV radiation will not go through normal glass, so inside (a house) you will most likely always read zero.
|
||||||
This may help to calibrate the zero level of the sensor.
|
This may of course help to calibrate the zero level of the sensor.
|
||||||
|
|
||||||
Note: depending on the light source used, the table above is incorrect.
|
Note: depending on the light source used, the table above is incorrect.
|
||||||
If one wants to use other values one need to fix this in the **mv2index()** function.
|
If one wants to use other values one need to fix the formula in the **mv2index()** function.
|
||||||
|
|
||||||
|
Note: the output of the sensor is typically 0 .. 1.1 volt. To increase precision one might configure
|
||||||
|
the ADC used to match this voltage range. E.g. Arduino UNO can be set to use an internal 1.1 volt reference.
|
||||||
|
See Arduino manual **setAnalogReference()**
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Sensitivity
|
### Wavelength sensitivity
|
||||||
|
|
||||||
The sensor is sensitive for wavelengths from 200 - 370 nm, so mostly in UVB and UVA region and less in the UVC.
|
The sensor is sensitive for wavelengths from 200 - 370 nm, so mostly in UVB and UVA region and less in the UVC.
|
||||||
|
There is no information about the detailed wavelength sensitivity, so it is not possible to compensate.
|
||||||
|
However one could assume that there is a normal (or other) distribution over the 200 - 370 nm range and create
|
||||||
|
a compensation table based upon the assumed distribution.
|
||||||
|
|
||||||
https://en.wikipedia.org/wiki/Ultraviolet
|
More about UV see - https://en.wikipedia.org/wiki/Ultraviolet
|
||||||
|
|
||||||
|
|
||||||
## Interface
|
## Interface
|
||||||
|
|
||||||
- **AnalogUVSensor()** Constructor.
|
- **AnalogUVSensor()** Constructor.
|
||||||
- **void begin(uint8_t analogPin, float volts = 5.0, uint16_t maxADC = 1023)**
|
- **void begin(uint8_t analogPin, float volts = 5.0, uint16_t maxADC = 1023)**
|
||||||
set the parameters of the sensor, analogPin, volts and maxADC to specify the internal ADC. Volts and maxADC have a default so these can be omitted.
|
set the parameters of the sensor, analogPin, volts and maxADC to specify the internal ADC.
|
||||||
Note that one needs to reset these parameters if the settings of the internal ADC are
|
Volts and maxADC have a default so these can be omitted if these match.
|
||||||
|
Note: one needs to reset these parameters if the settings of the internal ADC are
|
||||||
changed e.g. to INTERNAL_1V1 to change the accuracy.
|
changed e.g. to INTERNAL_1V1 to change the accuracy.
|
||||||
- **float read(uint8_t times = 1)** Returns the UV index.
|
- **float read(uint8_t times = 1)** Returns the UV index.
|
||||||
Read the analogue sensor one (or more) times to average the reading.
|
Read the analogue sensor one (or more) times to average the reading.
|
||||||
This can improve the accuracy of the reading.
|
This can improve the accuracy of the reading.
|
||||||
|
If times == 0 it is set to 1.
|
||||||
- **float mV2index(uint16_t milliVolt)** Returns the UV index.
|
- **float mV2index(uint16_t milliVolt)** Returns the UV index.
|
||||||
The conversion formula from milliVolt to the UV index used internally by the **read()** function.
|
The conversion formula from milliVolt to the UV index is used internally by the **read()** function.
|
||||||
This function can also be called with a voltage measured with an external ADC.
|
This function can also be called with a voltage measured with an external ADC.
|
||||||
- **char index2color(float index)** Converts an index to the first letter of Green,
|
THe function will return a value between 0.0 and 12.0.
|
||||||
Yellow, Orange, Red or Purple. Can be used as indication on a user interface.
|
- **char index2color(float index)** Converts an UV index to the first letter of **G**reen,
|
||||||
|
**Y**ellow, **O**range, **R**ed or **P**urple.
|
||||||
|
Can be used as indication on a user interface.
|
||||||
This function can also be called with an index from an other UV index sensor.
|
This function can also be called with an index from an other UV index sensor.
|
||||||
|
|
||||||
|
|
||||||
@ -73,9 +95,10 @@ Works only if setPowerPin is called properly.
|
|||||||
|
|
||||||
- **void setPowerPin(uint8_t powerPin, bool invert = false)**
|
- **void setPowerPin(uint8_t powerPin, bool invert = false)**
|
||||||
Can be used to control the power of the sensor e.g. for low power mode.
|
Can be used to control the power of the sensor e.g. for low power mode.
|
||||||
Optionally one can set the invert flag to **true** to invert the **HIGH LOW** levels e.g. when the analogue sensor is switched through a MOSFET.
|
Optionally one can set the invert flag to **true** to invert the **HIGH LOW** levels
|
||||||
- **void switchOff()** should switch off the power of the sensor.
|
e.g. when the analogue sensor is switched through a MOSFET.
|
||||||
- **void switchOn()** should switch on the power of the sensor.
|
- **void switchOff()** switch off the power of the sensor.
|
||||||
|
- **void switchOn()** switch on the power of the sensor.
|
||||||
|
|
||||||
|
|
||||||
### Future
|
### Future
|
||||||
@ -85,7 +108,8 @@ Optionally one can set the invert flag to **true** to invert the **HIGH LOW** le
|
|||||||
- investigate response time to stabilize e.g. does it react fast on clouds.
|
- investigate response time to stabilize e.g. does it react fast on clouds.
|
||||||
- investigate with different light sources (UVled, TL, sunlight).
|
- investigate with different light sources (UVled, TL, sunlight).
|
||||||
- investigate time needed to first (stable) measurement.
|
- investigate time needed to first (stable) measurement.
|
||||||
- **index2time()** calculate max exposure time? dangerous?
|
- **index2time()** calculate max exposure time? dangerous advice?
|
||||||
|
- **uint32_t index2RGB(float index)** full colour RGB mapping.
|
||||||
|
|
||||||
|
|
||||||
## Sponsor
|
## Sponsor
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
//
|
//
|
||||||
// FILE: UV_sensor.ino
|
// FILE: UV_sensor.ino
|
||||||
// AUTHOR: Rob Tillaart
|
// AUTHOR: Rob Tillaart
|
||||||
// VERSION: 0.1.0
|
|
||||||
// PURPOSE: demo
|
// PURPOSE: demo
|
||||||
// DATE: 2021-09-21
|
// DATE: 2021-09-21
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
//
|
//
|
||||||
// FILE: demUV.ino
|
// FILE: demUV.ino
|
||||||
// AUTHOR: Rob Tillaart
|
// AUTHOR: Rob Tillaart
|
||||||
// VERSION: 0.1.0
|
|
||||||
// PURPOSE: demo UV sensor
|
// PURPOSE: demo UV sensor
|
||||||
// DATE: 2021-09-25
|
// DATE: 2021-09-25
|
||||||
|
|
||||||
@ -25,7 +24,7 @@ void setup()
|
|||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
float uvi = AUV.read();
|
float uvi = AUV.read(3); // average 3 readings
|
||||||
Serial.print("UVI: ");
|
Serial.print("UVI: ");
|
||||||
Serial.print(uvi, 1);
|
Serial.print(uvi, 1);
|
||||||
Serial.print("\t");
|
Serial.print("\t");
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
//
|
//
|
||||||
// FILE: uvi_demo.ino
|
// FILE: uvi_demo.ino
|
||||||
// AUTHOR: Rob Tillaart
|
// AUTHOR: Rob Tillaart
|
||||||
// VERSION: 0.1.0
|
|
||||||
// PURPOSE: demo UV sensor
|
// PURPOSE: demo UV sensor
|
||||||
// DATE: 2021-09-25
|
// DATE: 2021-09-25
|
||||||
|
|
||||||
@ -24,7 +23,7 @@ void setup()
|
|||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
float uvi = AUV.read();
|
float uvi = AUV.read(5); // average 5 readings
|
||||||
Serial.print("UVI: ");
|
Serial.print("UVI: ");
|
||||||
Serial.println(uvi, 1);
|
Serial.println(uvi, 1);
|
||||||
delay(1000);
|
delay(1000);
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
//
|
//
|
||||||
// FILE: uvi_demo_low_power.ino
|
// FILE: uvi_demo_low_power.ino
|
||||||
// AUTHOR: Rob Tillaart
|
// AUTHOR: Rob Tillaart
|
||||||
// VERSION: 0.1.0
|
|
||||||
// PURPOSE: demo UV sensor
|
// PURPOSE: demo UV sensor
|
||||||
// DATE: 2021-09-25
|
// DATE: 2021-09-25
|
||||||
|
|
||||||
@ -21,7 +20,7 @@ void setup()
|
|||||||
|
|
||||||
AUV.begin(A0, 5.0, 1023);
|
AUV.begin(A0, 5.0, 1023);
|
||||||
|
|
||||||
AUV.setPowerPin(4);
|
AUV.setPowerPin(4); // connect power of sensor to pin 4
|
||||||
AUV.switchOff();
|
AUV.switchOff();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,7 +28,7 @@ void setup()
|
|||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
AUV.switchOn();
|
AUV.switchOn();
|
||||||
float uvi = AUV.read();
|
float uvi = AUV.read(); // default is 1 read
|
||||||
AUV.switchOff();
|
AUV.switchOff();
|
||||||
|
|
||||||
Serial.print("UVI: ");
|
Serial.print("UVI: ");
|
||||||
|
@ -0,0 +1,47 @@
|
|||||||
|
//
|
||||||
|
// FILE: uvi_plotter.ino
|
||||||
|
// AUTHOR: Rob Tillaart
|
||||||
|
// PURPOSE: demo UV sensor
|
||||||
|
// DATE: 2021-10-17
|
||||||
|
|
||||||
|
// Use the Arduino IDE -> Tools -> Serial plotter
|
||||||
|
// to get a graph.
|
||||||
|
|
||||||
|
#include "AnalogUVSensor.h"
|
||||||
|
|
||||||
|
AnalogUVSensor AUV;
|
||||||
|
float lastRead = 0;
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
Serial.begin(115200);
|
||||||
|
// Serial.println(__FILE__);
|
||||||
|
// Serial.print("ANALOG_UVSENSOR_LIB_VERSION: ");
|
||||||
|
// Serial.println(ANALOG_UVSENSOR_LIB_VERSION);
|
||||||
|
|
||||||
|
AUV.begin(A0, 5.0, 1023);
|
||||||
|
lastRead = AUV.read(5); // average 5 readings
|
||||||
|
|
||||||
|
// print the header for the plotter.
|
||||||
|
Serial.println("UVI \tLAST \tDELTA");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
float uvi = AUV.read(5); // average 5 readings
|
||||||
|
float delta = uvi - lastRead;
|
||||||
|
|
||||||
|
Serial.print(uvi, 1);
|
||||||
|
Serial.print('\t');
|
||||||
|
Serial.print(lastRead, 1);
|
||||||
|
Serial.print('\t');
|
||||||
|
Serial.print(delta, 1);
|
||||||
|
Serial.print('\n');
|
||||||
|
|
||||||
|
lastRead = uvi;
|
||||||
|
delay(1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// -- END OF FILE --
|
@ -1,7 +1,6 @@
|
|||||||
//
|
//
|
||||||
// FILE: uvi_test.ino
|
// FILE: uvi_test.ino
|
||||||
// AUTHOR: Rob Tillaart
|
// AUTHOR: Rob Tillaart
|
||||||
// VERSION: 0.1.0
|
|
||||||
// PURPOSE: demo UV sensor
|
// PURPOSE: demo UV sensor
|
||||||
// DATE: 2021-09-25
|
// DATE: 2021-09-25
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/RobTillaart/AnalogUVSensor.git"
|
"url": "https://github.com/RobTillaart/AnalogUVSensor.git"
|
||||||
},
|
},
|
||||||
"version": "0.1.0",
|
"version": "0.1.1",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"frameworks": "arduino",
|
"frameworks": "arduino",
|
||||||
"platforms": "*"
|
"platforms": "*"
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
name=AnalogUVSensor
|
name=AnalogUVSensor
|
||||||
version=0.1.0
|
version=0.1.1
|
||||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||||
sentence=AnalogUVSensor library for Arduino.
|
sentence=AnalogUVSensor library for Arduino.
|
||||||
|
Loading…
Reference in New Issue
Block a user