ulvis.paste.net

Paste Search Dynamic
Recent pastes
light
  1. //Made by TEKNO
  2. const int sensor = A0; //The photoresistor is connected to A0.
  3. const int relay = 8; //The relay is connected to digital pin 8.
  4.  
  5. void setup() {
  6.   Serial.begin(9600);
  7.   pinMode(sensor,INPUT);
  8.   pinMode(relay,OUTPUT);
  9.   digitalWrite(relay,HIGH); //My relay is reversed so HIGH = Off , LOW = On. You should connect your extension cord's one cable (neutral for example) to the COM port of your relay and then put a cable between relay's NO port and the place where you have unplugged the neutral cable from.
  10. }
  11.  
  12. void loop() {
  13.  Serial.println("Sensor reads: " + String(analogRead(sensor)));
  14.  if(analogRead(sensor) > 100) { //Change 100 to your ideal number which you can get by testing.
  15.   digitalWrite(relay,HIGH);
  16.  } else {
  17.   digitalWrite(relay,LOW);
  18.  }
  19.  delay(500);
  20. }
  21. //Made by TEKNO
Parsed in 0.004 seconds