[Arduino] Photoresistor


ok,
some days ago, there was arduino uno starter kit (IN OFFERTA) on amazon and so i wanted to try it...
my first project is photoresistor. One things that i love of Arduino instead of Raspberry is that in Arduino there are
analog inputs that makes life simpler. A thing that i hate of Arduino is that you need and IDE to write scripts, upload it to Arduino and execute.
There is Arduino IDE but i found an extension of Visual Studio that allows to write build and execute Arduino projects that seems very usefull.
You can find it on Visual Studio Gallery extension.

For this project we need this following things:

- Arduino...
- some wires
- photoresistor
- 1 10k Ohm resistor
- breadboard

connections schema is this:

Arduino 5v -----------> positive rail of breadboard
Arduino GND ----------> negative rail of breadboard
positive rail of breadboard ------> one pin of photoresistor
Arduino A0 -----------> second pin of photoresistor
rail in witch there is the second pin of photoresistor place the resistor and connect it to negative rail of breadboard

you shoul have a connection like this:




then use this code to read from photoresistor:


/////////////////////////////////////////////
int retrievedValue;


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


void loop() {
    retrievedValue = analogRead(A0);  // reading value from analog input AO

    int lightLevel = map(retrievedValue, 0, 1023, 0, 100);

    Serial.print("light value = ");
    Serial.print(lightLevel);
    Serial.print("%");
    Serial.println("");

    delay(3000);
}
/////////////////////////////////////////////



this is a screen of visual studio ide executing the script:



that's all folks!

see you for another experiment

Commenti