Update 'SmartPowerDevice/lightsensitive controll/README.md'

This commit is contained in:
lolo 2022-05-16 11:21:16 +00:00
parent f2fddd9ca8
commit 5e636ce8c8
2 changed files with 43 additions and 8 deletions

View File

@ -1,8 +0,0 @@
## lightsensitive controll
### hardware
### software (arduino code)

View File

@ -0,0 +1,43 @@
## lightsensitive controll
### hardware
### software (arduino code)
// arduino-light-sensor-triggers-relay incl delay counter
// constants won't change
const int LIGHT_SENSOR_PIN = A0; // Arduino pin connected to light sensor's pin
const int RELAY_PIN = 3; // Arduino pin connected to Relay's pin
const int ANALOG_THRESHOLD = 450;
// variables will change:
int analogValue;
void setup() {
pinMode(RELAY_PIN, OUTPUT); // set arduino pin to output mode
Serial.begin(9600);
}
void loop() {
analogValue = analogRead(LIGHT_SENSOR_PIN); // read the input on analog pin
float voltage = analogValue * (5.0 / 1023.0);
Serial.println(analogValue);
int var = 0;
while (var < 5 && analogValue < ANALOG_THRESHOLD) {
delay(1000);
var++; }
if(var=5 && analogValue < ANALOG_THRESHOLD) {
digitalWrite(RELAY_PIN, LOW); } // turn off Relay
else {
digitalWrite(RELAY_PIN, HIGH);
var = 0;
}
}