CODE Arduino
CODE Arduino
void loop() {
float sensor_volt; //Define variable for sensor voltage
float RS_air; //Define variable for sensor resistance
float R0; //Define variable for R0
float sensorValue; //Define variable for analog readings
for (int x = 0 ; x < 500 ; x++){
sensorValue = sensorValue + analogRead(A0); //Add analog values of sensor 500
times
}
sensorValue = sensorValue / 500.0; //Take average of readings
sensor_volt = sensorValue * (5.0 / 1023.0); //Convert average to voltage
RS_air = ((5.0 * 10.0) / sensor_volt) - 10.0; //Calculate RS in fresh air
R0 = RS_air / 4.4; //Calculate R0
Serial.print("R0 = ");
Serial.println(R0); //Display value of R0
delay(1000);
}
****************************************************
/*
Arduino MQ4 gas sensor - Geekstips.com
This example is to calculate the gas concentration using the R0
calculated in the example above
Also a OLED SSD1306 screen is used to display data, if you do not
have such a display, just delete the code used for displaying
*/
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include <gfxfont.h>
void setup() {
Serial.begin(9600); //Baud rate
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //Initialize screen
display.setTextColor(WHITE); //Set text color
display.setTextSize(3); //Set text size
pinMode(led, OUTPUT); //Set LED as output
digitalWrite(led, LOW); //Turn LED off
pinMode(buzzer, OUTPUT); //Set buzzer as output
digitalWrite(buzzer, LOW); // Turn buzzer off
pinMode(gas_sensor, INPUT); //Set gas sensor as input
}
void loop() {
display.clearDisplay(); //Clear display
display.setCursor(0, 5); //Place cursor in (x,y) location
float sensor_volt; //Define variable for sensor voltage
float RS_gas; //Define variable for sensor resistance
float ratio; //Define variable for ratio
float sensorValue = analogRead(gas_sensor); //Read analog values of sensor
sensor_volt = sensorValue * (5.0 / 1023.0); //Convert analog values to voltage
RS_gas = ((5.0 * 10.0) / sensor_volt) - 10.0; //Get value of RS in a gas
ratio = RS_gas / R0; // Get ratio RS_gas/RS_air
void setup() {
Serial.begin(9600);
}
void loop() {
float sensor_volt;
float RS_air;
float R0;
float sensorValue;
for (int x = 0 ; x < 500 ; x++){
sensorValue = sensorValue + analogRead(A0);
}
sensorValue = sensorValue / 500.0;
sensor_volt = sensorValue * (5.0 / 1023.0);
RS_air = ((5.0 * 10.0) / sensor_volt) - 10.0;
R0 = RS_air / 4.4;
Serial.print("R0 = ");
Serial.println(R0);
delay(1000);
}
--------------------------------------------------------------------
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include <gfxfont.h>
#include <SPI.h>
#include <Wire.h>
#define OLED_RESET 11
Adafruit_SSD1306 display(OLED_RESET);
int led = 10;
int buzzer = 9;
int gas_sensor = A0;
float m = -0.318;
float b = 1.133;
float R0 = 11.820;
void setup() {
Serial.begin(9600);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.setTextColor(WHITE);
display.setTextSize(3);
pinMode(led, OUTPUT);
digitalWrite(led, LOW);
pinMode(buzzer, OUTPUT);
digitalWrite(buzzer, LOW);
pinMode(gas_sensor, INPUT);
}
void loop() {
display.clearDisplay();
display.setCursor(0, 5);
float sensor_volt;
float RS_gas;
float ratio;
float sensorValue = analogRead(gas_sensor);
sensor_volt = sensorValue * (5.0 / 1023.0);
RS_gas = ((5.0 * 10.0) / sensor_volt) - 10.0;
ratio = RS_gas / R0;
double ppm_log = (log10(ratio) - b) / m;
double ppm = pow(10, ppm_log);
double percentage = ppm / 10000;
display.print(percentage);
display.print("%");
display.display();
digitalWrite(led, HIGH);
digitalWrite(buzzer, HIGH);
} else {
digitalWrite(led, LOW);
digitalWrite(buzzer, LOW);
}
}
************************************************************
MQ-7
void setup() {
Serial.begin(9600); //Baud rate
pinMode(A1,INPUT);
}
void loop() {
float sensor_volt; //Define variable for sensor voltage
float RS_air; //Define variable for sensor resistance
float R0; //Define variable for R0
float sensorValue=0.0; //Define variable for analog readings
for(int x = 0 ; x < 500 ; x++) //Start for loop
{
sensorValue = sensorValue + analogRead(A1); //Add analog values of sensor 500
times
}
sensorValue = sensorValue/500.0; //Take average of readings
Serial.print("Average = ");
Serial.println(sensorValue);
sensor_volt = sensorValue*(5.0/1023.0); //Convert average to voltage
RS_air = ((5.0*10.0)/sensor_volt)-10.0; //Calculate RS in fresh air
R0 = RS_air/27; //Calculate R0
Serial.print("Sensor RAW value = ");
Serial.println(analogRead(A1));
Serial.print("R0 = "); //Display "R0"
Serial.println(R0); //Display value of R0
Serial.println(analogRead(A1));
delay(1000); //Wait 1 second
}
______________________________________________________________________
void setup() {
Serial.begin(9600); //Baud rate
void loop() {
Serial.print("Ratio = ");
Serial.println(ratio);
double ppm_log = (log10(ratio)-b)/m; //Get ppm value in linear scale according to
the the ratio value
double ppm = pow(10, ppm_log); //Convert ppm value to log scale
Serial.print("Our desired PPM = ");
Serial.println(ppm);
double percentage = ppm/10000; //Convert to percentage
Serial.print("Value in Percentage = "); //Load screen buffer with percentage
value
Serial.println(percentage);
delay(2000);
}
***************************************************************
void setup() {
Serial.begin(9600); //Baud rate
pinMode(A1,INPUT);
}
void loop() {
float sensor_volt;
float RS_air;
float R0;
float sensorValue=0.0;
for(int x = 0 ; x < 500 ; x++)
{
sensorValue = sensorValue + analogRead(A1);
}
sensorValue = sensorValue/500.0;
Serial.print("Average = ");
Serial.println(sensorValue);
sensor_volt = sensorValue*(5.0/1023.0);
RS_air = ((5.0*10.0)/sensor_volt)-10.0;
R0 = RS_air/27;
Serial.print("Sensor RAW value = ");
Serial.println(analogRead(A1));
Serial.print("R0 = ");
Serial.println(R0);
Serial.println(analogRead(A1));
delay(1000);
}
______________________________________________________________
int gas_sensor = A0;
float m = -0.6527;
float b = 1.30;
float R0 = 21.91;
void setup() {
Serial.begin(9600);
pinMode(gas_sensor, INPUT);
}
void loop() {
float sensor_volt;
float RS_gas;
float ratio;
int sensorValue = analogRead(gas_sensor);
Serial.print("Ratio = ");
Serial.println(ratio);
double ppm_log = (log10(ratio)-b)/m;
double ppm = pow(10, ppm_log);
Serial.print("Our desired PPM = ");
Serial.println(ppm);
double percentage = ppm/10000;
Serial.print("Value in Percentage = ");
Serial.println(percentage);
delay(2000);
}
_________________________________________________________________________
ODS
#define USE_AVG
// Set the typical output voltage in Volts when there is zero dust.
static float Voc = 0.6;
/////////////////////////////////////////////////////////////////////////////
float voMeasured = 0;
float calcVoltage = 0;
float dustDensity = 0;
void setup(){
Serial.begin(9600);
pinMode(ledPower,OUTPUT);
}
void loop(){
digitalWrite(ledPower,LOW);
delayMicroseconds(samplingTime);
voMeasured = analogRead(measurePin);
delayMicroseconds(deltaTime);
digitalWrite(ledPower,HIGH);
delayMicroseconds(sleepTime);
calcVoltage = voMeasured*(5.0/1024);
dustDensity = 0.17*calcVoltage-0.1;
if ( dustDensity < 0)
{
dustDensity = 0.00;
}
Serial.println("Voltage:");
Serial.println(calcVoltage);
Serial.println("Dust Density:");
Serial.println(dustDensity);
delay(1000);
}
_________________________________________________________
dataset = pd.read_csv('dataset.csv')
df = dataset.copy()
df.head()
df.info()
df.isnull().sum()
df['agency'].value_counts()
# date format - mm/dd/yyyy
df['type'].value_counts()
df.isnull().sum()
df['type'] = a
df['type'].value_counts()
# rspm = PM10
df[['rspm', 'state']].groupby(['state']).median().sort_values("rspm", ascending =
False).plot.bar(color = 'r')
# spm
df[['spm', 'state']].groupby(['state']).median().sort_values("spm", ascending =
False).plot.bar(color = 'r')
# pm2_5
df[['pm2_5', 'state']].groupby(['state']).median().sort_values("pm2_5", ascending =
False).plot.bar(color = 'r')
#Correlation matrix
corrmat = df.corr()
f, ax = plt.subplots(figsize = (15, 10))
sns.heatmap(corrmat, vmax = 1, square = True, annot = True)
df.head()
# heatmap of rspm
f, ax = plt.subplots(figsize = (10,10))
ax.set_title('{} by state and year'.format('rspm'))
sns.heatmap(df.pivot_table('rspm', index='state',
columns = ['year'], aggfunc = 'median', margins = True),
annot = True, cmap = "YlGnBu", linewidths = 1, ax = ax, cbar_kws =
{'label': 'Annual Average'})
# heatmap of spm
f, ax = plt.subplots(figsize = (10, 10))
ax.set_title('{} by state and year'.format('spm'))
sns.heatmap(df.pivot_table('spm', index ='state',
columns = ['year'], aggfunc = 'median', margins = True)
, cmap = "YlGnBu", linewidths = 0.5, ax = ax, cbar_kws = {'label':
'Annual Average'})