Week Three
Week Three
This Week's Overview:
We constructed the complete circuit and produced a cohesive code that performs the requirements of our gas safety system.
Main Tasks:
1) We tackled the issues that arose last week:
- Since stepper motors have high accuracies, they can be instructed to rotate to a certain position and easily return to their original position when needed. Therefore, in an attempt to avoid replacing them for another type of motor (servo motor), we changed its full-step sequence to a half-step sequence in the code which made the pace faster:
half_step_sequence = [
[1, 0, 0, 0],
[1, 1, 0, 0],
[0, 1, 0, 0],
[0, 1, 1, 0],
[0, 0, 1, 0],
[0, 0, 1, 1],
[0, 0, 0, 1],
[1, 0, 0, 1],
]
Additionally, we specified the number of steps it would take to open up the window by 5 cm (3200 steps) and the time between each step (2 ms) to control the motor's speed:
STEPS_PER_5CM = 3200
STEP_DELAY = 0.002
- We were able to calibrate the CO sensor using its built in calibration potentiometer by changing it to produce values closer to 1.5 ppm rather than 900 ppm which were the original values the sensor was reading when placed indoors (an environment with low levels of CO).
The sensor was also calibrated in the code using this formula:
CO (ppm) = 10 x ((log (R_s / R_0) - b )/m)
R_s = ((V_in - V_out) / V_out) / RL
where R_s: sensor resistance at certain gas level
R_0: sensor resistance in clean air
b: y-intercept of the log plot of relationship between the ratio of R_s/R_0 and ppm
m: slope of the log plot of relationship between the ratio of R_s/R_0 and ppm
All of these values can be found on the data sheet [1].
2) The alarm system (the buzzer) was integrated into the system, creating our full circuit according to the circuit diagram.
All the components were connected to the 3.3V and GND pins except for the stepper motor which was connected to 5V and GND. The different GPIO (general purpose input/output) pins were connected as follows:
Connections:
a) DHT11 (Digital): GPIO pin 16
b) MQ9 (Analogue): GPIO pin 26
c) MQ135 (Analogue): GPIO pin 27
d) Buzzer: GPIO pin 14
e) Fan: GPIO pin 15
f) Stepper Motor:
- Input 1: GPIO pin 18
- Input 2: GPIO pin 19
- Input 3: GPIO pin 20
- Input 5: GPIO pin 21
g) E-Paper Display:
- Data/ Command Control: GPIO pin 8
- SPI Chip select: GPIO pin 9
- SPI SCK: GPIO pin 10
- SPI MOSI: GPIO pin 11
- External Reset: GPIO pin 12
- Busy Status: GPIO pin 13
3) We produced a full code that operates the requirements of our system:
a) Reads the values from the three sensors (MQ-135, MQ-9, and DHT11):
# Read temperature/humidity
dht11.measure()
temp = dht11.temperature()
hum = dht11.humidity()
# Read MQ-9 CO
co_ppm = read_co_ppm()
# Read MQ-135 CO2 (not calibrated yet)
co2_ppm = read_mq135_ppm()
b) Checks whether the gas levels are safe to breathe:
#checks if the CO levels are safe to breathe (<=10)
co_status = "Safe" if co_ppm <= 10 else "Dangerous"
#checks if the CO2 levels are safe to breathe (<=1000)
air_quality_status = "Good" if co2_ppm <= 1000 else ("Moderate" if co2_ppm <= 1500 else "Poor")
c) If they are safe, it displays those results on the e-paper display.
d) If they are not safe to breathe, it sounds the alarm, opens the window by 5 cm, shuts off the fan to provoke faster gas exchange, and displays a warning message until the gas levels are safe to breathe again:
# **Warning System**
if co_status == "Dangerous" or air_quality_status == "Poor":
# Checks if CO and CO2 levels are Dangerous or Poor respectively
buzzer_alert() # Buzzer sounds
print("Displaying warning...")
show_warning() # Shows the warning message on the display
# **'Window' and 'AC' Control**
# 1) air quality check:
if air_quality_status == "Poor": # Checks if CO2 levels are Poor
move_stepper(STEPS_PER_5CM, "open")#open the window by moving the stepper motor by 5cm
while True:
utime.sleep(5)
co2_ppm = read_mq135_ppm()
air_quality_status = "Good" if co2_ppm <= 1000 else ("Moderate" if co2_ppm <= 1500 else "Poor")# Keeps checking the quality of the air
if air_quality_status != "Poor":
break
# if the air quality is safe to breathe ie not poor, the loop breaks
move_stepper(STEPS_PER_5CM, "close")#closes the window by moving the stepper motor in the opposite direction by 5cm
# 2) CO levels check:
if co_status == "Dangerous": # Checks if CO levels are Dangerous
fan.value(0) # Closes the fan to allow faster gas exchange
move_stepper(STEPS_PER_5CM, "open") #open the window by moving the stepper motor by 5cm
while True:
utime.sleep(5)
co_ppm = read_co_ppm()
co_status = "Safe" if co_ppm <= 10 else "Dangerous"# Keeps checking the quality of the air
if co_status != "Dangerous":
break
# if the CO levels are safe to breathe ie not dangerous, the loop breaks
move_stepper(STEPS_PER_5CM, "close") #closes the window by moving the stepper motor in the opposite direction by 5cm
fan.value(1) # opens the fan
4) We finalized the 3D printed linear gears and the actuator and requested for them to be printed.
Issues:
- Our CO2 sensor (MQ-135) was not calibrated; we have to either compare its results with a calibrated one's results or purchase a calibrated CO2 sensor.
Next steps:
- Calibrating the CO2 sensor.
- Creating a demo circuit that is more presentable/ practical.
- Creating the "window's" mechanism using the stepping motor and 3D printed linear gear.
References:
[1] Hanwei Eletronics, "Technical data MQ-9 sensor," MQ-9 datasheet.
Comments
Post a Comment