Hello,
as I’m new to Arduino I’m having trouble with setting up 2 analog inputs to register.
I’m using 2 LDRs in my scheme, one is working perfectly, while the other one is always reading the same number, no matter what. I am following a tutorial to add new code lines, maybe I’ve made a mistake by adding wrong line or something.
Changing the input pin changes nothing. Tested my sensors, both of them are working fine, I just can’t get arduino to read both A0 and A1 correctly ( A0 always gives back good results, A1 repeats the same 15 value over and over again)
My code
//set pin numbers
//const won't change
const int ledPin = 13; //the number of the LED pin
const int ldrPin = A0; //the number of the LDR pin
const int sviesa = A1; //to read LDR 2
const int dayLight = 12; // daylight pin
const int headLight = 8; // headlights pin
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT); //initialize the LED pin as an output
pinMode(ldrPin, INPUT); //initialize the LDR pin as an input
pinMode(dayLight, OUTPUT); //
pinMode(headLight, OUTPUT); //
pinMode(sviesa, INPUT); //
}
void loop() {
delay(10);
int ldrStatus = analogRead(ldrPin); //read the status of the LDR value
delay(10);
int dayHead = analogRead(sviesa); // read LDR 2 value
delay(10);
//check if the LDR status is <= 300
//if it is, the LED is HIGH
if (dayHead >=300) {
digitalWrite(headLight, LOW);
digitalWrite(dayLight, HIGH);
Serial.println(sviesa);
delay(10);
}
else {
digitalWrite(dayLight, LOW);
digitalWrite(headLight, HIGH);
Serial.println(sviesa);
delay(10);
}
if (ldrStatus >=300) {
digitalWrite(ledPin, HIGH); //turn LED on
//Serial.println(ldrStatus);
delay(10);
}
else {
digitalWrite(ledPin, LOW); //turn LED off
//Serial.println(ldrStatus);
delay(10);
}
delay(1000);
}