Advertisement
lorenzo_cesaretti

Fotoresistenza Arduino

Apr 13th, 2021
18,182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int analogInPin = A0;
  2. int sensorValue = 0;
  3. int ledR = 5;
  4. int ledV = 3;
  5.  
  6. void setup() {
  7.   Serial.begin(9600);
  8.   pinMode( analogInPin, INPUT);
  9.   pinMode (ledR, OUTPUT);
  10.   pinMode (ledV, OUTPUT);
  11. }
  12.  
  13. void loop() {
  14.   sensorValue = analogRead(analogInPin);  
  15.   if (sensorValue<200){
  16.     digitalWrite (ledV,HIGH);          
  17.   }
  18.   else{
  19.     digitalWrite (ledV,LOW);
  20.   }
  21.   if (sensorValue>700){
  22.     digitalWrite (ledR,HIGH);
  23.   }
  24.   else{
  25.     digitalWrite (ledR,LOW);
  26.   }
  27.  
  28.   Serial.print("sensor = " );
  29.   Serial.println(sensorValue);      
  30.  
  31.   delay(1000);
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement