- List of parts:
Arduino Uno Board
Arduino Microphone similar to this one here
LCD Screen Compatible with Hitachi HD44780 driver
10 K Potentiometer
2 500 Ohm resistors
2 LEDs
A Breadboard
A large number of jumper cables - Assembly:
For the LCD refer to this guide it is not nesscary to use the last two pins on the LCD board
in wiring the LEDs go from the D9 port on the arduino, go through one of the 500 ohm resistors, connect to the positive end of the LED and connect the negative end to the GND on the arduino board
For the Microphone connect VCC to 3.3V on the arduino board, connect OUT to A0 and connect GND to GND - To operate the code you need to download the clock library from here, This is necessary to run the clock functions
- Code:
START CODE:
#include <LiquidCrystal.h> //LCD Library#include <Time.h> // The clock Library
#include <Wire.h> // Used in conjuction with the LCD library
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // setting up the LCD
int countertotal=0; //global variable
int timessetoff=0; //global variable
void setup() { //setup
Serial.begin(9600); //some more setup
pinMode(9,OUTPUT); //setting up the pins
pinMode(8,OUTPUT); //setting up the pins
lcd.begin(16, 2); //lcd number of rows and spaces
}
void loop() { //primary loop
time_t t=now(); //starting the clock
lcd.setCursor(0,1); //LCD position one on row one
lcd.print(hour(t)); //print the hours since it started
lcd.setCursor(3,1); //go to the m position
lcd.print(minute(t)); //print the minutes
lcd.setCursor(6,1); //go to the seconds position
lcd.print(second(t)); //print the seconds
int soundinput = 0; //for the mike
int counter = 0; // iterating increasing variable for counter
for (int timer0=0; timer0 < 5000; timer0++){ // the figure after the first semicolon "timer0 < #" the # is the timer counter, it does not actually count time but iterations of checking the counter function
soundinput = analogRead(A0); // for the mike
lcd.setCursor(0, 0); //set to first position first row
lcd.print(soundinput); //prints the current sound input
lcd.setCursor(5,0); //goes to next position
lcd.print(countertotal); //prints the total times that the counter has been set off
lcd.setCursor(8,0); //goes to the next position
lcd.print(timessetoff); //prints the number of times that the alarm has been activated
if (soundinput > 500){ //checks the sensor // the number here is the volume needed to trigger the counter
lcd.clear(); //clears the LCD screen
lcd.setCursor(0,1); //sets the cursor to the first position on the first row
lcd.print(counter); //prints the number of times the counter has been set off in the current trigger cycle
lcd.setCursor(6,1); //goes to the next position
lcd.print("Counting");//alerts the user that the trigger cycle is activated
timessetoff=timessetoff+1; //adds to the total counter
digitalWrite(9, HIGH); // turns on the LED
counter=counter+1; //adds to counter iterator
delay(100); // this is the delay between readings the number here is in milliseconds
digitalWrite(9, LOW); // turns off the LED
timer0=0;//resets the timer for this timer cycle
}
delay(1); //delay for stability
if (counter>10){ //how many times the counter function needs to trigger to turn on the "alert" led
lcd.clear(); //clears the LCD
lcd.print("ALARM"); //Prtints the alarm
digitalWrite(8, HIGH); // Turns on the LED
delay(10000); // how long the alert lasts
digitalWrite(8, LOW); // Turns off the LED
counter=0; //Resets the counter
timer0=5000; //resets the timer
countertotal=countertotal+1; //adds one to the total number of alarm set off
}
}
lcd.clear();
}
END CODE
5. Calibrations:
Calibrate the function by editing the number of times the counter needs to be set off and how long the timer should run, the timer is measured in number of iterations of the function rather than actual time elapsed so it can be freely edited without impacting the function.
To calibrate the microphone use a small screwdriver to adjust the screw on the back of the microphone. This changes the gain which can make it more or less sensitive to noises.
No comments:
Post a Comment