Components and supplies
MQ135
Grove - Barometer (High-Accuracy)
Arduino UNO
SG90 Micro-servo motor
Lichterkette mit 3V oder 5V
Tools and machines
Laser cutter (generic)
Project description
Code
kukO2 Indoor air quality sensor
c_cpp
The „kukO2“ has the purpose to detect the CO2 content in indoor areas. It shows the level of CO2 when the concentration or cognitive abilities decrese.
1// inlcude librqries needed: 2 3#include <SoftwareSerial.h> 4#include <Servo.h> 5 6// Initiate Servo oject 7Servo window_control; 8 9// These constants won't change: 10const int sensorPin = A0; // pin that the sensor is attached to 11const int LEDPIN = 9; // pin that the LED is attached to 12const int ZU = 10; // Position of the servo motor for start (Zu) 13const int AUF = 30; // Position of the servo motor for end - position (a18uf) 14const int BAD_AIR = 220; // Default Wert empirisch ermittelt fr schlechte Luft 15const int GOOD_AIR = 150; // Default Wert empirisch ermittelt fr gute Luft 16const int OPEN = 1; // Define value for "OPEN" using the button 17const int CLOSED = 0; // Define value for "CLOSED" using the button 18const int TASTE_IN = 7; // define digital input channel to connect the button 19 20// variables: 21int window_pos = 0; // Variable controlling the window position (open and closed) 22float sensorValue = 0; // the sensor value 23float bad_air = BAD_AIR; // Loaad limit value with default 24float good_air = GOOD_AIR; // Loaad limit value with default 25int window_status = CLOSED; // Variable storing window status (closed or open) 26 27// --------------------- 28// Setup routine: 29// --------------------- 30 31void setup() { 32 // declare the Input nd output pins used on Arduino: 33 pinMode(TASTE_IN, INPUT); // sets the digital pin 7 as input 34 pinMode(LEDPIN, OUTPUT); // Set external LED control 35 window_control.attach(10); // declare usage of PWM pin "10" 36 Serial.begin(9600); // initialize the debugging monitor for development purposes 37 Window_close(); // Close window at start 38 start_sensor(); // Sensor ein paar mal einlesen, bis er gute Werte erzeugt. 39} 40 41// --------------------- 42// endless main- loop: 43// --------------------- 44void loop() { 45 46 digitalWrite(LEDPIN, HIGH); // Light control LED 47 Read_CO2_Sensor(); // Read in the CO2 senor value 48 Calibrate(); // Set a new current "good value" to calibrate the mechanism 49 Serial.println(sensorValue); // send sensor value to debugging window 50 if(sensorValue < good_air) // In case current sensor value is better as worst "good air" limit 51 { 52 if(window_status != CLOSED) // Check if window is not closed already 53 { 54 Window_close(); // close the window 55 window_status = CLOSED; // remember it was closed 56 } 57 } 58 else if (sensorValue > bad_air) // Check if current sensor value is worse as allowed bad air limit 59 { 60 if(window_status != OPEN) // Check if window is open already 61 { 62 Window_open(); // open the window 63 window_status = OPEN; // remember it was closed 64 } 65 } 66 digitalWrite(LEDPIN, LOW); // Reset control LED 67} 68 69// --------------------- 70// Supporting functions: 71// --------------------- 72 73// -------------------------------------------------------------------- 74// Function Checking for settinng new "good air limit" 75// -------------------------------------------------------------------- 76void Calibrate(void) 77{ 78 int i; 79 int taste; 80 81 taste = digitalRead(TASTE_IN); 82 //Serial.print(" Taste: "); // for better redability in debug window 83 //Serial.print(taste); // send sensor value to debugging window 84 Serial.print(" Limit: "); 85 Serial.print(abs(good_air)); // send current good air - limit to debug window 86 Serial.print(" Limit: "); 87 Serial.print(abs(bad_air)); // send current good air - limit to debug window 88 Serial.print(" Act-Value: "); 89 90 if(taste == 0) 91 { 92 93 good_air = sensorValue; // set the new good_air limit to the current value (after windos had been opened for a while) 94 bad_air = good_air + 30; // Set the jysteresis to 40PPM 95 for(i=0;i<10;i++){ // Start control LED to blink showing new calibratin was made sucessfully 96 digitalWrite(LEDPIN, LOW); 97 delay(50); 98 digitalWrite(LEDPIN, HIGH); 99 delay(50); 100 } 101 } 102} 103 104// -------------------------------------------------------------------- 105// Function to read in analog sensor signal for a while as 106// first measurements are not accurate 107// -------------------------------------------------------------------- 108void start_sensor(void) 109{ 110 const int NUM_OF_READ = 1000; // number of read cycles not used for "window" control 111 int i=0; // because the sensor must get warmed up first. 112 113 for(i=0;i<NUM_OF_READ;i++) // for loop 114 { 115 analogRead(sensorPin); // read the sensor in 116 delay(10); // delay by 10ms 117 } 118} 119 120// -------------------------------------------------------------------- 121// Function to read in analog sensor signal and make a "Mittelwert" 122// This is because the sensor signal turned out to be very unstable 123// -------------------------------------------------------------------- 124void Read_CO2_Sensor(void) 125{ 126 const int NUM_OF_READ = 200; 127 float new_value = 0.0; 128 129 int i=0; 130 131 for(i=0;i<NUM_OF_READ;i++) // for loop reading in NUM_OF_READ sensor vlues and make average 132 { // as the sensor is not really stable 133 new_value = analogRead(sensorPin); // read the sensor in 134 sensorValue = sensorValue + new_value; // add to the last sum of sensor values 135 delay(10); // delay by 10ms 136 } 137 sensorValue = sensorValue/NUM_OF_READ; // devide by number of read ins 138} 139 140// -------------------------------------------------------------------- 141// Function closing the window by control of servo motor 142// -------------------------------------------------------------------- 143void Window_close(void) 144{ 145 146 window_control.attach(10); // declare usage of PWM pin "10" 147 for(window_pos = ZU; window_pos <= AUF; window_pos++) 148 { 149 window_control.write(window_pos); 150 delay(25); 151 } 152 Serial.println(" - OPEN -"); // Show Closing status on debug window 153 window_control.attach(11); // declare usage of PWM pin to an unused pin "11" to eliminate permanent noise of motor 154 155} 156 157// -------------------------------------------------------------------- 158// Function opening the window by control of servo motor 159// -------------------------------------------------------------------- 160void Window_open(void) 161{ 162 tone(3, 70); // Make sound with the buzzer 163 window_control.attach(10); // declare usage of PWM pin "10" 164 for(window_pos = AUF; window_pos >= ZU; window_pos--) 165 { 166 window_control.write(window_pos); 167 delay(25); 168 } 169 Serial.println(" - CLOSE -"); // Show Closing status on debug window 170 window_control.attach(11); // declare usage of PWM pin to an unused pin "11" to eliminate permanent noise of motor 171 172 noTone(3); // Stop sound 173} 174
Downloadable files
kukO2
This is how you need to assamble the parts.
kukO2
kukO2
This is how you need to assamble the parts.
kukO2
Documentation
the cutting mask for the house
the cutting mask for the house
the cutting mask for the house
the cutting mask for the house
Comments
Only logged in users can leave comments
theresa_angl
0 Followers
•0 Projects
Table of contents
Intro
3
0