Skip to content

Instantly share code, notes, and snippets.

Created March 16, 2017 23:48
Show Gist options
  • Save anonymous/2219e935c5fe5f6bbbacdea46f65474e to your computer and use it in GitHub Desktop.
Save anonymous/2219e935c5fe5f6bbbacdea46f65474e to your computer and use it in GitHub Desktop.
This code runs the motions sensor and RGB LEDs so that the lights are blue when no motion. When motion is detected the LEDs will flash green and it will send the signal to the other arduino to play a coin sound.
int pirPin = 10;
int redLED = A4;
int greenLED = A2;
int blueLED = A3;
int coinSound= 7;
void setup() {
Serial.begin(9600);
pinMode(pirPin, INPUT);
pinMode(redLED, OUTPUT);
pinMode(greenLED, OUTPUT);
pinMode(blueLED, OUTPUT);
pinMode(coinSound, OUTPUT);
}
void loop() {
int pirVal = digitalRead(pirPin);
if(pirVal == LOW) {
Serial.println("Motion Detected");
//delay(1500);
analogWrite(blueLED, 0);
analogWrite(greenLED, 1023);
delay(1500);
digitalWrite(coinSound, HIGH);
}
else {
Serial.println("None");
analogWrite(greenLED, 0);
analogWrite(blueLED, 1023);
//analogWrite(blueLED, 0);
digitalWrite(coinSound,LOW);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment