Arduino Gas Concentration Sensor

    For this project we need an MQ2 Gas Sensor, an Arduino Uno r3 board, and jumper wires. This project will detect gas concentration and output a value of low, medium, or high.


Code:


const int mq2Analog = A0;  // Connect OUT to A0


void setup() {

  Serial.begin(9600);

}


void loop() {

  int sensorValue = analogRead(mq2Analog);

  float voltage = sensorValue * (5.0 / 1023.0);


  Serial.print("Analog Value: ");

  Serial.print(sensorValue);

  Serial.print(" | Voltage: ");

  Serial.print(voltage);

  Serial.print(" V | Gas Level: ");


  // Simple thresholds for gas concentration

  if (sensorValue < 200) {

    Serial.println("Low");

  } else if (sensorValue < 600) {

    Serial.println("Medium");

  } else {

    Serial.println("High");

  }


  delay(1000);

}


Arduino Ultrasonic Sensor

    For this project, we will need an Arduino Uno r3 board, an HC-SR04 Ultrasonic Sensor, and some jumper wires. Below Is a model and the code of it.


Code:
    

const int trigPin = 9;
const int echoPin = 10;

long duration;
int distance;

void setup() {
  Serial.begin(9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
}

void loop() {
  // Send trigger pulse
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  // Read echo pulse
  duration = pulseIn(echoPin, HIGH);

  // Convert time to distance (cm)
  distance = duration * 0.034 / 2;

  // Show on Serial Monitor
  Serial.print("Distance: ");
  Serial.print(distance);
  Serial.println(" cm");

  delay(500);
}

Lesson 6: Comparison Operators | Python Beginner Course 2025 🐍

 


  In this lesson, we'll learn about comparison operators in python. Comparison operators are used to compare two values and return a boolean value in the console. Below are a list of comparison operators.


== Equal to

!= Not equal to

> Greater than

< Less than

>= Greater than or equal to

>= Less than or equal to


Here is an example


Input:

x = 5 print(x == 5)

Output:

    True

Lesson 5: Master Assignment Operators | Python Beginner Course 2025 🐍

 


    In this lesson, we'll learn about assignment operators in python. They are pretty similar to arithmetic operators so make sure to check out that lesson too. Below are a list of the basic assignment operators in python.


+= This operator adds to a value

-= This operator subtracts from a value

*= This operator multiplies a value

**= This operator performs exponentiation on a value

/= This operator divides a value

//= This operator floor divides a value

%= this operator performs the modulo function on a value


Here is an example

Input:

x = 2
x **= 3print(x)

Output:

9

Lesson 4: Arithmetic Operators | Python Beginner Course 2025 🐍

 


    In this lesson, we'll learn about arithmetic operators in python. Arithmetic operators are used to perform mathematical calculations. Below I will list some of them.


+ Addition - Used to add numbers

- Subtraction - Used to subtract numbers

* Multiplication - Used to multiply numbers

/ Division - used to divide numbers

// Floor division - divides and rounds down answer to nearest whole number

** Exponentiation - use exponents

% Modulo - find remainder of division

Lesson 3: Checking and Changing Data Types | Python Beginner Course 2025 🐍

 


    In this lesson, we will learn how to check and change data types.

EXAMPLE:

Input:

    print(type("hello"))

    number = "2"

    print(type(int(number)))

Output:

    <class 'str'>

    <class 'int'>

Lesson 2: Python Basic Data Types | Python Beginner Course 🐍

 




    In the last lesson, we learned about how to properly name variables. In this lesson, we will be using that knowledge to assign different data types to our variables. Below are the different types of data and when they should be used.


age=15    #int    (Used when dealing with whole numbers)

price=12.99    #float    (Used when dealing with numbers with a decimal place)

message="Hello"    #str    (Used for making a sequence of characters)

boolean=True/False    #bool    (Used when using true/false values)


How to use the print function: print(enter variable or data here)

How to use f string: print(f"Text goes here {variable} text)

Lesson 1: Naming Rules | Python Beginner Course 🐍



    Before writing real python code, we must make sure the code will run properly. One way of doing that is following naming rules when creating variables. I will list the rules below.

1. Must only contain letters, numbers, and underscores, other characters are unsupported.

2. Cannot begin with a number.

3. Cannot use python keywords.

Examples of Proper Naming

1. name

2. _age

3. User3

Examples of Bad Naming

1. 2user

2. user-name

3. for