Hi,
I'm trying to make a light dependant switch for my garden.
I have written this code:
int sensorPin = 2; // select the input pin for LDR
int sensorValue = 0; // variable to store the value coming from the sensor
int relaisPin = 1;
int relaisValue = LOW;
void setup() {
pinMode(relaisPin, OUTPUT);
}
void loop() {
sensorValue = analogRead(sensorPin); // read the value from the sensor
if (sensorValue < 350) { // dark is a low value
delay(500);
if (sensorValue < 350 && relaisValue == LOW) {
relaisValue = HIGH;
digitalWrite(relaisPin, relaisValue);
}
}
if (sensorValue > 550) {
delay (500);
if (sensorValue > 550 && relaisValue == HIGH) {
relaisValue = LOW;
digitalWrite(relaisPin, relaisValue);
}
}
}
Using an Arduino Uno it is working. The output is used to switch a BC546 transistor that switches a TIP122 transistor which is used to switch a relay.
What am I doing wrong? I cannot find the mistake.
Please explain what you mean by "doesn't work" and give some evidence for the problem.
What board and core are you using for the ATtiny45?
Have you successfully uploaded any working program to the ATtiny?
I have it working now, I searched the internet for a good pinout for the ATtiny45 and found it.
I made some errors when declaring the pins. I have now expanded the code so the moments of engagement can be set using potmeters.
I use this to programm the chip
With this code.
int sensorPin = 1; // select the input pin for LDR
int relaisPin = 1;
int startPin = 2;
int endPin = 3;
int sensorValue = 0; // variable to store the value coming from the sensor
int relaisValue = LOW;
int startValue = 0;
int endValue = 0;
int s;
int e;
void setup() {
}
void loop() {
sensorValue = analogRead(1); // Read value from resistor
startValue = analogRead(2);
endValue = analogRead(3);
s = map (startValue, 0, 1023, 0, 500);
e = map (endValue, 0, 1023, 523, 1023);
if (sensorValue < s && relaisValue == LOW) { // dark is a low value
delay(180000);
if (sensorValue < s && relaisValue == LOW) {
relaisValue = HIGH;
digitalWrite(relaisPin, relaisValue);
}
}
if (sensorValue > e && relaisValue == HIGH) {
delay (180000);
if (sensorValue > e && relaisValue == HIGH) {
relaisValue = LOW;
digitalWrite(relaisPin, relaisValue);
}
}
}
I don't know what you mean by board and core, please explain.
Thanks,
Leo
I don't know what you mean by board and core, please explain.
The Arduino IDE uses different board and core definitions, for different Arduino boards and processors.
Are you not using the Arduino IDE?
Ah ok, I use the ATiny45 (internal 8MHz clock) board and Arduino as ISP when programming.
I'm using the Arduino IDE, 1.0 for programming the ATtiny chips and the latest version otherwise.