Categories

Phototransistor and Arduino

Fototranzystor and Arduino

The tutorial shows how you can use fototranzystor using Arduino.

 

In this example we used the following elements:

 

Connect the module to Arduino:

The layout should connect as follows:

 

FototranzystorPin Arduino
Long legA1
Shorter leg5 V

 

In addition, the long leg pulls to ground through a resistor 1 kOhm (the value of the resistor, we can pick up experimentally). You are connected is visible in the following figure:

 

 

Wiring diagram fototranzystora with the Arduino Uno.

 

Program for Arduino

Fototranzystora the value read on the analog input of Arduino. When exceeding a preset threshold, the program shines the diode under the tongue 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 with the longer leg fototranzystora 

void setup() { 
 Serial.begin(9600); //initialize serial monitor 
 Serial.println("Test fototranzystora"); 
 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 > 400) 
 { 
 Serial.print(" led is off"); //if the value exceeds a prescribed threshold, then the led on 13th pine lights 
 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.