[go: up one dir, main page]

0% found this document useful (0 votes)
18 views2 pages

Using MQ7 to detect high level of CO2

Uploaded by

Rosedi Che Rose
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views2 pages

Using MQ7 to detect high level of CO2

Uploaded by

Rosedi Che Rose
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

//Using MQ7 to detect high level of CO2

//Relay will turn on car windows wind down process

// Define the pin for the MQ7 sensor and the relay

int mq7Pin = A0; // Analog pin for MQ7 sensor

int relayPin = 2; // Digital pin for 5V relay

void setup() {

// Initialize the relay pin as an OUTPUT

pinMode(relayPin, OUTPUT);

// Start Serial communication (for debugging)

Serial.begin(9600);

void loop() {

// Read the analog value from the MQ7 sensor

int sensorValue = analogRead(mq7Pin);

// Convert the analog value to voltage (assuming 5V reference)

float voltage = sensorValue * (5.0 / 1023.0);

// Print the sensor value and voltage (for debugging)

Serial.print("Sensor Value: ");

Serial.print(sensorValue);

Serial.print(", Voltage: ");

Serial.println(voltage);

// Check if the sensor detects a high CO level (adjust threshold as needed)

if (voltage > 1.0) { // You may need to adjust this threshold

// If CO level is high, turn on the relay

digitalWrite(relayPin, HIGH);

Serial.println("CO Detected! Relay ON");


} else {

// If CO level is low, turn off the relay

digitalWrite(relayPin, LOW);

Serial.println("No CO Detected. Relay OFF");

// Add a delay to avoid rapid sensor readings

delay(1000); // Adjust the delay time as needed

You might also like