Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int Pr = 0; // will be used for analog 0.
- int PrValue = 0; // value of output
- int Pr_Input = 100; // value of when light is on
- int Y = 0; // map PrValue into light value
- void setup() {
- Serial.begin(9600); //start serial Monitor
- pinMode(3, OUTPUT); // pin 3 as output
- }
- void loop() {
- PrValue = analogRead(Pr);
- Serial.println(PrValue); //prints photoresistor value
- delay(100); // value updated every 0.1 second.
- if (PrValue < Pr_Input) { // if sensor value is less than xx, light will turn on.
- Y = map(PrValue, 0, 300, 255, 0);
- analogWrite(3, Y);//LED on
- delay(15);
- }
- else {
- analogWrite(3, LOW); // LED off
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement