0.1.1 uv-sensor

This commit is contained in:
rob tillaart 2022-12-22 14:36:21 +01:00
parent a6e2af6b80
commit f667d575b5
11 changed files with 331 additions and 0 deletions

View File

@ -0,0 +1,28 @@
platforms:
rpipico:
board: rp2040:rp2040:rpipico
package: rp2040:rp2040
gcc:
features:
defines:
- ARDUINO_ARCH_RP2040
warnings:
flags:
packages:
rp2040:rp2040:
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
- uno
# - due
# - zero
# - leonardo
- m4
- esp32
- esp8266
# - mega2560
- rpipico

View File

@ -0,0 +1,4 @@
# These are supported funding model platforms
github: RobTillaart

View File

@ -0,0 +1,13 @@
name: Arduino-lint
on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: arduino/arduino-lint-action@v1
with:
library-manager: update
compliance: strict

View File

@ -0,0 +1,17 @@
---
name: Arduino CI
on: [push, pull_request]
jobs:
runTest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
- run: |
gem install arduino_ci
arduino_ci.rb

View File

@ -0,0 +1,18 @@
name: JSON check
on:
push:
paths:
- '**.json'
pull_request:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: json-syntax-check
uses: limitusus/json-syntax-check@v1
with:
pattern: "\\.json$"

View File

@ -0,0 +1,17 @@
# Change Log uv-sensor
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.1.1] - 2022-11-26
- Add RP2040 support to build-CI.
- Add CHANGELOG.md
- minor edits
## [0.1.0] - 2021-09-21
- initial version

View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2021-2022 Rob Tillaart
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -0,0 +1,70 @@
[![Arduino CI](https://github.com/RobTillaart/uv-sensor/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
[![Arduino-lint](https://github.com/RobTillaart/uv-sensor/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/uv-sensor/actions/workflows/arduino-lint.yml)
[![JSON check](https://github.com/RobTillaart/uv-sensor/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/uv-sensor/actions/workflows/jsoncheck.yml)
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/uv-sensor/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/uv-sensor.svg?maxAge=3600)](https://github.com/RobTillaart/uv-sensor/releases)
# uv-sensor
Arduino sketch for analog UV sensor.
## Description
![Foo](https://www.tinytronics.nl/shop/image/cache/catalog/products/product-003601/uv-light-sensor-module-200-370nm-80x80w.jpg)
Image courtesy Tinytronics
This small (type-less) UV-sensor is powered by 3.3 .. 5 V so it can be used by almost any microprocessor.
The sensor has an analogue output that is roughly linear with the UV-index (sunlight assumed, see notes)
| Voltage | UV index |
|:-------:|:--------:|
| <0.050 | 0 |
| 0.227 | 1 |
| 0.318 | 2 |
| 0.408 | 3 |
| 0.503 | 4 |
| 0.606 | 5 |
| 0.696 | 6 |
| 0.795 | 7 |
| 0.881 | 8 |
| 0.976 | 9 |
| 1.079 | 10 |
| 1.170> | 11 |
From this table the formula is derived (spreadsheet) which is pretty linear between UV 1 and 11.
Related to: https://github.com/RobTillaart/AnalogUVSensor
### Notes
Note: The sensor is not calibrated and the table is indicative for sunlight (assumption!) 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. This may help to calibrate the zero level of the sensor.
Note: depending on the light source used, the table above is incorrect.
### Sensitivity
The sensor is sensitive for wavelengths from 200 - 370 nm, so mostly in UVB and UVA region and less in the UVC.
https://en.wikipedia.org/wiki/Ultraviolet
### Future
- verify vs calibrated sensor.
- investigate angle sensitivity (if the UV light comes from an angle).
- investigate response time to stabilize (e.g. does it react fast on clouds).
- investigate with different light sources (UVled, TL, sunlight).
- allow use of internal / external ADC.
- add a pin to control the power of the sensor (low energy applications).
-

View File

@ -0,0 +1,47 @@
//
// FILE: UV_sensor.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.1
// PURPOSE: demo
// DATE: 2021-09-21
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
}
void loop()
{
Serial.println(indexUV(A0, 1023, 5.0)); // assume UNO analog port
delay(1000);
}
float indexUV(uint16_t pin, int16_t analog_max, float voltage_max)
{
uint16_t raw = analogRead(pin);
float millivolt = (voltage_max * raw * 1000) / analog_max;
float uvi = 0.0;
if (millivolt < 50)
{
return uvi;
}
if (millivolt < 227)
{
// linear interpolation between 0..1
uvi = (millivolt - 50) / (227 - 50);
return uvi;
}
// linear interpolation between 1..11
// formula derived with spreadsheet.
uvi = 0.0104865310 * millivolt - 1.289154988;
return uvi;
}
// -- END OF FILE --

View File

@ -0,0 +1,49 @@
//
// FILE: unit_test_001.cpp
// AUTHOR: Rob Tillaart
// DATE: 2022-08-04
// PURPOSE: unit tests for uv-sensor
// https://github.com/RobTillaart/uv-sensor
// https://github.com/Arduino-CI/arduino_ci/blob/master/REFERENCE.md
//
// supported assertions
// ----------------------------
// assertEqual(expected, actual)
// assertNotEqual(expected, actual)
// assertLess(expected, actual)
// assertMore(expected, actual)
// assertLessOrEqual(expected, actual)
// assertMoreOrEqual(expected, actual)
// assertTrue(actual)
// assertFalse(actual)
// assertNull(actual)
#include <ArduinoUnitTests.h>
#include "Arduino.h"
// #include "XXXXX.h"
unittest_setup()
{
}
unittest_teardown()
{
}
unittest(test_constructor)
{
assertEqual(1, 1);
}
unittest_main()
// --------

View File

@ -0,0 +1,47 @@
//
// FILE: UV_sensor.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.1
// PURPOSE: demo
// DATE: 2021-09-21
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
}
void loop()
{
Serial.println(indexUV(A0, 1023, 5.0)); // assume UNO analog port
delay(1000);
}
float indexUV(uint16_t pin, int16_t analog_max, float voltage_max)
{
uint16_t raw = analogRead(pin);
float millivolt = (voltage_max * raw * 1000) / analog_max;
float uvi = 0.0;
if (millivolt < 50)
{
return uvi;
}
if (millivolt < 227)
{
// linear interpolation between 0..1
uvi = (millivolt - 50) / (227 - 50);
return uvi;
}
// linear interpolation between 1..11
// formula derived with spreadsheet.
uvi = 0.0104865310 * millivolt - 1.289154988;
return uvi;
}
// -- END OF FILE --