int inPin = 0; // use Pin 0 to read value of analog input from microphone int value; // value of analog input boolean blinkState = false; // store the state of the LED, whether it is blinking or not unsigned long blinkTimer = 0; // create a timer for measuring the duration of blinking void setup(){ /* The orders will be sent to arduino B through serial communication. The commands 't', 'y', 'h' are defined in the code of arduino B. */ Serial.begin(9600); Serial.println('t'); // turn on the blue LED representing Night Serial.println('y'); // turn on the white LED representing Presence } void loop(){ value = analogRead(inPin); // Read value from Analog In Pin 0 /* Since the microphone generates AC, we tried to make use of values that around peak and trough. */ if (value < 400 || value > 600){ if (blinkState == false){ Serial.print('h'); blinkTimer = millis() + 8000; // the blink lasts 8 seconds. blinkState = true; } } if (blinkState == true){ if(millis() > blinkTimer){ Serial.print('y'); blinkState = false; } } }