otronics:
I am looking to create a project that measures the UV Index.
What is the best wireless card to use?
I'm a total beginner to this, so getting this all going and coding would be great!
I would probably use a WeMos D1 mini, or a bare ESP8266-12 module.
Arduino, WiFi and flash storage all in one.
But this project could be too advanced for a beginner. Read this guide. The last part has a temp logger that could be converted to a UV logger.
Leo..
My UV sensor is in a weatherproof box with a clear plastic top. Or at least it was when I installed it 7~8 months ago. Now the clear plastic has gone milky and the screws have corroded! Must find a better quality box...
Indeed, only one analog input on the NodeMCU/ESP8266, and indeed it's called A0 (the markings at the pin you connect your sensor to should have acted as strong suggestion to what pin number to use in your code!).
C:\Users\OTronics\Documents\Arduino\libraries\plotly_streaming_wifi\plotly_streaming_wifi.cpp:5:25: fatal error: avr/dtostrf.h: No such file or directory
"avr" is a trade mark of the manufacturer Atmel who make the chips in most Arduino. But they did not make the esp8266. So that library may not be available/suitable for esp. You need to find an equivalent library that is suitable.
Why not post your code so we can suggest how to fix it? Use code tags.
PaulRB:
"avr" is a trade mark of the manufacturer Atmel who make the chips in most Arduino. But they did not make the esp8266. So that library may not be available/suitable for esp. You need to find an equivalent library that is suitable.
Why not post your code so we can suggest how to fix it? Use code tags.
OK - that explains it.
Here is my project code, followed by the .h and .cpp wifi files. I've not added individual settings to my code (ie/ wifi passwords etc) - just trying to get it to compile first.
PROJECT CODE:
#include <WiFi.h>
#include "plotly_streaming_wifi.h"
// Sign up to plotly here: https://plot.ly
// View your API key and streamtokens here: https://plot.ly/settings
#define nTraces 3
// View your tokens here: https://plot.ly/settings
// Supply as many tokens as data traces
// e.g. if you want to ploty A0 and A1 vs time, supply two tokens
char *tokens[nTraces] = {"25tm9197rz", "unbi52ww8a", "ibsfyg7qd8"};
// arguments: username, api key, streaming token, filename
plotly graph = plotly("workshop", "v6w5xlbx9j", tokens, "your_filename", nTraces);
// Setup UV Sensor (ML8511) Pins
int UVOUT = A0;
const byte REF_3V3 = A0;
int status = WL_IDLE_STATUS; // the Wifi radio's status
char ssid[] = "wifi_network_name"; // your network SSID (name)
char pass[] = "wifi_network_password"; // // your network password
void wifi_connect(){
// attempt to connect using WPA2 encryption:
Serial.println("... Attempting to connect to WPA network...");
status = WiFi.begin(ssid, pass);
// if you're not connected, stop here:
if ( status != WL_CONNECTED) {
Serial.println("... Couldn't get a WiFi connection, trying again");
wifi_connect();
}
// if you are connected, print out info about the connection:
else {
Serial.println("... Connected to network");
}
}
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// Initialize pinMode for UV Sensor
pinMode(UVOUT, INPUT);
pinMode(REF_3V3, INPUT);
wifi_connect();
graph.fileopt="overwrite"; // See the "Usage" section in https://github.com/plotly/arduino-api for details
bool success;
success = graph.init();
if(!success){while(true){}}
graph.openStream();
}
void loop() {
int uvLevel = averageAnalogRead(UVOUT);
int refLevel = averageAnalogRead(REF_3V3);
float outputVoltage = 3.3 / refLevel * uvLevel;
float uvIntensity = mapfloat(outputVoltage, 0.99, 2.9, 0.0, 15.0);
Serial.print("MP8511 output: ");
Serial.print(uvLevel);
graph.plot(millis(), uvLevel, tokens[0]);
Serial.print("MP8511 voltage: ");
Serial.print(outputVoltage);
graph.plot(millis(), outputVoltage, tokens[1]);
Serial.print("UV Intensity (mW/cm^2): ");
Serial.print(uvIntensity);
graph.plot(millis(), uvIntensity, tokens[2]);
delay(200);
}
//Takes an average of readings on a given pin
//Returns the average
int averageAnalogRead(int pinToRead)
{
byte numberOfReadings = 8;
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;
}