IDE Progrmmaing
IDE Progrmmaing
Materials Needed:
// Setup function runs once when you press reset or power the board
void setup() {
// Initialize the digital pin as an output
pinMode(ledPin, OUTPUT);
}
• Connect your Arduino board to your computer using the USB cable.
• Select the correct board and port in the Arduino IDE:
o Go to Tools > Board and select your Arduino board (e.g., Arduino Uno).
o Go to Tools > Port and select the port that your Arduino is connected to.
• Click the upload button (right arrow) in the Arduino IDE to upload the code to your
Arduino board.
Result:
Detecting soil moisture using an Arduino is a common project for monitoring plant health.
Here’s a step-by-step guide to setting up a soil moisture sensor with an Arduino.
Materials Needed:
void setup() {
// Start the serial communication to display the sensor value
Serial.begin(9600);
}
void loop() {
// Read the value from the sensor
sensorValue = analogRead(sensorPin);
• Connect your Arduino board to your computer using the USB cable.
• Select the correct board and port in the Arduino IDE:
o Go to Tools > Board and select your Arduino board (e.g., Arduino Uno).
o Go to Tools > Port and select the port that your Arduino is connected to.
• Click the upload button (right arrow) in the Arduino IDE to upload the code to your
Arduino board.
• Open the Serial Monitor in the Arduino IDE (Tools > Serial Monitor) to see the
sensor readings.
• The sensor will output an analog value (usually between 0 and 1023). Lower values
typically indicate higher moisture levels, while higher values indicate drier conditions.
Result:
You should see the soil moisture sensor values being printed in the Serial Monitor, indicating the
moisture level of the soil.
Creating a smoke detector using an Arduino is a useful project for monitoring air quality and
detecting potential fire hazards. Here's a step-by-step guide to set up a smoke detector using an
MQ-2 gas sensor with an Arduino.
Materials Needed:
// Define pins
const int sensorPin = A0; // Analog pin connected to AO of the MQ-2 sensor
const int buzzerPin = 3; // Digital pin connected to the buzzer (optional)
void setup() {
// Start the serial communication to display the sensor value
Serial.begin(9600);
// Set the buzzer pin as output
pinMode(buzzerPin, OUTPUT);
// Initialize the buzzer to be off
digitalWrite(buzzerPin, LOW);
}
void loop() {
// Read the value from the sensor
int sensorValue = analogRead(sensorPin);
• Connect your Arduino board to your computer using the USB cable.
• Select the correct board and port in the Arduino IDE:
o Go to Tools > Board and select your Arduino board (e.g., Arduino Uno).
o Go to Tools > Port and select the port that your Arduino is connected to.
• Click the upload button (right arrow) in the Arduino IDE to upload the code to your
Arduino board.
• Open the Serial Monitor in the Arduino IDE (Tools > Serial Monitor) to see the
sensor readings.
• The sensor will output an analog value that represents the concentration of gas/smoke in
the air. The buzzer will sound if the concentration exceeds the threshold you set in the
code.
Result:
You should see the smoke sensor values being printed in the Serial Monitor. If the smoke level
exceeds the threshold, the buzzer will sound, indicating the presence of smoke.
Creating a sound detection system using an Arduino is a fun project that can be used for
various applications like noise monitoring or as a trigger for other actions. Here's a step-by-step
guide to set up a sound detector using an Arduino and a sound sensor module.
Materials Needed:
// Define pins
const int sensorPin = A0; // Analog pin connected to AO of the sound sensor
const int alertPin = 3; // Digital pin connected to the buzzer or LED
(optional)
void setup() {
// Start the serial communication to display the sensor value
Serial.begin(9600);
// Set the alert pin as output
pinMode(alertPin, OUTPUT);
// Initialize the alert pin to be off
digitalWrite(alertPin, LOW);
}
void loop() {
// Read the value from the sensor
int sensorValue = analogRead(sensorPin);
• Connect your Arduino board to your computer using the USB cable.
• Select the correct board and port in the Arduino IDE:
o Go to Tools > Board and select your Arduino board (e.g., Arduino Uno).
o Go to Tools > Port and select the port that your Arduino is connected to.
• Click the upload button (right arrow) in the Arduino IDE to upload the code to your
Arduino board.
• Open the Serial Monitor in the Arduino IDE (Tools > Serial Monitor) to see the
sensor readings.
• The sensor will output an analog value that represents the sound level. If the sound level
exceeds the threshold you set in the code, the buzzer or LED will activate.
Result:
You should see the sound sensor values being printed in the Serial Monitor. If the sound level
exceeds the threshold, the buzzer will sound or the LED will light up, indicating the presence of
a sound.
Creating an obstacle detection system using an Arduino is a useful project for robotics and
automation. Typically, an ultrasonic sensor like the HC-SR04 is used for obstacle detection.
Here's a step-by-step guide to set up an obstacle detection system using an Arduino and an
ultrasonic sensor.
Materials Needed:
void setup() {
// Start the serial communication to display the distance
Serial.begin(9600);
// Set the trigger pin as output and the echo pin as input
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
// Set the alert pin as output
pinMode(alertPin, OUTPUT);
// Initialize the alert pin to be off
digitalWrite(alertPin, LOW);
}
void loop() {
// Clear the trigger pin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
• Connect your Arduino board to your computer using the USB cable.
• Select the correct board and port in the Arduino IDE:
o Go to Tools > Board and select your Arduino board (e.g., Arduino Uno).
o Go to Tools > Port and select the port that your Arduino is connected to.
• Click the upload button (right arrow) in the Arduino IDE to upload the code to your
Arduino board.
• Open the Serial Monitor in the Arduino IDE (Tools > Serial Monitor) to see the
distance readings.
• The sensor will output the distance to the nearest object. If the distance is less than the
threshold you set in the code, the buzzer will sound or the LED will light up.
Result:
You should see the distance readings being printed in the Serial Monitor. If an obstacle is
detected within the threshold distance, the buzzer will sound or the LED will light up, indicating
the presence of an obstacle.