Skip to content

Commit

Permalink
Merge pull request #13 from dwyl/init
Browse files Browse the repository at this point in the history
#12 monitoring decibels and notifying user
  • Loading branch information
nelsonic authored Nov 17, 2017
2 parents db6024e + e021acb commit 3113ded
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
DS_Store
29 changes: 28 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,29 @@
# iot-decibel-meter
A decibel meter built with a raspberry pi
A decibel meter built with johnny-five

The eventual aim is to get the decibel meter running just on the raspberry pi. However as we are newbies and did not want to have to solder on an ADC converter, we have started off using an arduino and running the johnny-five script on the raspberry pi.

## You will need:
- a positive mental attitude :heart: :smile: :heart:
- a laptop or a raspberry pi :cake: with node installed
- an arduino
- a sparkfun sound detector (with envelope readings)
- a breadboard :bread:
- some male-male wires :boy: :boy:
- USB A to B cable

#### Optional:
- an 8 x 8 Matrix (we have MAX7219)
- LCD screen (we have the LCD 1602 module) and potentiometer (10k)

## Steps
- Clone the repository
- ```npm install```
- Hook up the sparkfun sound detector. Follow instructions [here](https://learn.sparkfun.com/tutorials/sound-detector-hookup-guide?_ga=2.42092133.1361593521.1505302503-234789299.1505302503#introducing-the-sound-detector)
On our setup, we have connected the envelope output to A1 and gate output to digital 3 (as well as 5V VCC and gnd). We have left the audio output disconnected because we do not need to use it.

- Connect your matrix. Our output pins are data: 6, clock: 4, cs: 5. Please see hook up instructions [here](http://johnny-five.io/examples/led-matrix)
- Connect LCD screen. We use pins: [7, 8, 9, 10, 11, 12]. Please see hook up instructions [here](http://johnny-five.io/examples/lcd/)
- Run ```sudo node sound.js```

You should now see the decibels (roughly) on the lcd screen and the matrix should switch between a :smile: and :disappointed: depending on the volume
30 changes: 30 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "iot-decibel-meter",
"version": "1.0.0",
"description": "A decibel meter built with a raspberry pi",
"main": "sound.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/dwyl/iot-decibel-meter.git"
},
"keywords": [
"iot",
"decibel",
"johnny-five",
"dwyl",
"arduino",
"pi"
],
"author": "naazy",
"license": "ISC",
"bugs": {
"url": "https://github.com/dwyl/iot-decibel-meter/issues"
},
"homepage": "https://github.com/dwyl/iot-decibel-meter#readme",
"dependencies": {
"johnny-five": "^0.11.7"
}
}
84 changes: 84 additions & 0 deletions sound.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
var five = require("johnny-five"), board, lcd;

var analog = "A1"
// var digital = "2";

new five.Board().on("ready", function() {

var heart = [
"01100110",
"10011001",
"10000001",
"10000001",
"01000010",
"00100100",
"00011000",
"00000000"
];

var smile = [
"00000000",
"00100100",
"00000000",
"00000000",
"10000001",
"01000010",
"00111100",
"00000000"]

var sad = [
"00000000",
"00100100",
"00000000",
"00000000",
"00000000",
"00111100",
"01000010",
"10000001"
]

var matrix = new five.Led.Matrix({
pins: {
data: 6,
clock: 4,
cs: 5
}
});

var ledRed = new five.Led(0);
var ledYellow = new five.Led(1);
var ledGreen = new five.Led(2)

var lcd = new five.LCD({
// LCD pin name RS EN DB4 DB5 DB6 DB7
// Arduino pin # 7 8 9 10 11 12
pins: [7, 8, 9, 10, 11, 12],
backlight: 2,
rows: 2,
cols: 20
});

// // Tell the LCD you will use these characters:
lcd.useChar("heart");

var analogSensor = new five.Sensor({pin:analog,
freq: 500
});


analogSensor.on("data", function() {
// this formula may need work but was inspired by https://forum.arduino.cc/index.php?topic=376308.0
var decibels = Math.round(40 + (20 * Math.log10(this.value/40)));
console.log('decibels', decibels);
if(decibels > 60){
matrix.draw(sad);
lcd.clear().cursor(0, 0).print(decibels + " Too loud :(");

} else {
matrix.draw(smile);
lcd.clear().print(decibels + " :heart:");

}
});

});

0 comments on commit 3113ded

Please sign in to comment.