User Tools

Site Tools


amc2021:groupl:extras:python:start

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
amc2021:groupl:extras:python:start [2021/09/05 01:17] kshama001amc2021:groupl:extras:python:start [2023/01/05 14:38] (current) – external edit 127.0.0.1
Line 3: Line 3:
 Python was used to parse the data received from the sensors. Python was used to parse the data received from the sensors.
  
-<file php myexample.php>+The below program was used to get a graph based on the values received from the sensor. The data was also saved in a csv format after. Data was then combined from all the locations and the pandas tool was used to find the mean value and the ratio of the mean vs the concentration of CO<sub>2</sub> in clean air.  
 + 
 +<file   php CO2.php> 
 <PHP> <PHP>
 +# Importing library
 +import csv
 +import pandas as pd
 import serial import serial
 import time import time
Line 10: Line 16:
  
 # make sure the 'COM#' is set according the Windows Device Manager # make sure the 'COM#' is set according the Windows Device Manager
-ser = serial.Serial('/dev/cu.usbmodem14101', 9600, timeout=1)+ser = serial.Serial('insert_device_com', 9600, timeout=1)
 time.sleep(2) time.sleep(2)
  
Line 30: Line 36:
 plt.show() plt.show()
  
-</PHP> 
- 
-<PHP> 
-# Importing library 
-import csv 
-import pandas as pd 
  
 CO2 = pd.DataFrame(data) #convert data to a pandas dataframe CO2 = pd.DataFrame(data) #convert data to a pandas dataframe
Line 44: Line 44:
 CO2.to_csv(file,index = False) CO2.to_csv(file,index = False)
  
-</PHP>+#combining data taken from all three locations 
  
-<PHP> 
-#combining data taken from all three locations  
-import pandas as pd 
 L = pd.read_csv('CO2_L.csv' #reading the csv files L = pd.read_csv('CO2_L.csv' #reading the csv files
 K = pd.read_csv('CO2_K.csv') K = pd.read_csv('CO2_K.csv')
 B = pd.read_csv('CO2_B.csv') B = pd.read_csv('CO2_B.csv')
-df = pd.concat([L,K,B], axis = 1) #combing all the files horizontally +df = pd.concat([L,K,B], axis = 1) #combining all the files horizontally
-</PHP>+
  
-<PHP> 
 # calculating the mean for each location # calculating the mean for each location
 mean = df.mean() mean = df.mean()
Line 69: Line 64:
 df.to_csv(file1,index = False) df.to_csv(file1,index = False)
 </PHP> </PHP>
 +
 +</file>
 +
 +The below program was used to get a graph based on the sound in decibels vs time. The data was received from the sensor LM393. 
 +<file   php Sound.php>
 +
 +<PHP>
 +# Importing library
 +import csv
 +import pandas as pd
 +import serial
 +import time
 +import matplotlib.pyplot as plt
 +
 +# make sure the 'COM#' is set according the Windows Device Manager
 +ser = serial.Serial('insert_device_com', 9600, timeout=1)
 +time.sleep(2)
 +
 +data = []
 +for i in range(100):
 +    line = ser.readline()   # read a byte string
 +    if line:
 +        string = line.decode()  # convert the byte string to a unicode string
 +        num = float(string) # convert the unicode string to an int
 +        num2 = int(num)
 +        data.append(num2) # add int to data list
 +ser.close()
 +
 +# build the plot
 +plt.plot(data)
 +plt.xlabel('Time[ms]')
 +plt.ylabel('Sound[dB]')
 +plt.title('Sound vs. Time')
 +plt.show()
 +
 +  
 +
 +</PHP>
 +
 +
 +</file>
 +[[amc2021:groupl:report:start|Back to report]]
amc2021/groupl/extras/python/start.1630797474.txt.gz · Last modified: 2023/01/05 14:38 (external edit)