KEMBAR78
All Project Coding1 | PDF | Arduino | Sensor
0% found this document useful (0 votes)
52 views8 pages

All Project Coding1

The document outlines several easy Arduino sensor projects for young innovators, including a clap switch, temperature display, light detector, burglar alarm, and LED fading with a potentiometer. Each project includes a brief description, required components, and sample code. Additionally, it provides teaching tips and explains the use of Serial communication in Arduino programming.

Uploaded by

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

All Project Coding1

The document outlines several easy Arduino sensor projects for young innovators, including a clap switch, temperature display, light detector, burglar alarm, and LED fading with a potentiometer. Each project includes a brief description, required components, and sample code. Additionally, it provides teaching tips and explains the use of Serial communication in Arduino programming.

Uploaded by

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

Fun with Arduino: Easy Sensor Projects for

Young Innovators
🔊 1. Clap Switch using Sound Sensor
Concept: Turn on an LED with a clap or loud soun

d.

Components:

 Sound sensor (KY-038 or similar)


 1 LED
 Arduino Uno

const int soundSensor = 2;


const int ledPin = 13;

void setup() {
pinMode(soundSensor, INPUT);
pinMode(ledPin, OUTPUT);
}
void loop() {
int soundValue = digitalRead(soundSensor);
if (soundValue == HIGH) {
digitalWrite(ledPin, HIGH);
delay(500); // LED on for 0.5 second
digitalWrite(ledPin, LOW);
}
}

🌡️ 2. Temperature Display using LM35


Concept: Measure room temperature and show it in Serial Monitor.

Components:

 LM35 temperature sensor


 Arduino Uno

const int tempPin = A0;

void setup() {
Serial.begin(9600);
}

void loop() {
int reading = analogRead(tempPin);
float voltage = reading * 5.0 / 1024.0;
float temperatureC = voltage * 100;

Serial.print("Temp: ");
Serial.print(temperatureC);
Serial.println(" C");

delay(1000); // 1 second delay


}

🌞 3. Light Detector with LDR


Concept: Turn on an LED when it’s dark.

Components:

 LDR (Light Dependent Resistor)


 10K resistor
 LED
 Arduino Uno

const int ldrPin = A0;


const int ledPin = 13;

void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}

void loop() {
int ldrValue = analogRead(ldrPin);
Serial.println(ldrValue);

if (ldrValue < 500) { // Adjust threshold for darkness


digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}

delay(500);
}

🚨 4. Burglar Alarm with PIR Motion Sensor


Concept: Detect motion and turn on a buzzer.

Components:

 PIR motion sensor


 Buzzer
 Arduino Uno

const int pirPin = 2;


const int buzzerPin = 8;

void setup() {
pinMode(pirPin, INPUT);
pinMode(buzzerPin, OUTPUT);
Serial.begin(9600);
}

void loop() {
int motion = digitalRead(pirPin);
if (motion == HIGH) {
digitalWrite(buzzerPin, HIGH);
Serial.println("Motion Detected!");
delay(2000); // Buzzer on for 2 seconds
digitalWrite(buzzerPin, LOW);
}
}

🌈 5. LED Fading with Potentiometer


Concept: Control LED brightness using a knob.

Components:
 Potentiometer
 LED
 Arduino Uno

const int potPin = A0;


const int ledPin = 9; // PWM pin

void setup() {
pinMode(ledPin, OUTPUT);
}

void loop() {
int potValue = analogRead(potPin);
int brightness = map(potValue, 0, 1023, 0, 255);
analogWrite(ledPin, brightness);
}

✅ Teaching Tips:

 Start each class by explaining the real-life use of each sensor.


 Let students build the circuit and then upload the code.
 Show Serial Monitor data for sensors like temperature or light.
 Ask them to modify thresholds or add conditions to encourage exploration.

What does Serial.begin(9600); do?

This line starts the serial communication between your Arduino and the computer — it opens the Serial
Monitor so you can see data coming from your Arduino.

 9600 is the baud rate — the speed of communication (bits per second). It must match the Serial Monitor.

📟 Why is it used in this code?


cpp
CopyEdit
Serial.begin(9600);
Serial.println("Motion Detected!");

In this project, Serial.begin(9600); is used because you're using:


✅ Serial.println() to print "Motion Detected!" when motion is sensed.

Without Serial.begin(9600);, the Serial Monitor won’t work.

✅ When should you use Serial.begin(9600);?

Use it when:

 You want to see values from sensors on the Serial Monitor.


 You use Serial.print() or Serial.println() anywhere in your code.

📦 Common sensors where Serial.begin() is useful:

Sensor Why use Serial.begin()


🔊 Sound Sensor To print sound detection (HIGH / LOW)
🌞 LDR (Light Sensor) To print light level (analog value)
🌡️ LM35 (Temperature Sensor) To print temperature value
🏃♂️ PIR Motion Sensor To show when motion is detected
🎮 Potentiometer To print position/rotation value
🌧️ Rain Sensor To print moisture levels
📦 Ultrasonic Sensor To display distance readings
📱 Bluetooth Module To debug what’s being sent or received

❌ When NOT to use Serial.begin():

 If you're not using Serial.print() or Serial Monitor, you don’t need it.
 For simple LED blink projects, or buzzer with no data output.

1. LED ON/OFF using a Button

Hardware Needed:

 1 LED
 1 resistor (220Ω)
 1 push button
 Arduino Uno
 Breadboard + jumper wires

const int ledPin = 13;


const int buttonPin = 2;
int buttonState = 0;

void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}

void loop() {
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
}

🚦 2. Traffic Light System

Hardware Needed:

 3 LEDs (Red, Yellow, Green)


 3 resistors (220Ω)
 Arduino Uno

cpp
CopyEdit
int red = 8;
int yellow = 9;
int green = 10;

void setup() {
pinMode(red, OUTPUT);
pinMode(yellow, OUTPUT);
pinMode(green, OUTPUT);
}

void loop() {
digitalWrite(green, HIGH);
delay(3000);
digitalWrite(green, LOW);

digitalWrite(yellow, HIGH);
delay(1000);
digitalWrite(yellow, LOW);

digitalWrite(red, HIGH);
delay(3000);
digitalWrite(red, LOW);
}

🚗 3. RC Car Controlled via Bluetooth


Hardware Needed:

 L298N motor driver


 2 DC motors
 HC-05 Bluetooth module
 Arduino Uno
 18650 battery or 9V battery

cpp
CopyEdit
// Motor Pins
int in1 = 7;
int in2 = 6;
int in3 = 5;
int in4 = 4;

// Bluetooth Input
char bt;

void setup() {
Serial.begin(9600);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
}

void loop() {
if (Serial.available()) {
bt = Serial.read();
if (bt == 'F') { // Forward
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
}
else if (bt == 'B') { // Backward
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
}
else if (bt == 'L') { // Left
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
}
else if (bt == 'R') { // Right
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
}
else if (bt == 'S') { // Stop
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
}
}
}

You might also like