0% found this document useful (0 votes)
64 views8 pages

Arduino Workshoop Loe

The document lists 20 experiments for an Arduino project involving sensors and actuators, including: blinking an LED, using a button to control an LED, reading analog sensor values, generating tones with a buzzer, controlling LED brightness with PWM, moving a servo motor to angles, reading temperature with a sensor, measuring distance with ultrasound, reading light levels with a light sensor, mixing colors on an RGB LED, displaying sensor data on an LCD, sending and receiving serial data, controlling LEDs with an IR remote, rotating a stepper motor in steps, detecting motion with a PIR sensor, and logging sensor data to an SD card.

Uploaded by

talha.k.rajpoot
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)
64 views8 pages

Arduino Workshoop Loe

The document lists 20 experiments for an Arduino project involving sensors and actuators, including: blinking an LED, using a button to control an LED, reading analog sensor values, generating tones with a buzzer, controlling LED brightness with PWM, moving a servo motor to angles, reading temperature with a sensor, measuring distance with ultrasound, reading light levels with a light sensor, mixing colors on an RGB LED, displaying sensor data on an LCD, sending and receiving serial data, controlling LEDs with an IR remote, rotating a stepper motor in steps, detecting motion with a PIR sensor, and logging sensor data to an SD card.

Uploaded by

talha.k.rajpoot
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/ 8

List of Experiments

1. Blinking LED: Start with a simple LED blink project.


2. Button Control: Use a push-button to control an LED.
3. Analog Input: Read analog sensor data from a potentiometer.
4. Sound Buzzer: Create melodies using a buzzer.
5. PWM LED Control: Control LED brightness using PWM.
6. Servo Motor Control: Move a servo motor to specific angles.
7. Temperature Sensor: Read temperature using a digital temperature sensor.
8. Ultrasonic Distance: Measure distance with an ultrasonic sensor.
9. Light Sensor: Read light intensity with an LDR (Light-Dependent Resistor).
10. RGB LED Control: Mix colors with an RGB LED.
11. LCD Display: Show sensor data on a character LCD.
12. Serial Communication: Send and receive data via Serial.
13. IR Remote Control: Control LEDs with an IR remote.
14. Stepper Motor Control: Rotate a stepper motor in steps.
15. PIR Motion Detector: Detect motion with a PIR sensor.
16. Gas Sensor: Detect gases with a gas sensor.
17. Real-Time Clock: Display the current time and date.
18. RFID Reader: Read RFID card data.
19. Data Logging: Log sensor data to an SD card.
20. Data Plotting: Plot sensor data in various ways on the Serial Plotter.
Blinking LED:
const int ledPin = 13; // Define the LED pin
void setup() {
pinMode(ledPin, OUTPUT); // Set the LED pin as an output
}
void loop() {
digitalWrite(ledPin, HIGH); // Turn the LED on
delay(1000); // Wait for 1 second
digitalWrite(ledPin, LOW); // Turn the LED off
delay(1000); // Wait for 1 second
}

Button Control:
const int ledPin = 13; // LED pin
const int buttonPin = 2; // Button pin
void setup() {
pinMode(ledPin, OUTPUT); // LED pin as output
pinMode(buttonPin, INPUT_PULLUP); // Button pin with internal pull-up resistor
}
void loop() {
if (digitalRead(buttonPin) == LOW) {
digitalWrite(ledPin, HIGH); // Turn the LED on when the button is pressed
} else {
digitalWrite(ledPin, LOW); // Turn the LED off when the button is not pressed
}
}

Analog Input (Potentiometer):

const int potentiometerPin = A0; // Potentiometer analog input pin


const int ledPin = 9; // LED pin
void setup() {
pinMode(ledPin, OUTPUT); // LED pin as output
}
void loop() {
int sensorValue = analogRead(potentiometerPin); // Read analog sensor value
int brightness = map(sensorValue, 0, 1023, 0, 255); // Map sensor value to LED brightness
analogWrite(ledPin, brightness); // Control LED brightness using PWM
}
Sound Buzzer:
const int buzzerPin = 9; // Buzzer pin
void setup() {
pinMode(buzzerPin, OUTPUT); // Buzzer pin as output
}
void loop() {
tone(buzzerPin, 1000); // Play a 1kHz tone
delay(500); // Wait for 0.5 seconds
noTone(buzzerPin); // Stop the tone
delay(500); // Wait for 0.5 seconds
}

PWM LED Control:

const int ledPin = 9; // LED pin


void setup() {
pinMode(ledPin, OUTPUT); // LED pin as output
}
void loop() {
for (int brightness = 0; brightness <= 255; brightness++) {
analogWrite(ledPin, brightness); // Increase LED brightness gradually
delay(10); // Wait for a short time
}
for (int brightness = 255; brightness >= 0; brightness--) {
analogWrite(ledPin, brightness); // Decrease LED brightness gradually
delay(10); // Wait for a short time
}
}

Servo Motor Control: Move a servo motor to specific angles


#include <Servo.h>
Servo servoMotor;
void setup() {
servoMotor.attach(9); // Connect the servo to pin 9
}
void loop() {
// Move the servo to 0 degrees
servoMotor.write(0);
delay(1000);
// Move the servo to 90 degrees
servoMotor.write(90);
delay(1000);
// Move the servo to 180 degrees
servoMotor.write(180);
delay(1000);
}

Temperature Sensor: Read temperature using a digital temperature sensor (e.g.,


DHT22)
#include <DHT.h>
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
dht.begin();
}
void loop() {
delay(2000);
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %");
}

Ultrasonic Distance: Measure distance with an ultrasonic sensor (HC-SR04)


#define TRIG_PIN 9
#define ECHO_PIN 10
void setup() {
Serial.begin(9600);
pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
}
void loop() {
long duration, distance;
digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
duration = pulseIn(ECHO_PIN, HIGH);
distance = (duration / 2) / 29.1; // Divide by 29.1 to convert to centimeters
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
delay(1000);
}

Light Sensor: Read light intensity with an LDR (Light-Dependent Resistor)


int ldrPin = A0; // LDR connected to analog pin A0
void setup() {
Serial.begin(9600);
}
void loop() {
int ldrValue = analogRead(ldrPin);
Serial.print("LDR Value: ");
Serial.println(ldrValue);
delay(1000);
}

RGB LED Control: Mix colors with an RGB LED

int redPin = 9;
int greenPin = 10;
int bluePin = 11;
void setup() {
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop() {
// Red
digitalWrite(redPin, HIGH);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, LOW);
delay(1000);
// Green
digitalWrite(redPin, LOW);
digitalWrite(greenPin, HIGH);
digitalWrite(bluePin, LOW);
delay(1000);
// Blue
digitalWrite(redPin, LOW);
digitalWrite(greenPin, LOW);
digitalWrite(bluePin, HIGH);
delay(1000);
}

LCD Display: Show sensor data on a character LCD (use a potentiometer that rotates at 0
to 180 degrees to show angle on LCD)

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // Define the LCD interface
void setup() {
lcd.begin(16, 2); // Initialize the LCD with 16x2 characters
}
void loop() {
int sensorValue = analogRead(A0); // Read the analog sensor value
int angle = map(sensorValue, 0, 1023, 0, 180); // Map the sensor value to angle (0-180)
lcd.clear(); // Clear the LCD
lcd.setCursor(0, 0); // Set the cursor to the first line
lcd.print("Angle: "); // Display text
lcd.print(angle); // Display the angle value
delay(500); // Delay to update the display
}

Serial Communication: Send and receive data via Serial


void setup() {
Serial.begin(9600); // Initialize serial communication at 9600 bps
}
void loop() {
if (Serial.available() > 0) {
char receivedChar = Serial.read(); // Read a character from serial
// Do something with the received data
Serial.print("You sent: ");
Serial.println(receivedChar);
// You can add more code to handle received data here
}
// Send data via serial
Serial.println("Hello, Arduino!");
delay(1000); // Delay for 1 second
}

IR Remote Control: Control LEDs with an IR remote


For this task, you will need to use an IR remote library. You can install the IRremote library via the
Arduino Library Manager. Here's an example code:

#include <IRremote.h>
int RECV_PIN = 11; // Define the IR receiver pin
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup() {
irrecv.enableIRIn(); // Start the IR receiver
pinMode(13, OUTPUT); // LED connected to pin 13
}
void loop() {
if (irrecv.decode(&results)) {
int value = results.value;
if (value == 0xFFA25D) { // Replace with your remote's button code
digitalWrite(13, !digitalRead(13)); // Toggle the LED on pin 13
}
irrecv.resume(); // Receive the next value
}
}

14. Stepper Motor Control: Rotate a stepper motor in steps

You'll need a stepper motor and a stepper motor driver for this task. Here's a basic example using the
AccelStepper library:

#include <AccelStepper.h>
AccelStepper stepper(1, 8, 9); // Define the stepper motor and pins
void setup() {
stepper.setMaxSpeed(1000); // Set the maximum speed in steps per second
stepper.setSpeed(500); // Set the initial speed
}
void loop() {
stepper.runSpeed(); // Run the motor at the current speed
// You can change the speed or direction as needed
}

PIR Motion Detector: Detect motion with a PIR sensor


Connect the PIR sensor's output to an input pin (e.g., 2) on your Arduino:

int pirPin = 2; // PIR sensor output connected to pin 2


void setup() {
pinMode(pirPin, INPUT); // Set PIR pin as input
Serial.begin(9600); // Initialize serial communication
}
void loop() {
int pirValue = digitalRead(pirPin); // Read PIR sensor state
if (pirValue == HIGH) {
Serial.println("Motion detected!");
// You can add additional actions here
}
delay(1000); // Delay to reduce sensor noise
}

You might also like