初始化提交

This commit is contained in:
王立帮
2024-07-20 22:09:06 +08:00
commit c247dd07a6
6876 changed files with 2743096 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
/*
ML8511_library_test.ino
Emanuele Signoretta, 2017
*/
#include <ML8511.h>
#define UVOUT A0 // define the pin attached to the ML8511 output
#define REF_3V3 A1 //define the 3.3 reference pin
double uvIntensity;
double outputVoltage;
ML8511 uv(UVOUT, REF_3V3); //create the ML8511's uv object
void setup() {
Serial.begin(115200); // begin the serial communication
Serial.print("ML8511 uv sensor library test. \n \n");
Serial.print("Emanuele Signoretta. 2017 \n \n");
Serial.print("Starting sensor. ");
while (!uv.begin()) { //wait until the sensor is ready
Serial.print(".");
delay(500);
}
Serial.println("Sensor started!");
}
void loop() {
outputVoltage = uv.getoutputVoltage(); // get the output voltage from the sensor
uvIntensity = uv.getuvIntensity(); // get the UV intensity from the sensor
//print the data on the serial port
Serial.print("Output voltage: ");
Serial.print(outputVoltage);
Serial.print(" v ");
Serial.print("UV intensity: ");
Serial.print(uvIntensity);
Serial.println(" mW/cm^2.");
delay (1000);
}

View File

@@ -0,0 +1,151 @@
/*
ML8511 UV Sensor Read Example
By: Nathan Seidle
SparkFun Electronics
Date: January 15th, 2014
License: This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license).
The ML8511 UV Sensor outputs an analog signal in relation to the amount of UV light it detects.
These last two connections are a little different. Connect the EN pin on the breakout to 3.3V on the breakout.
This will enable the output. Also connect the 3.3V pin of the breakout to Arduino pin 1.
This example uses a neat trick. Analog to digital conversions rely completely on VCC. We assume
this is 5V but if the board is powered from USB this may be as high as 5.25V or as low as 4.75V:
http://en.wikipedia.org/wiki/USB#Power Because of this unknown window it makes the ADC fairly inaccurate
in most cases. To fix this, we use the very accurate onboard 3.3V reference (accurate within 1%). So by doing an
ADC on the 3.3V pin (A1) and then comparing this against the reading from the sensor we can extrapolate
a true-to-life reading no matter what VIN is (as long as it's above 3.4V).
Test your sensor by shining daylight or a UV LED: https://www.sparkfun.com/products/8662
This sensor detects 280-390nm light most effectively. This is categorized as part of the UVB (burning rays)
spectrum and most of the UVA (tanning rays) spectrum.
There's lots of good UV radiation reading out there:
http://www.ccohs.ca/oshanswers/phys_agents/ultravioletradiation.html
https://www.iuva.org/uv-faqs
*/
/*
* Website:
https://hshop.vn/products/cam-bien-anh-sang-uvm-30a
https://hshop.vn/products/lcd1602-keypad-shield
https://hshop.vn/products/vietduino-uno
https://hshop.vn/search?type=product&q=day%20cam%20breadboard
Connect the following ML8511 breakout board to Arduino:
3.3V = 3.3V
OUT = A2
GND = GND
EN = 3.3V
3.3V = A1
*/
#include <LiquidCrystal.h>
LiquidCrystal lcd(8,9,4,5,6,7);
// https://learn.sparkfun.com/tutorials/ml8511-uv-sensor-hookup-guide
//Hardware pin definitions
int UVOUT = A2; //Output from the sensor
int REF_3V3 = A1; //3.3V power on the Arduino board
const int numReadings = 100;
int readings[numReadings]; // the readings from the analog input
int readIndex = 0; // the index of the current reading
int total = 0; // the running total
int average = 0; // the average
int inputPin = A0;
void setup()
{
Serial.begin(9600);
lcd.begin(16, 2);
lcd.print("UV value:");
pinMode(UVOUT, INPUT);
pinMode(REF_3V3, INPUT);
Serial.println("ML8511 example");
}
void loop()
{
// int uvLevel = averageAnalogRead(UVOUT);
float uvLevel = readAnalog_();
float refLevel = averageAnalogRead(REF_3V3);
//Use the 3.3V power pin as a reference to get a very accurate output value from sensor
float outputVoltage = 3.3 / refLevel * uvLevel;
float uvIntensity = mapfloat(outputVoltage, 0.99, 2.8, 0.0, 15.0); //Convert the voltage to a UV intensity level
Serial.print("output: ");
Serial.print(refLevel);
Serial.print("ML8511 output: ");
Serial.print(uvLevel);
Serial.print(" / ML8511 voltage: ");
Serial.print(outputVoltage);
Serial.print(" / UV Intensity (mW/cm^2): ");
Serial.print(uvIntensity);
Serial.println();
lcd.setCursor(0, 1);
// print the number of seconds since reset:
// String dataStr =
lcd.print(String(uvIntensity) + " ");
delay(100);
}
//Takes an average of readings on a given pin
//Returns the average
int averageAnalogRead(int pinToRead)
{
byte numberOfReadings = 300;
unsigned int runningValue = 0;
for(int x = 0 ; x < numberOfReadings ; x++)
runningValue += analogRead(pinToRead);
runningValue /= numberOfReadings;
return(runningValue);
}
//The Arduino Map function but for floats
//From: http://forum.arduino.cc/index.php?topic=3922.0
float mapfloat(float x, float in_min, float in_max, float out_min, float out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
float readAnalog_()
{
total = total - readings[readIndex];
// read from the sensor:
readings[readIndex] = analogRead(UVOUT);
// add the reading to the total:
total = total + readings[readIndex];
// advance to the next position in the array:
readIndex = readIndex + 1;
// if we're at the end of the array...
if (readIndex >= numReadings) {
// ...wrap around to the beginning:
readIndex = 0;
}
// calculate the average:
average = total / numReadings;
// send it to the computer as ASCII digits
Serial.print("KXN = " + String(average) + "====");\
return average;
}