Basic C++ IOT Weather Station I am making an IOT weather station based on a particle photon that sends data via webhook to one of my other projects. I am very new to c++ and programming in general. 

What can I do better with my code? What can be optimised? And what are industry best practices that I can put into place? 

Here's my code:

#include &lt;Adafruit_DHT/Adafruit_DHT.h&gt;

#define DHTPIN 2 

#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

void setup() {
Serial.begin(9600);
dht.begin();
}

void loop() {

delay(2000);

//Variables
//DHT11 sensor floats
float h = dht.getHumidity();
float t = dht.getTempCelcius();
float f = dht.getTempFarenheit();
float hi = dht.getHeatIndex();
//UV sensor floats
float sensorValue = analogRead(A0);
int UVLevel = 0;

//Error Retry
if (isnan(h) || isnan(t) || isnan(f)) 
{
Serial.println("Failed to read from DHT sensor!");
return;
}

if(sensorValue &lt;=10)
{
     UVLevel = 0;
}
if(sensorValue &lt;= 46 &amp;&amp; sensorValue &gt; 10)
{
     UVLevel = 1;
}
if(sensorValue &lt;= 65 &amp;&amp; sensorValue &gt; 46)
{
     UVLevel = 2;
}
if(sensorValue &lt;= 83 &amp;&amp; sensorValue &gt; 65)
{
     UVLevel = 3;
}
if(sensorValue &lt;= 103 &amp;&amp; sensorValue &gt; 83)
{
     UVLevel = 4;
}
if(sensorValue &lt;= 124 &amp;&amp; sensorValue &gt; 103)
{
     UVLevel = 5;
}
if(sensorValue &lt;= 142 &amp;&amp; sensorValue &gt; 124)
{
     UVLevel = 6;
}
if(sensorValue &lt;= 162 &amp;&amp; sensorValue &gt; 142)
{
     UVLevel = 7;
}
if(sensorValue &lt;= 180 &amp;&amp; sensorValue &gt; 162)
{
     UVLevel = 8;
}
if(sensorValue &lt;= 200 &amp;&amp; sensorValue &gt; 180)
{
     UVLevel = 9;
}
if(sensorValue &lt;= 221 &amp;&amp; sensorValue &gt; 200)
{
     UVLevel = 10;
}
if(sensorValue &lt;= 240 &amp;&amp; sensorValue &gt; 221)
{
     UVLevel = 11;
}
if(sensorValue &gt; 240)
{
     UVLevel = 12;
}

//Serial Print DHT
Serial.println();
Serial.println();
Serial.print("Humid: ");
Serial.print(h);
Serial.print("%");
Serial.println();
Serial.print("Temp: ");
Serial.print(t);
Serial.print("C ");
Serial.println();
Serial.print("Apparent Temperature: ");
Serial.print(hi);
Serial.println();
Serial.println();

//Serial Print UV
Serial.print("UV Level =");
Serial.print(UVLevel);
Serial.println();

//Publish Data To Particle Cloud
Particle.publish("Humidity", String(h));
Particle.publish("Temperature", String(t));
Particle.publish("Apparent Temperature", String(hi));
Particle.publish("UV Index",String(UVLevel));
delay(5000);
}


For reference these are the sensors I am using:

DHT 11 Temp/Humidity sensor

UV sensor
I'll assume the indentation is an artifact of pasting the code here.

The big problem here is that long series of if statements.  A simple improvement is to make use of the else clause, along with knowledge of what values you've tested for already, it can be simplified to

if (sensorValue &lt;= 10)
    UVLevel = 0;
else if (sensorValue &lt;= 46)
    UVLevel = 1;
// etc.


But we can do better.  Since the range of values you're checking with is contiguous, and the result (UVLevel) is linear, we can set up an array to hold the data, then just use a loop to find the right place.

static values[] = { 10, 46, 65, /* ... */, 240 };
UVLevel = std::size(values);    // 12
for (int i = 0; i &lt; std::size(values); ++i)
    if (values[i] &lt;= sensorValue) {
        UVLevel = i;
        break;
    }
}


We initially set UVLevel the the maximum value so that if the sensor value is greater than 240 we get the correct result without having to check after the loop.

For a larger range of possible values, the for loop used here can be replaced with a more complicated binary search.