Introduction: Arduino Tutorial 4: Photoresistance and Serial Monitor Comunication

In questo tutorial useremo una Fotoresistenza generica e ne ricaveremo la medesima resistenza in relazione alla luminosità della stanza. Il tutto ci è possibile attraverso il Monitor Seriale di Arduino, posto in alto a destra dell'IDE, sotto forma di lente d'ingrandimento.

Utilizzeremo i comandi

  • Serial.begin(9600), per cominciare la comunicazione, attraverso il monitor seriale, con Arduino;
  • Serial.print(), seve a scrivere nel monitor seriale nella stessa riga;
  • Serial.println(), serve a scrivere nel monitor seriale e andare immediatamente a capo.
In this tutorial we will use a generic Photo Resistance and we will get the same resistance in relation to the brightness of the room. All this is possible through the Arduino Serial Monitor, located at the top right of the IDE, in the form of a magnifying glass.

We will use commands
  • Serial.begin (9600), to begin communication, through the serial monitor, with Arduino;
  • Serial.print (), to write to the serial monitor in the same line;
  • Serial.println (), is used to write to the serial monitor and go immediately to head.

Step 1: Progettazione / Design

La fotoresistenza viene collegata esattamente come un pulsante, un piedino va a 5V, l'altro attraverso una resistenza a GND e al pin Analogico A1;

Materiale Occorrente:

  • Fotoresistenza di grandezza generica;
  • Resistenza generica (22K nel mio circuito).
The photoresistor is connected exactly as a button, a pin goes to 5V, the other through a GND resistor and Analog pin A1;
Material Required:
  • Photoresistor of generic magnitude;
  • Generic Existence (22K in my circuit).

Step 2: Programma / Programming

#define fotor A1    //Definiamo il pin della fotoresistenza

int luminosita=0;

void setup() {
pinMode(fotor,INPUT); Serial.begin(9600); //Apriamo la comunicazione Seriale a 9600 baud }

void loop() { luminosita= analogRead(fotor); //Leggiamo il valore della fotoresistenza Serial.println(luminosita); // Scriviamo nel monitor seriale i dati ottenuti delay(100);

}