0% found this document useful (0 votes)
23 views2 pages

Code 2

Uploaded by

Jonathan Bukenya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views2 pages

Code 2

Uploaded by

Jonathan Bukenya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

int LedPin =13;// pin 13 is the ledpin

int SoundPin = A0;// pin A0 is the input pin

int threshold;// input value by the user

int ReadVal;// will store analog signals from the mic

float Val;// stores coversion between input and output signals

int delayT = 500;// delay time is

String sent1 = "Enter the threshold sound in dbs";

String sent2 = " The threshold value is:";

void setup()

Serial.begin (9600);// begins the serial monitor at a baud rate of 9600

pinMode(LedPin, OUTPUT);// setting the pin 13 as the output

pinMode(SoundPin, INPUT);// setting pin A0 as the input

void loop()

Serial.println(sent1);// prints string stored in sent1

while(Serial.available()== 0) {} // serial monitar waits until it receives an input from the user

ReadVal = analogRead(SoundPin);// arduino receives analog data from the mic


Val = (255./1023.)*ReadVal;//

threshold = Serial.parseInt();// stores the threshold entered by the user and returns it to the serial port.

Serial.println(sent2);

Serial.println(threshold);// prints the threshold value entered on a new line.

if(Val > threshold)// conditional statement

digitalWrite(LedPin, HIGH);// makes the led light when Val exceeds threshold

delay (delayT);// the led delays for half a second

else

digitalWrite(LedPin, LOW);// if the condition is wrong, the led will go off

delay(delayT);//

You might also like