Hello guys and girls I hope everything is fine with you!
I'm working on a project which includes a Arduino UNO, PIR-sensor, wave shield and led lights.
Essentially we are making a thunderous cloud, so when the PIR-sensor register your presens we want the led lights to start simulating a thunder and sound to start.
But first of all we need to make the sensor work with the LED lights.
I've made the sensor work (yay!) and the LED lights blinking randomly (x2 yay!) but how in the name of Belzebub do I combine the scripts under one event?
So how do I make the LED lights blink randomly when someone walks infront of the PIR-sensor?
So time for some code:
PIR-sensor:
int ledPin = 13; // choose the pin for the light
int inputPin = 2; // choose the input pin (for PIR sensor)
int pirState = LOW; // we start, assuming no motion detected
int signal = 0; // variable for reading the pin status
void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare sensor as input
Serial.begin(9600);
}
void loop(){
signal = digitalRead(inputPin); // read input value
if (signal == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, HIGH); // turn light ON
if (pirState == LOW) { // we have just turned on
Serial.println("Active");
// We only want to print on the output change, not state
pirState = HIGH;
}
} else {
digitalWrite(ledPin, LOW); // turn light OFF
if (pirState == HIGH){
// we have just turned of
Serial.println("Inactive");
// We only want to print on the output change, not state
pirState = LOW;
}
}
}
LED lights that blinks randomly:
int ledRed = 6;
int ledGreen = 8;
int ledYellow = 9;
int ledBlack = 13;
void setup() {
pinMode (ledRed, OUTPUT);
pinMode (ledGreen, OUTPUT);
pinMode (ledYellow, OUTPUT);
pinMode (ledBlack, OUTPUT);
}
void loop() {
digitalWrite(ledRed, random(2));
digitalWrite(ledGreen, random(2));
digitalWrite(ledYellow, random(2));
digitalWrite(ledBlack, random(2));
delay(100);
}
I'm super stuck. It would be awesome if someone could sacrifice some time and help me.
Thank you in advance.
/Noob Neo