From: Tomas Mudrunka Date: Tue, 11 Feb 2014 01:09:33 +0000 (+0100) Subject: New arduino sketches X-Git-Url: https://git.harvie.cz/?a=commitdiff_plain;h=3a2579cc72c857ab1d2f69de776597e1118374f8;p=mirrors%2FPrograms.git New arduino sketches --- diff --git a/arduino/MeteoStenice/MeteoStenice.ino b/arduino/MeteoStenice/MeteoStenice.ino new file mode 100644 index 0000000..7c4a516 --- /dev/null +++ b/arduino/MeteoStenice/MeteoStenice.ino @@ -0,0 +1,48 @@ +#include "Wire.h" +#include "Adafruit_BMP085.h" + +#define EOL ";" + +Adafruit_BMP085 bmp; + +void setup() { + Serial.begin(9600); + bmp.begin(); +} + +void loop() { + Serial.print("label[temp]='Temperature'"EOL); + Serial.print("unit[temp]='*C'"EOL); + Serial.print("label[pressure]='Pressure'"EOL); + Serial.print("unit[pressure]='Pa'"EOL); + Serial.print("label[analog]='ADC'"EOL); + Serial.print("unit[analog]='Relative'"EOL); + + Serial.print("label[analog0]='ADC A0 (antenna?)'"EOL); + Serial.print("value[analog0]="); + Serial.print(analogRead(A0)); + Serial.print(EOL); + + Serial.print("label[analog1]='ADC A1 (coil?)'"EOL); + Serial.print("value[analog1]="); + Serial.print(analogRead(A1)); + Serial.print(EOL); + + Serial.print("label[analog2]='ADC A2 (phototransistor?)'"EOL); + Serial.print("value[analog2]="); + Serial.print(analogRead(A2)); + Serial.print(EOL); + + Serial.print("label[temp1]='BMP085 Temperature'"EOL); + Serial.print("value[temp1]="); + Serial.print(bmp.readTemperature()); + Serial.print(EOL); + + Serial.print("label[pressure1]='BMP085 Presure'"EOL); + Serial.print("value[pressure1]="); + Serial.print(bmp.readPressure()); + Serial.print(EOL); + + Serial.print("\n"); + delay(1000); +} diff --git a/arduino/MeteoStenice2/MeteoStenice2.ino b/arduino/MeteoStenice2/MeteoStenice2.ino new file mode 100644 index 0000000..6d5344b --- /dev/null +++ b/arduino/MeteoStenice2/MeteoStenice2.ino @@ -0,0 +1,100 @@ +#include "Wire.h" +#include "Adafruit_BMP085.h" +#include + +//#define EOL ";" + +Adafruit_BMP085 bmp; +dht DHT; +#define DHT11PIN 2 + +// delta max = 0.6544 wrt dewPoint() +// 5x faster than dewPoint() +// reference: http://en.wikipedia.org/wiki/Dew_point +double dewPointFast(double celsius, double humidity) +{ + double a = 17.271; + double b = 237.7; + double temp = (a * celsius) / (b + celsius) + log(humidity/100); + double Td = (b * temp) / (a - temp); + return Td; +} + +void setup() { + Serial.begin(9600); + bmp.begin(); + + Serial.println("\n"); +} + +void loop() { + int chk = DHT.read11(DHT11PIN); + if(chk != DHTLIB_OK) Serial.println("DHTLIB ERROR!"); + + Serial.print("{"); + Serial.print("\"config\":{"); + Serial.print("\"airquality\":{\"label\":\"Air Quality\",\"unit\":\"Relative\"},"); + Serial.print("\"temp\":{\"label\":\"Temperature\",\"unit\":\"°C\"},"); + Serial.print("\"pressure\":{\"label\":\"Pressure\",\"unit\":\"Pa\"},"); + Serial.print("\"humidity\":{\"label\":\"Humidity\",\"unit\":\"% RH\"},"); + Serial.print("\"analog\":{\"label\":\"ADC\",\"unit\":\"Relative\"}"); + Serial.print("},"); + Serial.print("\"data\":{"); + + Serial.print("\"airquality\":["); + + Serial.print("{\"label\":\"Air polution (MQ-2)\",\"value\":\""); + Serial.print(analogRead(A1)); + Serial.print("\"}"); + + Serial.print("],"); + + +/* + Serial.print("\"analog\":["); + + Serial.print("{\"label\":\"ADC A0 (antenna?)\",\"value\":\""); + Serial.print(analogRead(A0)); + Serial.print("\"}"); + + Serial.print(",{\"label\":\"ADC A2 (phototransistor?)\",\"value\":\""); + Serial.print(analogRead(A2)); + Serial.print("\"}"); + + Serial.print("],"); +*/ + + Serial.print("\"temp\":["); + + Serial.print("{\"label\":\"BMP085 Temperature\",\"value\":\""); + Serial.print(bmp.readTemperature()); + Serial.print("\"}"); + + Serial.print(",{\"label\":\"DHT11 Temperature\",\"value\":\""); + Serial.print((float)DHT.temperature); + Serial.print("\"}"); + + Serial.print("],"); + + + Serial.print("\"pressure\":["); + + Serial.print("{\"label\":\"BMP085 Pressure\",\"value\":\""); + Serial.print(bmp.readPressure()); + Serial.print("\"}"); + + Serial.print("],"); + + + Serial.print("\"humidity\":["); + + Serial.print("{\"label\":\"DHT11 Humidity\",\"value\":\""); + Serial.print((float)DHT.humidity); + Serial.print("\"}"); + + Serial.print("]"); + + Serial.print("}"); + Serial.print("}\n"); + delay(2000); +} diff --git a/arduino/UPSka/UPSka.ino b/arduino/UPSka/UPSka.ino new file mode 100644 index 0000000..ae44123 --- /dev/null +++ b/arduino/UPSka/UPSka.ino @@ -0,0 +1,27 @@ +int resetPin = 8; + + +void setup() { + Serial.begin(9600); + Serial.println("\n"); + + //Resetator test + + pinMode(resetPin, OUTPUT); + digitalWrite(resetPin, HIGH); + delay(100); + digitalWrite(resetPin, LOW); + +} + +void loop() { + + Serial.print("{"); + Serial.print("\"voltage\":\""); + Serial.print(map(analogRead(A7),0,1023,0,5000)/100.0); + //Serial.print(analogRead(A0)); + Serial.print("\""); + Serial.print("}\n"); + + delay(500); +}