Files
Arduino/photoresistor1/photoresistor1.ino
Jérôme Delacotte 7b30d6e298 first commit
2025-03-06 11:15:32 +01:00

52 lines
1.5 KiB
C++
Executable File

/*
Basic Analogue Input Control - PhotoResistor Input
This example reads an analogue value from analogue in pin 1 and then compares this to a set point.
If the set point is threshold is crossed, the LED on digital pin 7 is turned on/off.
Author: David M. Auld
Date: 9th October 2009
*/
int photoIn = A0; // photoresistor on Analogue Pin 1
int ledOut = 7; // LED on Digital Pin 7
int aiValue = 0; // input value
int setPoint = 550; // Trigger value
int val = 0;
void setup()
{
pinMode(ledOut, OUTPUT); // Configure the Digital Pin Direction for the LED
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
Serial.begin(9600);
}
void loop() {
val = analogRead(1);
Serial.print(val);
Serial.println("");
// int dat = (125*val)>>8 ;
// Serial.print("Tep : ") ; //print “Tep” means temperature
//Serial.print(dat) ; // print the value of dat
//Serial.println(" C"); //print “C” means degree
aiValue = analogRead(photoIn); // Read the analogue input value
Serial.print(aiValue);
Serial.print("\n");
if (aiValue < setPoint)
{
digitalWrite(ledOut, HIGH); // It has got dark, turn the LED on.
digitalWrite(8, LOW); // It has got dark, turn the LED on.
//digitalWrite(9, HIGH); // It has got dark, turn the LED on.
}
else
{
digitalWrite(ledOut, LOW); // It is light again, turn the LED off.
digitalWrite(8, HIGH); // It has got dark, turn the LED on.
//digitalWrite(9, LOW);
}
delay(1000);
}