Hello everyone!
I am doing a programming project for school and we are using arduino. The idea is to build a circuit in which a srf05 sensor detects movement at a certain distance and makes the 12v rgb led strip light up. The thing is, I don't know how to program it to do that and would appreciate help
currently they both work at the same time but the sensor doesn't control the led
here's the code:
const int trigPin = 8;
const int echoPin = 7;
// defines variables
long duration;
int distance;
#define red 9
#define green 10
#define blue 11
int brightness;
int fadeAmount = 5;
void setup()
{
//SENSOR EMITTER AND RECEIVER
pinMode(8, OUTPUT); // Sets the trigPin as an Output
pinMode(7, INPUT); // Sets the echoPin as an Input
Serial.begin(9600); // Starts the serial communication
}
void loop() {
// Clears the trigPin
{
digitalWrite(8, LOW);
}
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(8, HIGH);
delayMicroseconds(10);
digitalWrite(8, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(7, HIGH);
// Calculating the distance
distance = duration * 0.034 / 2;
// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(distance);
//LED'S
analogWrite(green, brightness);
analogWrite(blue, brightness);
brightness += fadeAmount;
if (brightness <= 0 || brightness >= 255 )
{
fadeAmount = -fadeAmount;
}
delay(20);
}