Advertisement
ccarman602

Lesson-5-Light

Nov 25th, 2021 (edited)
750
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Light Switch
  2. int sensorpin = A6; // Analog input pin that the sensor is attached to
  3. int ledPin = 4;    // LED port
  4. int sensorValue = 0;        // value read from the port
  5. int outputValue = 0;        // value output to the PWM (analog out)
  6.  
  7. void setup() {
  8.   pinMode(ledPin,OUTPUT);
  9.   pinMode(sensorpin, INPUT);
  10.   Serial.begin(9600);
  11. }
  12.  
  13. void loop() {
  14.   // read the analog in value:
  15.   sensorValue = analogRead(sensorpin);
  16.  
  17.   Serial.println(sensorValue);
  18.  
  19.   if (sensorValue < 200) {
  20.     digitalWrite(ledPin, LOW);
  21.   }
  22.   else {
  23.     digitalWrite(ledPin, HIGH);
  24.   }
  25.  
  26.   delay(200);
  27. }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement