Posted By

estolada on 06/06/17


Tagged

arduino


Versions (?)

Arduino Sensors


 / Published in: C++
 

Error

  1. /*Cayenne
  2.  * Windows:
  3.  1. Open the Windows command line (cmd.exe)
  4.   2. cd C:\Users\ataca\Documents\Arduino\libraries\Cayenne\extras\scripts
  5.   tablet: cd C:\Users\Ata\Documents\Arduino\libraries\Cayenne\extras\scripts
  6.   3. Run the script by typing "cayenne-ser.bat -c COM4" (where COM4 is port with your Arduino) and hitting Enter
  7.  /cayenne-ser.sh -c dev/cu.usbmodem1431 -b 9600 -s arduino.mydevices.com -p 8442
  8.  */
  9.  
  10. /* HDC1080 ba?lant?lar
  11.  *
  12.   VDD 3.3V DC
  13.   SCL A5
  14.   SDA A4
  15.  *
  16.  */
  17.  
  18. //// kütüphaneler
  19. #include <ClosedCube_HDC1080.h> // Is? ve nem
  20. #include <Wire.h> // I2C
  21. #include <CayenneSerial.h>
  22. #include <LiquidCrystal.h>
  23. #include <Adafruit_Sensor.h>
  24. #include <SPI.h>
  25. #include <Adafruit_BMP280.h> // bas?nç
  26. //#include <Adafruit_GFX.h>
  27. //#include <Adafruit_PCD8544.h> // LCD
  28.  
  29.  
  30. char token[] = "AuthCode";
  31.  
  32.  
  33. //// tan?mlamalar
  34. int lcdSic,lcdNem,lcdCo2,lcdCo,lcdA,lcdDum;
  35.  
  36. int alkolAnalogPin = 12;
  37. float alkolDeger = 0;
  38.  
  39. int co2AnalogPin = 13;
  40. float co2deger = 0;
  41. float co2val,co2val1,co2val2,co2val3,co2vrl,co2ppm,co2ratio;
  42. float co2rs,co2ro=10000;
  43.  
  44. float coval,coval1,coval2,coval3;
  45. int coAnalogPin = 14;
  46.  
  47. float mq9volt,mq9sensorValue,mq9ppm,mq9sensorValue1,mq9sensorValue2,
  48. mq9sensorValue3,mq9Ro=10000,mq9RS,mq9ratio;
  49. int mq9AnalogPin = 11;
  50.  
  51. int suDeger;
  52.  
  53. ClosedCube_HDC1080 hdc1080;
  54. float nemDeger,sicaklikDeger;
  55.  
  56. // pin 16 - SCLK
  57. // pin 15 - DIN
  58. // pin 14 - D/C
  59. // pin 13 - CS
  60. // pin 12 - RST
  61. //Adafruit_PCD8544 display = Adafruit_PCD8544(4, 5, 6, 7, 8);
  62. #define SEALEVELPRESSURE_HPA (1013.25)
  63.  
  64. #define BMP_SCK 41 //scl
  65. #define BMP_MISO 39
  66. #define BMP_MOSI 37 // SDA
  67. #define BMP_CS 35
  68.  
  69. //Adafruit_BMP280 bmp;
  70. Adafruit_BMP280 bmp(BMP_CS, BMP_MOSI, BMP_MISO, BMP_SCK); // software SPI
  71. LiquidCrystal lcd(3,4,5,6,7,8);
  72.  
  73. /* LCD RS pin to digital pin 3
  74.  * LCD Enable pin to digital pin 4
  75.  * LCD D4 pin to digital pin 5
  76.  * LCD D5 pin to digital pin 6
  77.  * LCD D6 pin to digital pin 7
  78.  * LCD D7 pin to digital pin 8
  79.  * LCD R/W pin to ground
  80. */
  81. ///////////////////////////////////
  82.  
  83. void setup() {
  84.  
  85. pinMode(A0,OUTPUT);
  86. pinMode(A1,OUTPUT);
  87.  
  88. //Serial.begin(115200);
  89. hdc1080.begin(0x40); // 14bit ?s? ve nem, ?s?t?c? kapal?
  90. Cayenne.begin(token,115200);
  91. lcd.begin(16, 2);
  92. bmp.begin();
  93. }
  94.  
  95. void loop() {
  96.  
  97. /*
  98. lcd.setCursor(0,0);
  99. lcd.print("N:");
  100. lcd.setCursor(2,0);
  101. lcdNem = (int)nemOlcum();
  102. lcd.print(lcdNem);
  103.  
  104. lcd.setCursor(5,0);
  105. lcd.print("C:");
  106. lcd.setCursor(7,0);
  107. lcdSic = (int)sicaklikOlcum();
  108. lcd.print(lcdSic);
  109.  
  110. lcd.setCursor(10,0);
  111. lcd.print("P:");
  112. lcdCo= (int)basincOlcum();
  113. lcd.setCursor(12,0);
  114. lcd.print(lcdCo);
  115.  
  116.  
  117. lcd.setCursor(0,1);
  118. lcd.print("CO2:");
  119. lcdCo2= (int)CO2olcum();
  120. lcd.setCursor(4,1);
  121. lcd.print(lcdCo2);
  122.  
  123.  
  124.  
  125. lcd.setCursor(10,0);
  126. lcd.print("CO:");
  127. lcdCo= (int)COolcum();
  128. lcd.setCursor(14,0);
  129. lcd.print(lcdCo);
  130. delay(250);
  131. */
  132. /*
  133. lcd.setCursor(8,1);
  134. lcd.print("A:");
  135. lcdA= (int)alkolOlcum();
  136. lcd.setCursor(10,1);
  137. lcd.print(lcdA);
  138.  
  139.  
  140.  
  141. /*
  142. display.begin();
  143. display.setContrast(40);
  144. display.display();
  145. delay(2000);
  146. display.clearDisplay();
  147. display.drawPixel(10, 10, BLACK);
  148. display.display();
  149. delay(2000);
  150. display.setTextSize(1);
  151. display.setTextColor(BLACK);
  152. display.setCursor(0,0);
  153. display.println("Hello, world!");
  154. */
  155.  
  156. Cayenne.run();
  157.  
  158. }
  159.  
  160.  
  161.  
  162. ///HDC1080 ölçüm
  163. float basincOlcum()
  164. {
  165. float basinc;
  166. basinc= bmp.readPressure()/100.0F;
  167. return basinc;
  168. }
  169.  
  170.  
  171.  
  172. float sicaklikOlcum()
  173. {
  174. sicaklikDeger = hdc1080.readTemperature();
  175. return sicaklikDeger;
  176. }
  177. float nemOlcum()
  178. {
  179. nemDeger = hdc1080.readHumidity();
  180. return nemDeger;
  181. }
  182. ////
  183.  
  184.  
  185. //////MQ-3 ölçüm
  186.  
  187. int alkolOlcum()
  188. {
  189.  
  190. float mq3val,mq3val1,mq3val2,mq3val3;
  191.  
  192.  
  193. mq3val1 = analogRead(alkolAnalogPin);
  194. delay(50);
  195. mq3val2 = analogRead(alkolAnalogPin);
  196. delay(50);
  197. mq3val3 = analogRead(alkolAnalogPin);
  198.  
  199. mq3val = (mq3val1+mq3val2+mq3val3)/3;
  200. mq3val = mq3val;//*0.0097; // 0,05 - 9,95 mg/L
  201. return mq3val;
  202. }
  203. //////////
  204.  
  205. //////MQ-135 ölçüm
  206. float CO2olcum()
  207. {
  208.  
  209. co2val1 = analogRead(co2AnalogPin);
  210. delay(50);
  211. co2val2 = analogRead(co2AnalogPin);
  212. delay(50);
  213. co2val3 = analogRead(co2AnalogPin);
  214.  
  215. co2val = (co2val1+co2val2+co2val3)/3;
  216. co2vrl = 5*co2val/1024;
  217.  
  218. co2rs = 2500 * (5.0-co2vrl) / co2vrl;
  219. co2ratio = co2rs / co2ro;
  220. //co2ppm = 37143 * pow (co2ratio, -3.178);
  221. co2ppm = 141.34 * pow (co2ratio, 0.842);
  222. //Serial.println(ppm);
  223.  
  224. return co2ppm;
  225. }
  226.  
  227. //MQ135-2 olcum
  228. float COolcum()
  229. {
  230.  
  231. coval1 = analogRead(coAnalogPin);
  232. delay(50);
  233. coval2 = analogRead(coAnalogPin);
  234. delay(50);
  235. coval3 = analogRead(coAnalogPin);
  236.  
  237. coval = (coval1+coval2+coval3)/3;
  238.  
  239. return coval;
  240. }
  241. //////////////
  242.  
  243. //MQ9 Olcum
  244. float yaniciGazOlcum()
  245. {
  246. mq9sensorValue1 = analogRead(mq9AnalogPin);
  247. delay(50);
  248. mq9sensorValue2 = analogRead(mq9AnalogPin);
  249. delay(50);
  250. mq9sensorValue3 = analogRead(mq9AnalogPin);
  251. mq9sensorValue = (mq9sensorValue1+mq9sensorValue2+mq9sensorValue3)/3;
  252.  
  253.  
  254. mq9volt = mq9sensorValue/1024*5.0;
  255. mq9RS = 2000*(5.0-mq9volt)/mq9volt; // omit *RL
  256.  
  257. mq9ratio = mq9RS / mq9Ro;
  258. mq9ppm = 136.27 * pow (mq9ratio, -4.11);
  259. return mq9ppm;
  260. }
  261. /////////////////////
  262.  
  263. //Su Kontrol
  264. int suKontrol()
  265. {
  266. bool suVar=false;
  267. suDeger = analogRead(A8);
  268.  
  269. if(suDeger>600){
  270. digitalWrite(A0,HIGH);
  271. suVar = true;
  272. }
  273. else
  274. {
  275. digitalWrite(A0,LOW);
  276. suVar = false;
  277. }
  278.  
  279. return suDeger;
  280.  
  281. }
  282.  
  283.  
  284. ////CAYENNE GÖNDER?MLER
  285.  
  286. CAYENNE_OUT(V0)
  287. {
  288. delay(3000);
  289. Cayenne.virtualWrite(V0,sicaklikOlcum());
  290.  
  291. }
  292.  
  293. CAYENNE_OUT(V1)
  294. {
  295. delay(3000);
  296. Cayenne.virtualWrite(V1,nemOlcum());
  297.  
  298. }
  299. CAYENNE_OUT(V2)
  300. {
  301. delay(3000);
  302. Cayenne.virtualWrite(V2,alkolOlcum());
  303.  
  304. }
  305.  
  306. CAYENNE_OUT(V3)
  307. {
  308. delay(3000);
  309. Cayenne.virtualWrite(V3,CO2olcum());
  310.  
  311. }
  312. CAYENNE_OUT(V4)
  313. {
  314. delay(3000);
  315. Cayenne.virtualWrite(V4,COolcum());
  316.  
  317. }
  318.  
  319. CAYENNE_OUT(V5)
  320. {
  321. delay(3000);
  322. Cayenne.virtualWrite(V5,yaniciGazOlcum());
  323.  
  324. }
  325.  
  326.  
  327. CAYENNE_IN(V6)
  328. {
  329. delay(3000);
  330. bool havalandirma = false;
  331. if(havalandirma){
  332. havalandirma = false;
  333. digitalWrite(A1,LOW);
  334. }
  335. else{
  336. havalandirma = true;
  337. digitalWrite(A1,HIGH);
  338. }
  339.  
  340. }
  341. CAYENNE_OUT(V7)
  342. {
  343. delay(3000);
  344. Cayenne.virtualWrite(V7,basincOlcum());
  345.  
  346. }

Report this snippet  

You need to login to post a comment.