#include <Wire.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
#include <SoftwareSerial.h>
Adafruit_SSD1306 display(OLED_RESET);
SoftwareSerial BTserial(0,1);
int analogInput = A0;
int led1=8;
int led2=9;
int led3=10;
const int sampleWindow = 50;
unsigned int sample;
const int noise=A1;
void setup(){
BTserial.begin(9600);
Serial.begin(9600);
pinMode(analogInput, INPUT);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
}
void loop(){
unsigned long startMillis = millis();
unsigned int PeaktoPeak = 0;
unsigned int SignalMax = 0;
unsigned int SignalMin = 1024;
while ( millis() - startMillis < sampleWindow ){
sample = analogRead(analogInput);
if (sample < 1024) {
if (sample > SignalMax){
SignalMax = sample;
}
else if (sample < SignalMin){
SignalMin = sample;
}
}
}
PeaktoPeak = SignalMax - SignalMin;
float MeterValue = ( PeaktoPeak * 3.3 /675) * 10;
int change = map(MeterValue, 0, 1023, 0, 255);
analogWrite(noise, change);
Serial.println(MeterValue*10);
BTserial.println(MeterValue*10);
int a =MeterValue*10;
char temp_buff[5];
char temp_disp_buff[11] = "Sound:";
dtostrf(a,2,1,temp_buff);
strcat(temp_disp_buff,temp_buff);
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.println(temp_disp_buff);
display.display();
if(a < 30)
{
digitalWrite(led1,HIGH);
digitalWrite(led2,LOW);
digitalWrite(led3,LOW);
Serial.println("Sound is Low");
}
else if((a>30) && (a<=90))
{
digitalWrite(led1,LOW);
digitalWrite(led2,HIGH);
digitalWrite(led3,LOW);
Serial.println("Sound is Moderate");
}
else if(a>90)
{
digitalWrite(led1,LOW);
digitalWrite(led2,LOW);
digitalWrite(led3,HIGH);
Serial.println("Sound is High");
}
HI,
wireless Sound Meter
This is my sound sensor code. Function of my project is sense the sound value and convert analog to digital , after conversion i send the digital data of sound in dB to android via bluetooth HC-05 and OLED 0.96''. But i need to store sound data in specific location arduino like i want to use only my apk with arduino, Like i want specify where the sensor data available.
for example in Ruuvi sensor , there is multiple parameters are measured and transferred to android via Bluetooth. They specify each parameters in HEX address in both android and microcontroller like for temperature value -127c - 127c from 0x04 to 0x17, like the same i want to allocate specific loaction for my data 0dB to 128dB . PLEASE HEPL ME WITH YOUR IDEA