Categories

Photoresistor and Arduino

Fotorezystor and Arduino

The tutorial shows how to cope fotorezystor using Arduino. Fotorezystor is a type of resistor whose resistance depends on the incident light rays.

 

In this example we used the following elements:

 

Fotorezystora connect with Arduino:

Unlike fototranzystora, fotorezystor does not have a definite polarization, and we can freely stick to the layout (like a normal resistor). The layout should connect as follows:

 

FotorezystorPin Arduino
The first legA1
The second leg5 V

 

In addition, pin A1 is pulled up to ground through a 1kω resistor, creating a simple voltage divider (resistor, we can pick up experimentally). You are connected is visible in the following figure:

 

 

Wiring diagram fotorezystora with the Arduino Uno.

 

Program for Arduino

Fotorezystora the value read on the analog input of Arduino. In excess of the established threshold, the program lights the led connected to pin 13. In addition, all of the time displays the value read on the display consistent. In the example, we used the following code:

int sensor = A1; //analog pin A1 is connected to the stalk fotorezystora 

void setup() { 
 Serial.begin(9600); //initialize serial monitor 
 Serial.println ("---- Test fotorezystora ----"); 
 pinMode(13, OUTPUT); //set pin 13 as output led 
} 

void loop() { 
 int war = analogRead(sensor); //read the value from A1 
 Serial.print(war); //display it on the monitor 
 if (war > 700) //if the value exceeds a prescribed threshold, then the led on 13th pine lights 
 { 
 Serial.print(" led is off"); 
 digitalWrite(13, HIGH); 
 } 
 else 
 { 
 digitalWrite(13, LOW); 
 } 
 Serial.println(""); 
 delay(200); //delay between consecutive readings 
} 

 

The effects of the program can be seen in the following screenshot:

 

A screenshot of the serial monitor.