Professional Documents
Culture Documents
Experiment No.3
Photoresistor application
Aim- To develop street light based on photoresistors.
Application of photoresistor
1. Street Light
LED is on
60001170042 Prasad Mohite BE Elex
LED is off
Code-
// variables:
int sensorValue = 0; // the sensor value
int sensorMin = 1023; // minimum sensor value
int sensorMax = 0; // maximum sensor value
void setup() {
pinMode(9, OUTPUT);
digitalWrite(9, HIGH);
}
void loop() {
if (sensorValue > sensorMax) {
sensorMax = sensorValue;
}
if (sensorValue < sensorMin) {
sensorMin = sensorValue;
}
}
digitalWrite(9, LOW);
}
sensorValue = analogRead(sensorPin);
sensorValue = map(sensorValue, sensorMin, sensorMax, 0, 255);
sensorValue = constrain(sensorValue, 0, 255);
analogWrite(ledPin, sensorValue);
}
60001170042 Prasad Mohite BE Elex
3. Tone pitch
Code
int sensorReading = 0;
void setup()
{
pinMode(A0, INPUT);
Serial.begin(9600);
60001170042 Prasad Mohite BE Elex
pinMode(9, OUTPUT);
}
void loop()
{
sensorReading = analogRead(A0);
Serial.println(sensorReading);
tone(9, 440 * pow(2.0, (constrain(int(map(sensorReading, 0, 1023, 36, 84)), 35, 127) - 57) / 12.0),
1000);
delay(10);
}
Conclusion- Thus we have studied the working of photoresistors. Also for different applications
circuits like street light, speed control of dc motor, tone pitch variation we have simulated the
result.