Hello,
for a project I'm trying to let a speaker and a LED react on a LDR sensor. I want to let them react after a certain amount of time, which can be set with a 10K Ohm potentiometer.
However, I don't know how to set the values for the potentiometer.
I want to be able to set the delay form 0 to about 6 seconds. At this moment it can be set from about 0 to 2.0 seconds.
Does anybody knows how to change it?
Can it be changed by setting the values in the code, or do I need another potentiometer?
This is de code i'm using:
#define INPIN 0 // pin used for input (analog)
#define LEDPIN 2 // pin used for output to LED
int ldr = 0; //analog pin to which LDR is connected
int ldr_value = 0; //variable to store LDR values
int ledStatus = 0; // LED status (0 = low, 1 = high)
int inVal = 0; // variable used to store state of input
int switchOn = 600; // value at which we switch LED on
int switchOff = 800; // value at which we switch LED off
int sensorPin = A1; //input potentiometer
int sensorValue = 0;
void setup ()
{{
Serial.begin(9600); //start te serial monitor
}
{ pinMode (9, OUTPUT); // set pin for output (Piezo)
pinMode (LEDPIN, OUTPUT); // Set pin for output(LED)
digitalWrite (LEDPIN, LOW); // Turn LED off
}}
void loop ()
{
{sensorValue = analogRead(sensorPin);}
{
ldr_value = analogRead(ldr); //reads the LDR values
Serial.println(ldr_value); //prints the LDR values to serial monitor
delay(50); //wait
}
{
inVal = analogRead(INPIN); // Read state of the input pin
if (ledStatus == 0 && inVal >= switchOff)
{
ledStatus = 1; //LED on
delay(sensorValue); //(wait
digitalWrite (LEDPIN, ledStatus);
analogWrite(9,20); //speaker on
}
else if (ledStatus == 1 && inVal <= switchOn)
{
ledStatus = 0; //LED off
digitalWrite (LEDPIN, ledStatus);
analogWrite(9,0); // Speaker off
}
}}
Thanks