UV sensor code

So we are doing a project where we gonna use 3 UV sensors.

I was just wondering how can we use the code more than one time? Like how can we triple it?

this is the code. IT was actually written for Energia launchpad.. Feel free to change into an Arduino code /* AnalogReadSerial Reads an analog input on pin A3, prints the result to the serial monitor. Attach the center pin of a potentiometer to pin A3, and the outside pins to ~3V and ground.

Hardware Required: * MSP-EXP430G2 LaunchPad * 10-kilohm Potentiometer * hook-up wire

This example code is in the public domain. */

// the setup routine runs once when you press reset: void setup() { // initialize serial communication at 9600 bits per second: Serial.begin(9600); // msp430g2231 must use 4800 }

// the loop routine runs over and over again forever: void loop() { // read the input on analog pin A3: int sensorValue = analogRead(A1)* (3.3/4096.0); // print out the value you read: Serial.println(sensorValue); delay(1); // delay in between reads for stability }

pin A3 ? analogRead(A1)

Use more than one analog input pin?

Hi guys,

So, we are making a project where we use 3 UV sensors.

We want to get the readings of 3 sensors connected together but we want the serial monitor to show only the readings of the highest intensity of the sensors. So whenever one of the sensor is been directed towards the sun we want only that sensor’s readings to show up. And we are not sure how to make the 3 sensors all in one code

Thanks!

This is the original code of the Sensor

//Hardware pin definitions
int UVOUT = A0; //Output from the sensor
int REF_3V3 = A1; //3.3V power on the Arduino board

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

  pinMode(UVOUT, INPUT);
  pinMode(REF_3V3, INPUT);

  Serial.println("ML8511 example");
}

void loop()
{
  int uvLevel = averageAnalogRead(UVOUT);
  int 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();
  
  delay(100);
}

//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;
}

For three sensors, use three analogue inputs. e.g.:

int REF_3V3 = A0 (was A1) int UVOUT1 = A1 int UVOUT2 = A2 int UVOUT3 = A3

I would first calculate each individual sensor. And then work out the highest one, and display that on the serial monitor. Leo..