Laboratory n°1


In this version of our arduino program, there are different step. The first function is the initialization of the arduino board. The initialization part is used to said who works and how it works.
For example, we initiale the serial connection at 9600 bauds, the pin A0 like a analogue input and the pin 5 like a analogue output. It’s better but not a obligation.
The next part is a infinity loop, the first step in this part is to read the value of the sensor and next to transform this in normal value.
The last part transform the value after correction of the value. We write the value in output

/* // Regulation of the light //
Reads an analog input pin (it’s a number between 0 – 1024) and next, maps the result to a range from 0 to 255
and uses the result to set the pulsewidth modulation (PWM) of an output pin.
Also prints the results to the serial monitor to check the value.
The circuit:
* Connect sensor output to Analog Pin 0.
Connect 3.3v to the AREF pin
Connect 5v to VCC and GND to GND
* LED connected from digital pin 5 to ground
// to the pins used:
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int analogOutPin = 5; // Analog output pin that the LED is attached to
float rawRange = 1024; // 3.3v
float logRange = 5.0; // 3.3v = 10^5 lux
int sensorValue = 0; // value read from the pot
int outputValue = 0; // value output to the PWM (analog out)

// Void setup is the function that your arduino call for the initialization
// In this program, we use an analogue reference extern (3.3V) to improve the precision because // the scale is between 0 – 3.3V for 1024 Values
void setup()
analogReference(EXTERNAL); //
void loop()
// Read the analog in value and display this in the serial
int rawValue = analogRead(analogInPin);
Serial.print(“Raw = “);
Serial.print(” – Lux = “);
// map it to the range of the analog out
outputValue = map(rawValue, 0, 1023, 255, 0);
analogWrite(analogOutPin, outputValue);
Serial.print(“\t output = “);
// This function is a little bit strange but this function is supplied with the sensor
float RawToLux(int raw)
float logLux = raw * logRange / rawRange;
return pow(10, logLux);

You can find our laboratory here : Lab_1

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.