Hello, fellow Arduino developers!
I'm stuck on a slight problem with a project I'm working on at school right now. Basically what we are trying to do is simulate a "Thunderstorm"-cloud.
At the moment, the project is powered by the following components:
- Arduino UNO
- USB Power
- four single-colored LED
- Ai PIR Sensor from Adafruit
- A fuckton of wires
Basically, the issue at hand seems to be code based, as the wiring triggers everything as it is supposed to, it's just a matter of turning off the LEDs after they have completed their blink cycle.
Essentially, I want the Arduino to do the following:
-> If the PIR Sensor detects motion, run random blink cycle for x amount of seconds
-> Play a thunderstorm-sound from a bluetooth speaker, connected to the computer powering the Arduino
-> Else do nothing, wait for motion detection to run the code explained above
Here is a video demonstration of the sensor at work at this point in time, running with the code supplied in the post:
This is an imgur album of the current wiring to the board (slightly unclear photos, I can take new ones if it's necessary):
This is the source code from the project that I have been working with so far:
//LED variables, designating pin lights
int ledRed = 6;
int ledGreen = 8;
int ledYellow = 9;
int ledBlack = 13;
//Sensor variables
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
//Designate LED states
void setup() {
pinMode (ledRed, OUTPUT);
pinMode (ledGreen, OUTPUT);
pinMode (ledYellow, OUTPUT);
pinMode (ledBlack, OUTPUT);
Serial.begin(9600);
}
void loop() {
signal = digitalRead(inputPin); // read input value
if (signal == HIGH) { // Check if the input state is HIGH
if (pirState == HIGH) { // We have just turned it on
Serial.println("Motion");
pirState = LOW;
digitalWrite(ledRed, random(1));
digitalWrite(ledGreen, random(1));
digitalWrite(ledYellow, random(1));
digitalWrite(ledBlack, random(1));
delay(100);
} else {
Serial.println("No motion");
digitalWrite(ledRed, 0);
digitalWrite(ledGreen, 0);
digitalWrite(ledYellow, 0);
digitalWrite(ledBlack, 0);
pirState = HIGH;
}
}
}
Pastebin:
Any and all help is greatly appreciated! I seem to be really stumped with this one.
//@onordbo