/*
TWSendRawSound
Beschreibung: Dieses Programm liesst die Daten von dem Soundsensor analog ein und sendet Signale per WiFi.
Folgende Verbindungen sind noetig:
Arduino Nano: A3 auf PIN 2 OUT
+5v auf PIN 3 +5 Volt
GND auf PIN 1 GND
Serielle Konsole auf 9600 Baud stellen.
Compile mit Arduino 1.6.2 IDE. Einstellung: Board Arduino Nano
Copyright (C) 2015 Thomas Wenzlaff http://www.wenzlaff.de
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
#include <VirtualWire.h>
// Baud Rate zum Host PC, evl. aendern
const long BAUD_RATE = 9600L;
// Baud Rate zum Virtual Wirer
const int BAUD_VIRTUAL_WIRE = 2000;
// PIND zu Virtual Wire
const int VIRTUAL_WIRE_PIN = 12;
// SOUND Sensor an analog Pin 3
const int SOUND_SENSOR_PIN = 3;
void sendString(String message, bool wait)
{
byte messageLength = message.length() + 1;
// convert string to char array
char charBuffer[messageLength];
message.toCharArray(charBuffer, messageLength);
vw_send((uint8_t *)charBuffer, messageLength);
if (wait) vw_wait_tx();
}
void setup() {
Serial.begin(BAUD_RATE);
Serial.println("Starte TWSendRawSound V. 1.0 von wenzlaff.info");
pinMode(SOUND_SENSOR_PIN, INPUT);
vw_set_tx_pin(VIRTUAL_WIRE_PIN);
vw_setup(BAUD_VIRTUAL_WIRE);
}
void loop() {
// analog
int sensorDaten = analogRead(SOUND_SENSOR_PIN);
// digital würde auch gehen mit
// int sensorDaten =digitalRead(soundSensor);
// dann aber den digitalen Pin auf der anderen Seite des Nano verwenden
if (sensorDaten <= 1000){ //rausche verhindern
// ueber WIFI senden
String data = String(sensorDaten, DEC);
sendString(data, true);
}
}