{"id":766,"date":"2016-05-19T12:09:08","date_gmt":"2016-05-19T06:39:08","guid":{"rendered":"http:\/\/artscienceblr.org\/?p=766"},"modified":"2016-05-21T20:20:51","modified_gmt":"2016-05-21T14:50:51","slug":"songs-of-the-swamp","status":"publish","type":"post","link":"https:\/\/artscienceblr.org\/index.php\/songs-of-the-swamp\/","title":{"rendered":"Songs of the Swamp"},"content":{"rendered":"<p>This summer we worked with <a href=\"http:\/\/www.theisro.org\" target=\"_blank\">The Indian Sonic Research Organisation<\/a> and the <a href=\"http:\/\/earthcolab.com\/\">Earth Co.Lab<\/a> . Earth Co Lab is developing a Swamp Song machine using environmental sensors. Swamp songs is <span style=\"color: #676767;\">a pedagogical experiment with electronics, sound, and ecology \u2013 It uses physical computing tools to develop ecological sensors in an effort to rethink how we perceive ecological data. <\/span><\/p>\n<p><a href=\"http:\/\/artscienceblr.org\/wp-content\/uploads\/2016\/05\/IMG_20160427_075248.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-778\" src=\"http:\/\/artscienceblr.org\/wp-content\/uploads\/2016\/05\/IMG_20160427_075248.jpg\" alt=\"IMG_20160427_075248\" width=\"1564\" height=\"1564\" srcset=\"https:\/\/artscienceblr.org\/wp-content\/uploads\/2016\/05\/IMG_20160427_075248.jpg 1564w, https:\/\/artscienceblr.org\/wp-content\/uploads\/2016\/05\/IMG_20160427_075248-150x150.jpg 150w, https:\/\/artscienceblr.org\/wp-content\/uploads\/2016\/05\/IMG_20160427_075248-300x300.jpg 300w, https:\/\/artscienceblr.org\/wp-content\/uploads\/2016\/05\/IMG_20160427_075248-1024x1024.jpg 1024w\" sizes=\"auto, (max-width: 1564px) 100vw, 1564px\" \/><\/a><br \/>\nThe machine was based on the Arduino nano which is connected to a nano sensors shield and that is connected to a data logger. The data logger we used was a clone of the <a href=\"https:\/\/www.adafruit.com\/product\/1141\">adafruit data logger<\/a>. The sensors shield was an expansion board which gave +5V and GND to each analog and digital input\/output. It also interfaces with the UNO\/Datalogger as a shield.<\/p>\n<p><a href=\"http:\/\/artscienceblr.org\/wp-content\/uploads\/2016\/05\/nano-sensors-shield.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft wp-image-779 size-full\" src=\"http:\/\/artscienceblr.org\/wp-content\/uploads\/2016\/05\/nano-sensors-shield.jpg\" alt=\"nano sensors shield\" width=\"800\" height=\"800\" srcset=\"https:\/\/artscienceblr.org\/wp-content\/uploads\/2016\/05\/nano-sensors-shield.jpg 800w, https:\/\/artscienceblr.org\/wp-content\/uploads\/2016\/05\/nano-sensors-shield-150x150.jpg 150w, https:\/\/artscienceblr.org\/wp-content\/uploads\/2016\/05\/nano-sensors-shield-300x300.jpg 300w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>The machine measures pH, salinity, temperature, methane, moisture\/humidity, turbidity and distance.<\/p>\n<p>1) pH &#8211; The pH measurements are still being experimented with. We used a <a href=\"https:\/\/progressive-growth.com\/wp-content\/uploads\/2015\/03\/phprobe-1024x768.jpg\">pH probe with the BNC connector <\/a> and an FET transistor (2n4393\/pn4393) to amplify the signal. This was connected to A0 of the sensors shield (nano).<\/p>\n<p><a href=\"http:\/\/artscienceblr.org\/wp-content\/uploads\/2016\/05\/fet-ph-probe-connections.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-792\" src=\"http:\/\/artscienceblr.org\/wp-content\/uploads\/2016\/05\/fet-ph-probe-connections.jpg\" alt=\"fet ph probe connections\" width=\"1500\" height=\"1125\" srcset=\"https:\/\/artscienceblr.org\/wp-content\/uploads\/2016\/05\/fet-ph-probe-connections.jpg 1500w, https:\/\/artscienceblr.org\/wp-content\/uploads\/2016\/05\/fet-ph-probe-connections-300x225.jpg 300w, https:\/\/artscienceblr.org\/wp-content\/uploads\/2016\/05\/fet-ph-probe-connections-1024x768.jpg 1024w\" sizes=\"auto, (max-width: 1500px) 100vw, 1500px\" \/><\/a><\/p>\n<p>The signal from the central pin of the BNC goes to the FET and the shielding goes to common ground. The pin-outs might change if you use a different FET transistor, so just check the datasheet before connecting.<\/p>\n<p>&nbsp;<\/p>\n<p>2) Turbidity &#8211; We made our own turbidity sensor using a LASER diode and a LDR. A great resource for DIY turbidity meters can be found<a href=\"http:\/\/hackteria.org\/wiki\/DIY_turbidity_meters\"> here<\/a>. We used a black PVC pipe, slightly bigger than the diameter of a test tube as the housing to ensure darkness. The LDR was placed inside the pipe and a hole drilled opposite to the face of the LDR to allow the laser beam to enter. The wiring is really simple- 33k resistor between +5v to A1, LDR between A1 and GND.<\/p>\n<p><a href=\"http:\/\/artscienceblr.org\/wp-content\/uploads\/2016\/05\/IMG_20160401_105401.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-785\" src=\"http:\/\/artscienceblr.org\/wp-content\/uploads\/2016\/05\/IMG_20160401_105401.jpg\" alt=\"IMG_20160401_105401\" width=\"1500\" height=\"1500\" srcset=\"https:\/\/artscienceblr.org\/wp-content\/uploads\/2016\/05\/IMG_20160401_105401.jpg 1500w, https:\/\/artscienceblr.org\/wp-content\/uploads\/2016\/05\/IMG_20160401_105401-150x150.jpg 150w, https:\/\/artscienceblr.org\/wp-content\/uploads\/2016\/05\/IMG_20160401_105401-300x300.jpg 300w, https:\/\/artscienceblr.org\/wp-content\/uploads\/2016\/05\/IMG_20160401_105401-1024x1024.jpg 1024w\" sizes=\"auto, (max-width: 1500px) 100vw, 1500px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>We used the following code &#8211;<\/p>\n<pre style=\"color: black;\">#define turbidityPin A1\r\nint sensorValue = 0;\r\nint outputValue = 0; \/\/ variable for value in percentage\r\n\r\nvoid setup() {\r\n\/\/ initialize serial communication at 9600 bits per second:\r\nSerial.begin(9600);\r\n}\r\n\r\nvoid loop() {\r\n\/\/ read the input on analog pin 1:\r\nsensorValue = analogRead(turbidityPin);\r\noutputValue = map(sensorValue,0,673, 0, 100); \/\/ replace 673 with the sensor value when something opaque is inserted \r\n\/\/Incase the reading is inversely related,use map as - map(sensorValue,0,673, 100, 0)<\/pre>\n<pre style=\"color: black;\">\/\/ print out the value you read: \r\nSerial.print(\"SensorReading =\"); \r\nSerial.println(sensorValue); \r\nSerial.print(\"\\t % turbidity = \"); \r\nSerial.println(outputValue); \r\ndelay(1000); \/\/ delay in between reads for stability }<\/pre>\n<p>&nbsp;<\/p>\n<p>3) Methane &#8211; Methane is measured using the <a href=\"https:\/\/www.sparkfun.com\/products\/9404\">MQ4 gas sensor.<\/a> It is better to power the methane sensor with a separate power supply as it&#8217;s heating element consumes more energy and the other sensors get effected. This is connected to A2 <a href=\"http:\/\/playground.arduino.cc\/Main\/MQGasSensors\">( wiring diagram)<\/a>. To get the readings, upload the following code to the arduino.<\/p>\n<pre style=\"color: black;\">int sensorValue;\r\nvoid setup()\r\n{\r\n Serial.begin(9600);      \/\/ sets the serial port to 9600\r\n}\r\nvoid loop()\r\n{\r\n sensorValue = analogRead(2);       \/\/ read analog input pin 0\r\n Serial.println(sensorValue, DEC);  \/\/ prints the value read\r\n delay(100);                        \/\/ wait 100ms for next reading\r\n}<\/pre>\n<p>The above reading that we get gives us a general trend but doesn&#8217;t correspond to the actual ppm concentration. We modified a sketch that <a href=\"http:\/\/sandboxelectronics.com\/?p=165\">we found for the MQ2 general purpose sensor<\/a> with data found on the <a href=\"https:\/\/www.sparkfun.com\/datasheets\/Sensors\/Biometric\/MQ-4.pdf\">MQ4 datasheet<\/a> to get the concentration of methane in ppm.<\/p>\n<pre style=\"color: black;\">#define gasPin A2\r\n#define RL_VALUE (5) \/\/define the load resistance on the board, in kilo ohms\r\n#define RO_CLEAN_AIR_FACTOR (4.5) \/\/RO_CLEAR_AIR_FACTOR=(Sensor resistance in clean air)\/RO,\r\n\r\n#define CALIBARAION_SAMPLE_TIMES (50) \/\/define how many samples you are going to take in the calibration phase\r\n#define CALIBRATION_SAMPLE_INTERVAL (500) \/\/define the time interal(in milisecond) between each samples in the\r\n\/\/cablibration phase\r\n#define READ_SAMPLE_INTERVAL (50) \/\/define how many samples you are going to take in normal operation\r\n#define READ_SAMPLE_TIMES (5) \/\/define the time interal(in milisecond) between each samples in\r\n\r\n\/\/normal operation\/\/which is derived from the chart in datasheet\r\n#define gas_CH4 (0)\r\n\r\nfloat CH4Curve[3] = {2.3,0.45,-1.04};\r\n\r\nfloat Ro = 4.5;\r\n\r\nvoid setup() {\r\nSerial.begin(9600); \/\/UART setup, baudrate = 9600bps\r\n}\r\n\r\nvoid loop() {\r\nSerial.print(\"Methane:\");\r\nSerial.print(MQGetGasPercentage(MQRead(gasPin)\/Ro,gas_CH4) );\r\nSerial.print( \"ppm\" );\r\nSerial.println(\" \");\r\ndelay(200);\r\n}\r\n\r\nfloat MQResistanceCalculation(int raw_adc)\r\n{\r\nreturn ( ((float)RL_VALUE*(1023-raw_adc)\/raw_adc));\r\n}\r\n\r\nfloat MQCalibration(int gasPin)\r\n{\r\nint i;\r\nfloat val=0;\r\n\r\nfor (i=0;i&lt;CALIBARAION_SAMPLE_TIMES;i++) { \/\/take multiple samples\r\nval += MQResistanceCalculation(analogRead(gasPin));\r\ndelay(CALIBRATION_SAMPLE_INTERVAL);\r\n}\r\nval = val\/CALIBARAION_SAMPLE_TIMES; \/\/calculate the average value\r\n\r\nval = val\/RO_CLEAN_AIR_FACTOR; \/\/divided by RO_CLEAN_AIR_FACTOR yields the Ro\r\n\/\/according to the chart in the datasheet\r\n\r\nreturn val;\r\n}\r\n\r\nfloat MQRead(int mq_pin)\r\n{\r\nint i;\r\nfloat rs=0;\r\n\r\nfor (i=0;i&lt;READ_SAMPLE_TIMES;i++) {\r\nrs += MQResistanceCalculation(analogRead(mq_pin));\r\ndelay(READ_SAMPLE_INTERVAL);\r\n}\r\nrs = rs\/READ_SAMPLE_TIMES;\r\nreturn rs;\r\n}\r\n\r\nint MQGetGasPercentage(float rs_ro_ratio, int gas_id)\r\n{\r\nif ( gas_id == gas_CH4 ) {\r\nreturn MQGetPercentage(rs_ro_ratio,CH4Curve);\r\n}\r\n\r\nreturn 0;\r\n}\r\nint MQGetPercentage(float rs_ro_ratio, float *pcurve)\r\n{\r\nreturn (pow(4.5,( ((log(rs_ro_ratio)-pcurve[1])\/pcurve[2]) + pcurve[0])));\r\n} \r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>4) Salinity &#8211; For measuring salinity, we initially built our own sensor. It is connected to A3 of the nano.<\/p>\n<p><a href=\"http:\/\/artscienceblr.org\/wp-content\/uploads\/2016\/05\/IMG_20160401_170754.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-786\" src=\"http:\/\/artscienceblr.org\/wp-content\/uploads\/2016\/05\/IMG_20160401_170754.jpg\" alt=\"salinity sensor\" width=\"1500\" height=\"1271\" srcset=\"https:\/\/artscienceblr.org\/wp-content\/uploads\/2016\/05\/IMG_20160401_170754.jpg 1500w, https:\/\/artscienceblr.org\/wp-content\/uploads\/2016\/05\/IMG_20160401_170754-300x254.jpg 300w, https:\/\/artscienceblr.org\/wp-content\/uploads\/2016\/05\/IMG_20160401_170754-1024x867.jpg 1024w\" sizes=\"auto, (max-width: 1500px) 100vw, 1500px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>The sensor was built by placing two graphite electrodes (taken from the mechanical pencil) 1cm apart. A 1k resistor was used to form a potential divider and the sensor connected to the Arduino. The graphite electrode was quite fragile and broke often. It was replaced by a water level sensor repurposed to be used as the salinity sensor.<\/p>\n<p><a href=\"http:\/\/artscienceblr.org\/wp-content\/uploads\/2016\/05\/Water_Level_Sensor_2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-787\" src=\"http:\/\/artscienceblr.org\/wp-content\/uploads\/2016\/05\/Water_Level_Sensor_2.jpg\" alt=\"Water_Level_Sensor_2\" width=\"800\" height=\"600\" srcset=\"https:\/\/artscienceblr.org\/wp-content\/uploads\/2016\/05\/Water_Level_Sensor_2.jpg 800w, https:\/\/artscienceblr.org\/wp-content\/uploads\/2016\/05\/Water_Level_Sensor_2-300x225.jpg 300w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>The following sketch that we found was used to measure the salinity.<\/p>\n<pre style=\"color: black;\">\/*\r\nThis is the Arduino sketch for the conductivity probe.\r\nVersion 1 - Initial design that report values through to the serial monitor\r\n*\/\r\n\r\nint inputPin = A3;\r\nconst float closedVoltage = 5.00; \/\/assumed value of voltage (replace with vcc)\r\nconst float voltageRange = closedVoltage\/1024; \/\/Used to map the analog reading to the voltage of the circuit.\r\nconst float resistor = 10000.00; \/\/size of resistor on the ground line, 1000 in the case of using with the DIY sensor \r\nint conductReading = 0; \/\/reading from A3 pin\r\nfloat conductVoltage = 0.00; \/\/calculated voltage from reading\r\nfloat resistance = 0.00; \/\/calculated resistance of water (ohms)\r\nfloat area = 0.0002; \/\/area of the all four sides of the electrodes in square meters\r\nfloat length = 0.01; \/\/distance between the electrodes in meters \r\nfloat resistivity = 0.0; \/\/resistivity of fluid\r\nfloat conductivity = 0.00; \/\/calculated conductivity of water (micro-siemens\/m)\r\n\r\nvoid setup(){\r\nSerial.begin(9600);\r\npinMode(inputPin, INPUT);\r\n}\r\n\r\nvoid loop(){\r\nconductReading = analogRead(inputPin);\r\nconductVoltage = conductReading * voltageRange;\r\nresistance = ((closedVoltage * resistor)\/conductVoltage) - resistor;\r\nresistivity = resistance * area \/ length;\r\nconductivity = (1 \/ resistivity)*1000;\r\nSerial.print(conductReading);\r\nSerial.print(\", Conductivity (milliSiemens\/m) =\");\r\nSerial.println(conductivity);\r\ndelay(1000);\r\n}\r\n\r\n<\/pre>\n<p>5) Temperature &#8211; Temperature was measured using an LM35. It is connected to A6 on the Nano. A good tutorial can be found <a href=\"http:\/\/www.instructables.com\/id\/ARDUINO-TEMPERATURE-SENSOR-LM35\/\">here <\/a>. It is important to waterproof the sensor well before using it in humid conditions\/water.<\/p>\n<p>Pin 1 goes to +5V, Pin 2 to A6, Pin 3 to GND<\/p>\n<p><a href=\"http:\/\/artscienceblr.org\/wp-content\/uploads\/2016\/05\/temp.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-789\" src=\"http:\/\/artscienceblr.org\/wp-content\/uploads\/2016\/05\/temp.jpg\" alt=\"temp\" width=\"862\" height=\"1000\" srcset=\"https:\/\/artscienceblr.org\/wp-content\/uploads\/2016\/05\/temp.jpg 862w, https:\/\/artscienceblr.org\/wp-content\/uploads\/2016\/05\/temp-258x300.jpg 258w\" sizes=\"auto, (max-width: 862px) 100vw, 862px\" \/><\/a><\/p>\n<p>The following sketch was used.<\/p>\n<pre style=\"color: black;\">int val;\r\nint tempPin = A6;\r\n\r\nvoid setup()\r\n{\r\nSerial.begin(9600);\r\n}\r\nvoid loop()\r\n{\r\nval = analogRead(tempPin);\r\nfloat cel = ( val\/1024.0)*500;\r\nfloat farh = (cel*9)\/5 + 32;\r\n\r\nSerial.print(\"TEMPRATURE = \");\r\nSerial.print(cel);\r\nSerial.print(\"*C\");\r\nSerial.println();\r\ndelay(1000);\r\n\r\n\/* uncomment this to get temperature in farenhite\r\nSerial.print(\"TEMPRATURE = \");\r\nSerial.print(farh);\r\nSerial.print(\"*F\");\r\nSerial.println();\r\n*\/\r\n}\r\n<\/pre>\n<p>6) Soil Moisture &#8211; It was measured using a soil moisture sensor.<\/p>\n<p><a href=\"http:\/\/artscienceblr.org\/wp-content\/uploads\/2016\/05\/soil-moisture.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-790\" src=\"http:\/\/artscienceblr.org\/wp-content\/uploads\/2016\/05\/soil-moisture.jpg\" alt=\"soil moisture\" width=\"1500\" height=\"1278\" srcset=\"https:\/\/artscienceblr.org\/wp-content\/uploads\/2016\/05\/soil-moisture.jpg 1500w, https:\/\/artscienceblr.org\/wp-content\/uploads\/2016\/05\/soil-moisture-300x255.jpg 300w, https:\/\/artscienceblr.org\/wp-content\/uploads\/2016\/05\/soil-moisture-1024x872.jpg 1024w\" sizes=\"auto, (max-width: 1500px) 100vw, 1500px\" \/><\/a><\/p>\n<p>Soil moisture was represented in percentage. The following sketch was used for it.<\/p>\n<pre style=\"color: black;\">#define moisturePin A7\r\nint sensorValue = 0;\r\nint outputValue = 0; \/\/ variable for value in percentage\r\n\r\nvoid setup() {\r\n\/\/ initialize serial communication at 9600 bits per second:\r\nSerial.begin(9600);\r\n}\r\n\r\nvoid loop() {\r\n\/\/ read the input on analog pin 7:\r\nsensorValue = analogRead(moisturePin);\r\noutputValue = map(sensorValue,0,800, 0, 100); \/\/ replace 800 with the sensor value when sensor is put into water i.e. 100% moisture\r\n\r\n\/\/ print out the value you read:\r\nSerial.print(\"SensorReading =\");\r\nSerial.println(sensorValue);\r\nSerial.print(\"\\t % moisture = \");\r\nSerial.println(outputValue);\r\n\r\ndelay(1000); \/\/ delay in between reads for stability\r\n}\r\n\r\n<\/pre>\n<p>7) Distance- We thought that it might be useful to include a distance meter to track the placement of the machine from a known fixed object. We used an ultrasonic sensor for this. It is connected to digital pins 5 and 6. We got the sketch from <a href=\"%20 https:\/\/www.dealextreme.com\/p\/hc-sr04-ultrasonic-sensor-distance-measuring-module-133696   \">here <\/a>.<\/p>\n<pre style=\"color: black;\">const int trigPin = 5;\r\nconst int echoPin = 6;\r\nvoid setup() {\r\n\/\/ initialize serial communication:\r\nSerial.begin(9600);\r\n}\r\n\r\nvoid loop()\r\n{\r\n\/\/ establish variables for duration of the ping,\r\n\/\/ and the distance result in inches and centimeters:\r\nlong duration, inches, cm;\r\n\r\n\/\/ The sensor is triggered by a HIGH pulse of 10 or more microseconds.\r\n\/\/ Give a short LOW pulse beforehand to ensure a clean HIGH pulse:\r\npinMode(trigPin, OUTPUT);\r\ndigitalWrite(trigPin, LOW);\r\ndelayMicroseconds(2);\r\ndigitalWrite(trigPin, HIGH);\r\ndelayMicroseconds(10);\r\ndigitalWrite(trigPin, LOW);\r\n\r\n\/\/ Read the signal from the sensor: a HIGH pulse whose\r\n\/\/ duration is the time (in microseconds) from the sending\r\n\/\/ of the ping to the reception of its echo off of an object.\r\npinMode(echoPin, INPUT);\r\nduration = pulseIn(echoPin, HIGH);\r\n\r\n\/\/ convert the time into a distance\r\ninches = microsecondsToInches(duration);\r\ncm = microsecondsToCentimeters(duration);\r\n\r\nSerial.print(inches);\r\nSerial.print(\"in, \");\r\nSerial.print(cm);\r\nSerial.print(\"cm\");\r\nSerial.println();\r\n\r\ndelay(100);\r\n}\r\n\r\nlong microsecondsToInches(long microseconds)\r\n{\r\n\/\/ According to Parallax's datasheet for the PING))), there are\r\n\/\/ 73.746 microseconds per inch (i.e. sound travels at 1130 feet per\r\n\/\/ second). This gives the distance travelled by the ping, outbound\r\n\/\/ and return, so we divide by 2 to get the distance of the obstacle.\r\n\/\/ See: http:\/\/www.parallax.com\/dl\/docs\/prod\/acc\/28015-PING-v1.3.pdf\r\nreturn microseconds \/ 74 \/ 2;\r\n}\r\n\r\nlong microsecondsToCentimeters(long microseconds)\r\n{\r\n\/\/ The speed of sound is 340 m\/s or 29 microseconds per centimeter.\r\n\/\/ The ping travels out and back, so to find the distance of the\r\n\/\/ object we take half of the distance travelled.\r\nreturn microseconds \/ 29 \/ 2;\r\n}\r\n<\/pre>\n<p>After getting all the sensors working, the next step is to move onto the Data Logger. The first step is to set the real time clock on the data logger. We used the tutorial from the <a href=\"https:\/\/learn.adafruit.com\/adafruit-data-logger-shield\">Adafruit website.<\/a><\/p>\n<p>After setting it up, we uploaded the master all sensors + data logger file to the nano. Below is the code for that.<\/p>\n<p>&nbsp;<\/p>\n<pre style=\"color: black;\">#include &lt;SD.h&gt;\r\n#include &lt;Wire.h&gt;\r\n#include \"RTClib.h\"\r\n\r\n\/\/ A simple data logger for the Arduino analog pins\r\n\r\n\/\/ how many milliseconds between grabbing data and logging it. 1000 ms is once a second\r\n#define LOG_INTERVAL 1000 \/\/ mills between entries (reduce to take more\/faster data)\r\n\r\n\/\/ how many milliseconds before writing the logged data permanently to disk\r\n\/\/ set it to the LOG_INTERVAL to write each time (safest)\r\n\/\/ set it to 10*LOG_INTERVAL to write all data every 10 datareads, you could lose up to\r\n\/\/ the last 10 reads if power is lost but it uses less power and is much faster!\r\n#define SYNC_INTERVAL 1000 \/\/ mills between calls to flush() - to write data to the card\r\nuint32_t syncTime = 0; \/\/ time of last sync()\r\n\r\n#define ECHO_TO_SERIAL 1 \/\/ echo data to serial port\r\n#define WAIT_TO_START 0 \/\/ Wait for serial input in setup()\r\n\r\n\/\/ the digital pins that connect to the LEDs\r\n#define redLEDpin 2\r\n#define greenLEDpin 3\r\n\r\n\/\/ The analog pins that connect to the sensors\r\n\/\/#define phPin A0\r\n#define turbidityPin A1\r\n#define gasPin A2\r\n#define gasDPin D4\r\n#define salinityPin A3\r\n#define tempPin A6\r\n#define moisturePin A7\r\n\/\/#define trigPin 5 \/\/ range ultrasound added below as const int\r\n\/\/#define echoPin 6 \/\/range ultrasound\r\n\r\n#define RL_VALUE (5) \/\/define the load resistance on the board, in kilo ohms\r\n#define RO_CLEAN_AIR_FACTOR (4.5) \/\/RO_CLEAR_AIR_FACTOR=(Sensor resistance in clean air)\/RO,\r\n#define CALIBARAION_SAMPLE_TIMES (50) \/\/define how many samples you are going to take in the calibration phase\r\n#define CALIBRATION_SAMPLE_INTERVAL (500) \/\/define the time interal(in milisecond) between each samples in the \/\/cablibration phase\r\n#define READ_SAMPLE_INTERVAL (50) \/\/define how many samples you are going to take in normal operation\r\n#define READ_SAMPLE_TIMES (5) \/\/define the time interal(in milisecond) between each samples in\r\n#define gas_CH4 (0)\r\n\r\n#define BANDGAPREF 14 \/\/ data logger stuff:special indicator that we want to measure the bandgap\r\n#define aref_voltage 5 \/\/ we tie 5V to ARef and measure it with a multimeter!\r\n#define bandgap_voltage 1.1 \/\/ this is not super guaranteed but its not -too- off\r\n\r\nfloat CH4Curve[3] = {2.3,0.45,-1.04};\r\nfloat Ro = 4.5;\r\n\r\nint phReading = 0;\r\nint phValue = 0;\r\nint turbidityReading = 0;\r\nint turbidityValue = 0;\r\n\/\/int gasReading = 0;\r\n\/\/int gasValue = 0;\r\n\/\/int salinityReading = 0;\r\n\/\/int salinityValue = 0;\r\nint tempReading = 0;\r\nint tempValue = 0;\r\nint moistureReading = 0;\r\nint moistureValue = 0;\r\n\r\n\/\/int microsecondsToCentimeters = 0; \/\/ for range ultrasound\r\n\r\nconst int trigPin = 5; \/\/range ultrasound\r\nconst int echoPin = 6;\r\n\r\nconst float salclosedVoltage = 5.00; \/\/Salinity stuff; assumed value of voltage (replace with vcc)\r\nconst float salvoltageRange = salclosedVoltage\/1024; \/\/Used to map the analog reading to the voltage of the circuit.\r\nconst float salresistor = 10000.00; \/\/size of resistor on the ground line\r\n\r\nint salconductReading = 0; \/\/reading from A3 pin\r\n\r\nfloat salconductVoltage = 0.00; \/\/calculated voltage from reading\r\nfloat salresistance = 0.00; \/\/calculated resistance of water (ohms)\r\nfloat salarea = 0.0002; \/\/area of the all four sides of the electrodes in square meters\r\nfloat length = 0.01; \/\/distance between the electrodes in meters\r\nfloat salresistivity = 0.0; \/\/resistivity of fluid\r\nfloat salconductivity = 0.00; \/\/calculated conductivity of water (micro-siemens\/m)\r\n\r\nRTC_DS1307 RTC; \/\/ DATA LOGGER STUFF : define the Real Time Clock object\r\n\r\n\/\/ for the data logging shield, we use digital pin 10 for the SD cs line\r\nconst int chipSelect = 10;\r\n\r\n\/\/ the logging file\r\nFile logfile;\r\n\r\nvoid error(char *str)\r\n{\r\nSerial.print(\"error: \");\r\nSerial.println(str);\r\n\r\n\/\/ red LED indicates error\r\ndigitalWrite(redLEDpin, HIGH);\r\n\r\nwhile(1);\r\n}\r\n\r\nvoid setup(void)\r\n{\r\nSerial.begin (115200);\r\nanalogReference(INTERNAL);\r\nSerial.println();\r\n\r\n\/\/ use debugging LEDs\r\npinMode(redLEDpin, OUTPUT);\r\npinMode(greenLEDpin, OUTPUT);\r\n\r\n#if WAIT_TO_START\r\nSerial.println(\"Type any character to start\");\r\nwhile (!Serial.available());\r\n#endif \/\/WAIT_TO_START\r\n\r\n\/\/ initialize the SD card\r\nSerial.print(\"Initializing SD card...\");\r\n\/\/ make sure that the default chip select pin is set to\r\n\/\/ output, even if you don't use it:\r\npinMode(10, OUTPUT);\r\n\r\n\/\/ see if the card is present and can be initialized:\r\nif (!SD.begin(chipSelect)) {\r\nerror(\"Card failed, or not present\");\r\n}\r\nSerial.println(\"card initialized.\");\r\n\r\n\/\/ create a new file\r\nchar filename[] = \"LOGGER00.CSV\";\r\nfor (uint8_t i = 0; i &lt; 100; i++) {\r\nfilename[6] = i\/10 + '0';\r\nfilename[7] = i%10 + '0';\r\nif (! SD.exists(filename)) {\r\n\/\/ only open a new file if it doesn't exist\r\nlogfile = SD.open(filename, FILE_WRITE);\r\nbreak; \/\/ leave the loop!\r\n}\r\n}\r\n\r\nif (! logfile) {\r\nerror(\"couldnt create file\");\r\n}\r\n\r\nSerial.print(\"Logging to: \");\r\nSerial.println(filename);\r\n\r\n\/\/ connect to RTC\r\nWire.begin();\r\nif (!RTC.begin()) {\r\nlogfile.println(\"RTC failed\");\r\n#if ECHO_TO_SERIAL\r\nSerial.println(\"RTC failed\");\r\n#endif \/\/ECHO_TO_SERIAL\r\n}\r\n\r\nlogfile.println(\"millis,stamp,datetime,turbidity%,Methane_ppm,Saln_mS\/m,temp_C,temp_F,moisture%,range_in,range_cm,vcc\");\r\n#if ECHO_TO_SERIAL\r\nSerial.println(\"millis,stamp,datetime,turbidity%,Methane_ppm,Saln_mS\/m,temp_C,temp_F,moisture%,range_in,range_cm,vcc\");\r\n#endif \/\/ECHO_TO_SERIAL\r\n\r\n\/\/ If you want to set the aref to something other than 5v\r\nanalogReference(EXTERNAL);\r\n}\r\n\r\nvoid loop(void)\r\n{\r\nDateTime now; \/\/DATA LOGGER STUFF\r\n\r\n\/\/ delay for the amount of time we want between readings\r\ndelay((LOG_INTERVAL -1) - (millis() % LOG_INTERVAL));\r\n\r\ndigitalWrite(greenLEDpin, HIGH);\r\n\r\n\/\/ log milliseconds since starting\r\nuint32_t m = millis();\r\nlogfile.print(m); \/\/ milliseconds since start\r\nlogfile.print(\", \");\r\n#if ECHO_TO_SERIAL\r\nSerial.print(m); \/\/ milliseconds since start\r\nSerial.print(\", \");\r\n#endif\r\n\r\n\/\/ fetch the time\r\nnow = RTC.now();\r\n\/\/ log time\r\nlogfile.print(now.unixtime()); \/\/ seconds since 1\/1\/1970\r\nlogfile.print(\", \");\r\nlogfile.print('\"');\r\nlogfile.print(now.year(), DEC);\r\nlogfile.print(\"\/\");\r\nlogfile.print(now.month(), DEC);\r\nlogfile.print(\"\/\");\r\nlogfile.print(now.day(), DEC);\r\nlogfile.print(\" \");\r\nlogfile.print(now.hour(), DEC);\r\nlogfile.print(\":\");\r\nlogfile.print(now.minute(), DEC);\r\nlogfile.print(\":\");\r\nlogfile.print(now.second(), DEC);\r\nlogfile.print('\"');\r\n#if ECHO_TO_SERIAL\r\nSerial.print(now.unixtime()); \/\/ seconds since 1\/1\/1970\r\nSerial.print(\", \");\r\nSerial.print('\"');\r\nSerial.print(now.year(), DEC);\r\nSerial.print(\"\/\");\r\nSerial.print(now.month(), DEC);\r\nSerial.print(\"\/\");\r\nSerial.print(now.day(), DEC);\r\nSerial.print(\" \");\r\nSerial.print(now.hour(), DEC);\r\nSerial.print(\":\");\r\nSerial.print(now.minute(), DEC);\r\nSerial.print(\":\");\r\nSerial.print(now.second(), DEC);\r\nSerial.print('\"');\r\n#endif \/\/ECHO_TO_SERIAL\r\n\r\n\/\/ startting sensor codes\r\nturbidityReading = analogRead(turbidityPin);\r\nturbidityValue = map(turbidityReading, 20, 960, 0, 100);\r\n\r\nsalconductReading = analogRead(salinityPin); \/\/salConductivity\r\nsalconductVoltage = salconductReading * salvoltageRange;\r\nsalresistance = ((salclosedVoltage * salresistor)\/salconductVoltage) - salresistor;\r\nsalresistivity = salresistance * salarea \/ length;\r\nsalconductivity = (1 \/ salresistivity)*1000;\r\n\r\ntempValue = analogRead(tempPin); \/\/temperature problems\r\nfloat mv = ( tempValue\/1024.0)*5000;\r\nfloat cel = (mv\/10)-10; \/\/CORRECTION OF -10\r\nfloat farh = (cel*9)\/5 + 32;\r\n\r\nmoistureReading = analogRead(moisturePin); \/\/soil moisture\r\nmoistureValue = map(moistureReading,1023,104,0,100);\r\n\r\nlong duration, inches, cm; \/\/range ultrasound\r\npinMode(trigPin, OUTPUT);\r\ndigitalWrite(trigPin, LOW);\r\ndelayMicroseconds(2);\r\ndigitalWrite(trigPin, HIGH);\r\ndelayMicroseconds(10);\r\ndigitalWrite(trigPin, LOW); \/\/ Read the signal from the sensor: a HIGH pulse whose\r\n\/\/ duration is the time (in microseconds) from the sending\r\n\/\/ of the ping to the reception of its echo off of an objec\r\npinMode(echoPin, INPUT);\r\nduration = pulseIn(echoPin, HIGH);\r\n\/\/ convert the time into a distance\r\ninches = microsecondsToInches(duration);\r\ncm = microsecondsToCentimeters(duration);\r\nlogfile.print(\", \");\r\nlogfile.print(turbidityValue);\r\nlogfile.print(\", \");\r\nlogfile.print(MQGetGasPercentage(MQRead(gasPin)\/Ro,gas_CH4));\r\nlogfile.print(\", \");\r\nlogfile.print(salconductivity);\r\nlogfile.print(\", \");\r\nlogfile.print(cel);\r\nlogfile.print(\", \");\r\nlogfile.print(farh);\r\nlogfile.print(\", \");\r\nlogfile.print(moistureValue);\r\nlogfile.print(\", \");\r\nlogfile.print(inches);\r\nlogfile.print(\", \");\r\nlogfile.print(cm);\r\nlogfile.print(\", \");\r\n\r\n#if ECHO_TO_SERIAL \/\/ DONT TOUCH DL\r\nSerial.print(\", \");\r\nSerial.print(\"turbidity%=\");\r\nSerial.println(turbidityValue);\r\nSerial.print(\", \");\r\nSerial.print(\"Methane:\"); \/\/gas\r\nSerial.print(MQGetGasPercentage(MQRead(gasPin)\/Ro,gas_CH4) );\r\nSerial.print( \"ppm\" );\r\nSerial.print(\", \");\r\nSerial.print(\"Conductivity (milliSiemens\/m) =\");\r\nSerial.println(salconductivity);\r\nSerial.print(\", \");\r\nSerial.print(\"TEMPRATURE_c = \");\r\nSerial.print(cel);\r\nSerial.print(\"*C\");\r\nSerial.print(\", \");\r\nSerial.print(\"TEMPRATURE_f = \");\r\nSerial.print(farh);\r\nSerial.print(\"*F\");\r\nSerial.print(\"% moisture = \");\r\nSerial.print(moistureValue);\r\nSerial.println();\r\nSerial.print(\"distance:\");\r\nSerial.print(inches);\r\nSerial.print(\"in, \");\r\nSerial.print(cm);\r\nSerial.print(\"cm\");\r\nSerial.println();\r\n#endif \/\/ECHO_TO_SERIAL \/\/DONT TOUCH DL\r\n\r\n\/\/ Log the estimated 'VCC' voltage by measuring the internal 1.1v ref\r\nanalogRead(BANDGAPREF);\r\ndelay(4000);\r\n\r\nint refReading = analogRead(BANDGAPREF);\r\nfloat supplyvoltage = (bandgap_voltage * 1024) \/ refReading;\r\n\r\nlogfile.print(\", \");\r\nlogfile.print(supplyvoltage);\r\n#if ECHO_TO_SERIAL\r\nSerial.print(\", \");\r\nSerial.print(supplyvoltage);\r\n#endif \/\/ ECHO_TO_SERIAL\r\n\r\nlogfile.println();\r\n#if ECHO_TO_SERIAL\r\nSerial.println();\r\n#endif \/\/ ECHO_TO_SERIAL\r\n\r\ndigitalWrite(greenLEDpin, LOW);\r\n\r\n\/\/ Now we write data to disk! Don't sync too often - requires 2048 bytes of I\/O to SD card\r\n\/\/ which uses a bunch of power and takes time\r\nif ((millis() - syncTime) &lt; SYNC_INTERVAL) return;\r\nsyncTime = millis();\r\n\r\n\/\/ blink LED to show we are syncing data to the card &amp; updating FAT!\r\ndigitalWrite(redLEDpin, HIGH);\r\nlogfile.flush();\r\ndigitalWrite(redLEDpin, LOW);\r\n\r\n}\r\n\r\nfloat MQResistanceCalculation(int raw_adc) \/\/gas sensor details\r\n{\r\nreturn ( ((float)RL_VALUE*(1023-raw_adc)\/raw_adc));\r\n}\r\n\r\nfloat MQCalibration(int gasPin)\r\n{\r\nint i;\r\nfloat val=0;\r\n\r\nfor (i=0;i&lt;CALIBARAION_SAMPLE_TIMES;i++) { \/\/take multiple samples\r\nval += MQResistanceCalculation(analogRead(gasPin));\r\ndelay(CALIBRATION_SAMPLE_INTERVAL);\r\n}\r\nval = val\/CALIBARAION_SAMPLE_TIMES; \/\/calculate the average value\r\n\r\nval = val\/RO_CLEAN_AIR_FACTOR; \/\/divided by RO_CLEAN_AIR_FACTOR yields the Ro\r\n\/\/according to the chart in the datasheet\r\n\r\nreturn val;\r\n}\r\n\r\nfloat MQRead(int mq_pin)\r\n{\r\nint i;\r\nfloat rs=0;\r\n\r\nfor (i=0;i&lt;READ_SAMPLE_TIMES;i++) {\r\nrs += MQResistanceCalculation(analogRead(mq_pin));\r\ndelay(READ_SAMPLE_INTERVAL);\r\n}\r\nrs = rs\/READ_SAMPLE_TIMES;\r\nreturn rs;\r\n}\r\n\r\nint MQGetGasPercentage(float rs_ro_ratio, int gas_id)\r\n{\r\nif ( gas_id == gas_CH4 ) {\r\nreturn MQGetPercentage(rs_ro_ratio,CH4Curve);\r\n}\r\n\r\nreturn 0;\r\n}\r\nint MQGetPercentage(float rs_ro_ratio, float *pcurve)\r\n{\r\nreturn (pow(4.5,( ((log(rs_ro_ratio)-pcurve[1])\/pcurve[2]) + pcurve[0])));\r\n}\r\n\r\nlong microsecondsToInches(long microseconds) \/\/ calculations for range ultrasound\r\n{\r\n\/\/ According to Parallax's datasheet for the PING))), there are\r\n\/\/ 73.746 microseconds per inch (i.e. sound travels at 1130 feet per\r\n\/\/ second). This gives the distance travelled by the ping, outbound\r\n\/\/ and return, so we divide by 2 to get the distance of the obstacle.\r\n\/\/ See: http:\/\/www.parallax.com\/dl\/docs\/prod\/acc\/28015-PING-v1.3.pdf\r\nreturn microseconds \/ 74 \/ 2;\r\n}\r\n\r\nlong microsecondsToCentimeters(long microseconds)\r\n{\r\n\/\/ The speed of sound is 340 m\/s or 29 microseconds per centimeter.\r\n\/\/ The ping travels out and back, so to find the distance of the\r\n\/\/ object we take half of the distance travelled.\r\nreturn microseconds \/ 29 \/ 2;\r\n}\r\n<\/pre>\n<p>The file that we get is in CSV format and can be directly imported into excel, pd or other softwares.<\/p>\n<p><a href=\"http:\/\/artscienceblr.org\/wp-content\/uploads\/2016\/05\/data-logger-excel.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-793\" src=\"http:\/\/artscienceblr.org\/wp-content\/uploads\/2016\/05\/data-logger-excel.jpg\" alt=\"data logger excel\" width=\"1500\" height=\"1125\" srcset=\"https:\/\/artscienceblr.org\/wp-content\/uploads\/2016\/05\/data-logger-excel.jpg 1500w, https:\/\/artscienceblr.org\/wp-content\/uploads\/2016\/05\/data-logger-excel-300x225.jpg 300w, https:\/\/artscienceblr.org\/wp-content\/uploads\/2016\/05\/data-logger-excel-1024x768.jpg 1024w\" sizes=\"auto, (max-width: 1500px) 100vw, 1500px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>We used a plastic chocolate box and coolant pipes to make the structure and housing.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This summer we worked with The Indian Sonic Research Organisation and the Earth Co.Lab . Earth Co Lab is developing a Swamp Song machine using environmental sensors. Swamp songs is a pedagogical experiment with electronics, sound, and ecology \u2013 It uses physical computing tools to develop ecological sensors in an effort to rethink how we [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":790,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"footnotes":""},"categories":[11,15],"tags":[104,94,102,101,100,97,91,89,103,95,92,93,80,98,99,132,90,96],"class_list":["bg-stuff"],"_links":{"self":[{"href":"https:\/\/artscienceblr.org\/index.php\/wp-json\/wp\/v2\/posts\/766","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/artscienceblr.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/artscienceblr.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/artscienceblr.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/artscienceblr.org\/index.php\/wp-json\/wp\/v2\/comments?post=766"}],"version-history":[{"count":25,"href":"https:\/\/artscienceblr.org\/index.php\/wp-json\/wp\/v2\/posts\/766\/revisions"}],"predecessor-version":[{"id":811,"href":"https:\/\/artscienceblr.org\/index.php\/wp-json\/wp\/v2\/posts\/766\/revisions\/811"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/artscienceblr.org\/index.php\/wp-json\/wp\/v2\/media\/790"}],"wp:attachment":[{"href":"https:\/\/artscienceblr.org\/index.php\/wp-json\/wp\/v2\/media?parent=766"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/artscienceblr.org\/index.php\/wp-json\/wp\/v2\/categories?post=766"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/artscienceblr.org\/index.php\/wp-json\/wp\/v2\/tags?post=766"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}