Grade 11 Computer Engineering Final
by 881148 in Circuits > Arduino
319 Views, 0 Favorites, 0 Comments
Grade 11 Computer Engineering Final
Step 1: Parts List
Parts list:
1x Arduino
1x Breadboard
6x Female to female wires
1x Lamp
1x Wire cuter
1x Relay
1x Sound Sensor
8x Jumper Wires
Step 2: Time for Code!!
int relayPin = 10; //Relay IN1 connected to pin 7
int micPin = 11; // Mic connected to pin 6 int micVal = HIGH; //HIGH is no sound, LOW is sound
boolean pwrToggle = true;
void setup () { Serial.begin(9600); pinMode(relayPin, OUTPUT); //Set pin for output digitalWrite(relayPin, HIGH); // HIGH is off, LOW is on pinMode (micPin, INPUT) ; //Set pin for input } void loop () { micVal = digitalRead (micPin) ; // Listen... if (micVal == LOW) // Hear something!!! { if (pwrToggle == true) { //relay off (true) Turn it on and display message in serial Monitor Serial.println ("Relay on"); digitalWrite(relayPin, LOW); pwrToggle = false; delay (500); } else { //relay on (true) Turn it off and display message in serial Monitor Serial.println ("Relay off"); digitalWrite(relayPin, HIGH); pwrToggle = true; delay (500); } } }