0% found this document useful (0 votes)
78 views60 pages

60 Projects

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

60 Projects

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

60 Arduino[UNO]

Projects
BY- YUVRAJ.R
Light Automation:
const int MOTION_SENSOR_PIN = 10;
const int LED_PIN = 6;
int motionStateCurrent = LOW;
int motionStatePrevious = LOW;
void setup() {
Serial.begin(9600);
pinMode(10, INPUT);
pinMode(6, OUTPUT);
}
void loop() {
motionStatePrevious = motionStateCurrent;
motionStateCurrent = digitalRead(10); // read new state
if (motionStatePrevious == LOW && motionStateCurrent
== HIGH) {
change: LOW -> HIGH
Serial.println("Motion detected!");
digitalWrite(6, HIGH); // turn on
}
else
if (motionStatePrevious == HIGH && motionStateCurrent
== LOW) {
change: HIGH -> LOW
Serial.println("Motion stopped!");
digitalWrite(6, LOW); // turn off
}
}
Blink:
Code:

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

void loop()
{
digitalWrite(13, HIGH);
delay(1000); // Wait for 1000
millisecond(s)
digitalWrite(13, LOW);
delay(1000); // Wait for 1000
millisecond(s)
}
Servo Motor:
#include <Servo.h>

int pos = 0;
Servo servo_9;
void setup()
{
servo_9.attach(9, 500, 2500);
}
void loop()
{
for (pos = 0; pos <= 180; pos += 1) {
servo_9.write(pos);

delay(15); // Wait for 15 millisecond(s)


}
for (pos = 180; pos >= 0; pos -= 1) {
servo_9.write(pos);
delay(15);
}
}
Ultrasonic Sensor:
int inches = 0;
int cm = 0;
long readUltrasonicDistance(int triggerPin, int echoPin)
{
pinMode(triggerPin, OUTPUT); // Clear the trigger
digitalWrite(triggerPin, LOW);
delayMicroseconds(2);
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
pinMode(echoPin, INPUT);
return pulseIn(echoPin, HIGH);
}
void setup()
{
Serial.begin(9600);
}
void loop()
{
cm = 0.01723 * readUltrasonicDistance(7, 7);
inches = (cm / 2.54);
Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.println("cm");
delay(100); // Wait for 100 millisecond(s)
}
LCD Display:
int seconds = 0;

Adafruit_LiquidCrystal lcd_1(0);
void setup()
{
lcd_1.begin(16, 2);

lcd_1.print("hello world");
}
void loop()
{
lcd_1.setCursor(0, 1);
lcd_1.print(seconds);
lcd_1.setBacklight(1);
delay(500); // Wait for 500 millisecond(s)
lcd_1.setBacklight(0);
delay(500); // Wait for 500 millisecond(s)
seconds += 1;
}
Button:
const int buttonPin = 2;
const int ledPin = 13;

int buttonState = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}

void loop() {
buttonState = digitalRead(buttonPin);

if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
} else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}
Potentiometer:
const int potPin = A0;
const int ledPin = 9;
int potValue = 0;
int brightness = 0;

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

void loop() {
potValue = analogRead(potPin);

brightness = map(potValue, 0, 1023, 0, 255);

analogWrite(ledPin, brightness);

delay(10);
}
Photoresistor with Buzzer:
const int photoPin = A0; // the number of the photoresistor
pin
const int buzzerPin = 9; // the number of the buzzer pin

int photoValue = 0; // variable to store the photoresistor


value
int threshold = 500; // threshold value for triggering the
buzzer
void setup() {
// initialize the buzzer pin as an output:
pinMode(9, OUTPUT);
}
void loop() {
// read the value of the photoresistor:
photoValue = analogRead(photoPin);

// check if the photoresistor value is below the threshold:


if (photoValue < threshold) {
// trigger the buzzer:
tone(9, 1000); // 1000 Hz frequency
} else {
// turn off the buzzer:
noTone(9);
}
delay(10);
Traffic Light:
const int redPin = 9; // the number of the red LED pin
const int yellowPin = 10; // the number of the yellow
LED pin
const int greenPin = 11; // the number of the green
LED pin
void setup() {
// initialize the LED pins as outputs:
pinMode(redPin, OUTPUT);
pinMode(yellowPin, OUTPUT);
pinMode(greenPin, OUTPUT);
}
void loop() {

digitalWrite(redPin, HIGH);
digitalWrite(yellowPin, LOW);
digitalWrite(greenPin, LOW);
delay(5000); // wait for 5 seconds

digitalWrite(redPin, LOW);
digitalWrite(yellowPin, HIGH);
digitalWrite(greenPin, LOW);
delay(2000); // wait for 2 seconds

digitalWrite(redPin, LOW);
digitalWrite(yellowPin, LOW);
digitalWrite(greenPin, HIGH);
delay(5000); // wait for 5 seconds
LED Fade:
const int ledPin = 13;

void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
}

void loop() {
// fade in the LED:
for (int brightness = 0; brightness < 256; brightness++)
{
analogWrite(ledPin, brightness);
delay(10);
}

// fade out the LED:


for (int brightness = 255; brightness >= 0; brightness--) {
analogWrite(ledPin, brightness);
delay(10);
}
}
Temperature Sensor:
if (celsius < baselineTemp) {
int baselineTemp = 0; digitalWrite(5, LOW);
int celsius = 0; digitalWrite(6, LOW);
int fahrenheit = 0; digitalWrite(7, LOW);
void setup() }
{ if (celsius >= baselineTemp && celsius <
pinMode(A0, INPUT); baselineTemp + 10) {
Serial.begin(9600); digitalWrite(5, HIGH);
pinMode(5, OUTPUT); digitalWrite(6, LOW);
pinMode(6, OUTPUT); digitalWrite(7, LOW);
}
pinMode(7, OUTPUT);
if (celsius >= baselineTemp + 10 && celsius <
}
baselineTemp + 20) {
void loop() digitalWrite(5, HIGH);
{ digitalWrite(6, HIGH);
// set threshold temperature to activate LEDs digitalWrite(7, LOW);
baselineTemp = 40; }
// measure temperature in Celsius if (celsius >= baselineTemp + 20 && celsius <
celsius = map(((analogRead(A0) - 20) * 3.04), 0, baselineTemp + 50) {
1023, -40, 125); digitalWrite(5, HIGH);
fahrenheit = ((celsius * 9) / 5 + 32); digitalWrite(6, HIGH);
Serial.print(celsius); digitalWrite(7, HIGH);
}
Serial.print(" C, ");
if (celsius >= baselineTemp + 100) {
Serial.print(fahrenheit);
digitalWrite(5, HIGH);
Serial.println(" F"); digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
}
delay(1000); // Wait for 1000 millisecond(s)
}
Soil Moisture Detector :
int moisture = 0; if (moisture < 200) {
void setup() digitalWrite(12, HIGH);
{ } else {
pinMode(A0, OUTPUT); if (moisture < 400) {
pinMode(A1, INPUT); digitalWrite(11, HIGH);
Serial.begin(9600); } else {
pinMode(8, OUTPUT); if (moisture < 600) {
pinMode(9, OUTPUT); digitalWrite(10, HIGH);
pinMode(10, OUTPUT); } else {
pinMode(11, OUTPUT); if (moisture < 800) {
pinMode(12, OUTPUT); digitalWrite(9, HIGH);
} } else {
void loop() digitalWrite(8, HIGH);
{ }
digitalWrite(A0, HIGH); }
delay(10); // Wait for 10 }
millisecond(s) }
moisture = delay(100); // Wait for 100 millisecond(s)
analogRead(A1); }
digitalWrite(A0, LOW);
Serial.println(moisture);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
Ultrasonic with servo:
#include <Servo.h> void loop() {

// constants won't change digitalWrite(6, HIGH);


const int TRIG_PIN = 6; delayMicroseconds(10);
const int ECHO_PIN = 7; digitalWrite(6, LOW);
const int SERVO_PIN = 9;
const int
DISTANCE_THRESHOLD = duration_us = pulseIn(7, HIGH);
150; distance_cm = 0.017 *
duration_us;
Servo servo;
if (distance_cm < 150)
float duration_us, servo.write(180);
distance_cm; else
servo.write(0);
void setup() {
Serial.begin (9600); Serial.print("distance: ");
pinMode(6, OUTPUT); Serial.print(distance_cm);
pinMode(7, INPUT); Serial.println(" cm");
servo.attach(9);
servo.write(0); delay(500);
} }
Ultrasonic with Buzzer:
const int trigPin = 3; digitalWrite(3, HIGH);
const int echoPin = 2; delayMicroseconds(10);
const int buzzer = 8; digitalWrite(3, LOW);

long duration; duration = pulseIn(2, HIGH);


int distance; distance= duration*0.034/2;
int safetyDistance;
safetyDistance = distance;
void setup() { if (safetyDistance <= 123){
pinMode(3, OUTPUT); digitalWrite(8, HIGH);
pinMode(2, INPUT); }
pinMode(8, OUTPUT); else{
Serial.begin(9600); digitalWrite(8, LOW);
} }
void loop() {
tone(4, 440); //G Serial.print("Distance: ");
delay(100); Serial.println(distance);
// Clears the trigPin }
digitalWrite(3, LOW);
delayMicroseconds(2);
4 Servo motor Individual
rotation:
#include <Servo.h> for(pos = 0; pos < 120; pos += 1)
{
Servo myservo; myservo2.write(pos);
Servo myservo2; delay(15);
Servo myservo3; }
Servo myservo4;
for(pos = 160; pos>=1; pos-=1)
int pos = 0; {
myservo3.write(pos);
void setup() delay(25);
{ }
myservo.attach(9);
myservo2.attach(10); for(pos = 120; pos>=1; pos-=1)
myservo3.attach(11); {
myservo4.attach(12); myservo4.write(pos);
} delay(30);
}
void loop() }
{
for(pos = 0; pos < 160; pos +=
1)
{
myservo.write(pos);
delay(10);
}
RGB light without Arduino:
Temperature sensor in LCD
display:
#include <Adafruit_LiquidCrystal.h>
int seconds = 0;
Adafruit_LiquidCrystal lcd_1(0);
Adafruit_LiquidCrystal lcd_2(0)
void setup()
{
lcd_1.begin(16, 1);

lcd_1.print("Temprature");

lcd_2.begin(16, 1);

lcd_2.print("Temprature");
}
void loop()
{
lcd_1.setCursor(0, 1);
lcd_1.print(seconds);
lcd_1.setBacklight(1);
delay(500);
lcd_1.setBacklight(0);
delay(500);
seconds += 1;
}
Soil Moisture with DC motor:
const int soilMoisturePin = A0;
const int motorPin = 2;
void setup() {
pinMode(A0, INPUT);
pinMode(2, OUTPUT);
}

void loop() {
int soilMoistureValue = analogRead(A0);
int soilMoisturePercentage = map(soilMoistureValue,
0, 1023, 0, 100);

if (soilMoisturePercentage < 30) {


// turn on the DC motor to water the plant:
digitalWrite(2, HIGH);
} else {
// turn off the DC motor:
digitalWrite(2, LOW);
}
delay(1000);
}
Ultrasonic with LCD:
void loop() {
#include <LiquidCrystal.h> // Read the distance from the
ultrasonic sensor
// Define the LCD pins int distance = readDistance();
const int rs = 12, en = 11, d4 = 5,
d5 = 4, d6 = 3, d7 = 2; // Display the distance on the LCD
lcd.setCursor(0, 0);
// Define the ultrasonic sensor pin lcd.print("Distance: ");
const int sigPin =A9; lcd.print(distance);
lcd.print(" cm");
// Create an instance of the LCD
library delay(500);
LiquidCrystal_I2C lcd(rs, en, d4, d5, }
d6, d7);
int readDistance() {
void setup() { int duration = pulseIn(sigPin,
// Initialize the LCD HIGH);
lcd.begin(16, 2);
lcd.setCursor(0, 0); // Calculate the distance
int distance = duration * 0.034 /
// Initialize the ultrasonic sensor 2;
pin
pinMode(A9, INPUT); return distance;
} }
2 Ultrasonic and Buzzer with
different sounds:
const int trigPin1 = 2;
digitalWrite(4, LOW);
const int echoPin1 = 3;
const int trigPin2 = 4; delayMicroseconds(2);
const int echoPin2 = 5; digitalWrite(4, HIGH);
const int buzzerPin = 9; delayMicroseconds(10);
void setup() { digitalWrite(4, LOW);
pinMode(2, OUTPUT); duration2 = pulseIn(5,
pinMode(3, INPUT); HIGH);
pinMode(4, OUTPUT); distance2 = duration2 *
pinMode(5, INPUT); 0.034 / 2;
// initialize the buzzer pin as an
output: if (distance1 < 20 &&
pinMode(9, OUTPUT);
distance2 < 20) {
}
tone(9, 2000, 100);
void loop() {
int duration1, distance1, duration2, } else if (distance1 < 20 ||
distance2; distance2 < 20) {
tone(9, 1000, 100);
digitalWrite(2, LOW); } else {
delayMicroseconds(2); tone(9, 500, 100);
digitalWrite(2, HIGH); }
delayMicroseconds(10); delay(500);
digitalWrite(2, LOW); }
duration1 = pulseIn(3, HIGH);
distance1 = duration1 * 0.034 / 2;
}
Neo pixel strip 6:
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
for (int i = 0; i < 6; i++) {
switch (i) {
case 0:
strip.setPixelColor(i, strip.Color(255, 0, 0)); // Red
break;
case 1:
strip.setPixelColor(i, strip.Color(0, 255, 0)); // Green
break;
case 2:
strip.setPixelColor(i, strip.Color(0, 0, 255)); // Blue
break;
case 3:
strip.setPixelColor(i, strip.Color(255, 255, 0)); // Yellow
break;
case 4:
strip.setPixelColor(i, strip.Color(255, 0, 255)); // Magenta
break;
case 5:
strip.setPixelColor(i, strip.Color(0, 255, 255)); // Cyan
break;
}}
strip.show();
delay(1000);
}
Neo pixel Ring 16:
const int PIN = 6;
const int NUM_PIXELS = 16;

Adafruit_NeoPixel ring = Adafruit_NeoPixel(16, 6, NEO_GRB +


NEO_KHZ800);
void setup() {
// Initialize the Neopixel ring
ring.begin();
ring.show();
}
void loop() {
// Example: Set each pixel to a different color
for (int i = 0; i < 16; i++) {
switch (i % 4) {
case 0:
ring.setPixelColor(i, ring.Color(255, 0, 0)); // Red
break;
case 1:
ring.setPixelColor(i, ring.Color(0, 255, 0)); // Green
break;
case 2:
ring.setPixelColor(i, ring.Color(0, 0, 255)); // Blue
break; ring.show();
case 3: delay(1000);
ring.setPixelColor(i, ring.Color(255, 255, 0)); // Yellow
}
break;
}
}
Vibrator:
void setup() {
pinMode(vibratorPin, OUTPUT);
}

void loop() {
// Turn the vibrator on
digitalWrite(vibratorPin, HIGH);
delay(1000); // Vibrate for 1 second

// Turn the vibrator off


digitalWrite(vibratorPin, LOW);
delay(1000); // Pause for 1 second
}
Voltage Meter:
const int voltagePin = A0; // ADC #include <LiquidCrystal.h>
pin connected to the voltage source
const int voltagePin = A0;
void setup() { const int rs = 12, en = 11, d4 = 5, d5 =
Serial.begin(9600); 4, d6 = 3, d7 = 2;
} LiquidCrystal_I2C lcd(rs, en, d4, d5, d6,
d7);
void loop() {
// Read the voltage from the ADC void setup() {
pin lcd.begin(16, 2);
int voltageReading = lcd.setCursor(0, 0);
analogRead(voltagePin); }
void loop() {
float voltage = voltageReading * 5.0 int voltageReading =
/ 1023.0; analogRead(voltagePin);

// Print the voltage reading to the float voltage = voltageReading * 5.0 /


serial monitor 1023.0;
Serial.print("Voltage: ");
Serial.print(voltage); // Display the voltage reading on the
Serial.println(" V"); LCD
lcd.setCursor(0, 0);
delay(1000); // Take a reading lcd.print("Voltage: ");
every 1 second lcd.print(voltage);
} lcd.print(" V");
Neo pixel strip 12:
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS,
PIN, NEO_GRB + NEO_KHZ800);
int delayval = 100; // timing delay in milliseconds
int redColor = 0;
int greenColor = 0;
int blueColor = 0;

void setup() {
pixels.begin();
}
void loop() {
setColor();
for (int i=0; i < NUMPIXELS; i++) {
pixels.setPixelColor(i, pixels.Color(redColor, greenColor,
blueColor));
pixels.show();
delay(delayval);
}
}
void setColor(){
redColor = random(0, 255);
greenColor = random(0,255);
blueColor = random(0, 255);
}
LCD with Potentiometer:
#include <LiquidCrystal.h>

int seconds = 0;

LiquidCrystal lcd_1(12, 11, 5, 4, 3, 2);

void setup()
{
lcd_1.begin(16, 2); // Set up the number of
columns and rows on the LCD.
lcd_1.print("hello world!");
}

void loop()
{
lcd_1.setCursor(0, 1);
lcd_1.print(seconds);
delay(1000); // Wait for 1000 millisecond(s)
seconds += 1;
}
Force Sensor:
const int forceSensorPin = A0;

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

void loop() {
int sensorValue =
analogRead(forceSensorPin);
float force = sensorValue * (5.0 / 1023.0);
Serial.print("Force: ");
Serial.print(force);
Serial.println(" V");
delay(100);
}
Force Sensor with LED:
const int forcePin = A0;
const int ledPins[] = {2, 3, 4, 5, 6};

void setup() {
pinMode(forcePin, INPUT);
for (int i = 0; i < 5; i++) {
pinMode(ledPins[i], OUTPUT);
}
}
void loop() {
int forceValue = analogRead(forcePin);
int ledIndex = map(forceValue, 0, 1023, 0, 5);

for (int i = 0; i < ledIndex; i++) {


digitalWrite(ledPins[i], HIGH);
}
for (int i = ledIndex; i < 5; i++) {
digitalWrite(ledPins[i], LOW);
}

delay(50);
}
Multiple Tones:
const int speakerPin = 8 ;
const int speakerPin = 7 ;
const int speakerPin = 6;

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

void loop() {
tone(8, 200);
delay(500); // Play the tone for 500ms

tone(7, 600);
delay(500); // Play the tone for 500ms

tone(6, 1000);
delay(500); // Play the tone for 500ms
}
Light Range Sensor:
const int buzzerPin = 9; delay(100); // Take a reading every 100ms
const int trigPin = 10; }
const int echoPin = 11;
const int lightPin = A0; int readDistance() {
// Send a pulse to the ultrasonic sensor
void setup() { digitalWrite(trigPin, LOW);
pinMode(buzzerPin, OUTPUT); delayMicroseconds(2);
pinMode(trigPin, OUTPUT); digitalWrite(trigPin, HIGH);
pinMode(echoPin, INPUT); delayMicroseconds(10);
pinMode(lightPin, INPUT); digitalWrite(trigPin, LOW);
}
// Read the echo pulse
void loop() { int duration = pulseIn(echoPin, HIGH);
int distance = readDistance();
// Calculate the distance
int lightIntensity = int distance = duration * 0.034 / 2;
analogRead(lightPin);
return distance;
if (distance < 10 && lightIntensity }
< 500) {
tone(buzzerPin, 1000);
delay(500);
noTone(buzzerPin);
}
Digital Clock:
#include <LiquidCrystal.h>
#include <Wire.h>
#include <DS3231.h>
const int lcdRs = 12, lcdEn = 11, lcdD4 = 5, lcdD5 = 4, lcdD6 = 3, lcdD7 = 2;
LiquidCrystal_I2C lcd(lcdRs, lcdEn, lcdD4, lcdD5, lcdD6, lcdD7);
DS3231 rtc;
void setup() {
lcd.begin(20, 4);
lcd.setCursor(0, 0);
lcd.print("Digital Clock");
Wire.begin();
rtc.begin();
}
void loop() {
DateTime now = rtc.now();
lcd.setCursor(0, 1);
lcd.print(now.hour(), DEC);
lcd.print(":");
lcd.print(now.minute(), DEC);
lcd.print(":");
lcd.print(now.second(), DEC);
lcd.setCursor(0, 2);
lcd.print(now.day(), DEC);
lcd.print("/");
lcd.print(now.month(), DEC);
lcd.print("/");
lcd.print(now.year(), DEC);
delay(1000);
}
Flex Sensor:
const int flexSensorPin = A0;
const int fixedResistor = 10000;
void setup() {
Serial.begin(9600);
}

void loop() {
int sensorValue = analogRead(flexSensorPin);
float resistance = sensorValue * (fixedResistor /
1023.0);
float bendAngle = map(resistance, 0,
fixedResistor, 0, 90);
Serial.print("Bend Angle: ");
Serial.print(bendAngle);
Serial.println(" degrees");
delay(100);
}
Smoke Detector:
const int smokePin = A0; // smoke sensor pin
const int ledPin =A1; // LED pin

void setup() {
pinMode(A0, INPUT);
pinMode(A1, OUTPUT);
Serial.begin(9600);
}

void loop() {
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
if (sensorValue > 400) {
digitalWrite(A1, HIGH);
} else {
digitalWrite(A1, LOW);
}
delay(100);
}
Disco Neopixel:
#include <Adafruit_NeoPixel.h> void loop() {
// Jewel mode
#define PIN_JEWEL 6 for (int i = 0; i < NUM_PIXELS_JEWEL; i++) {
#define PIN_NEOPIXEL1 7 jewel.setPixelColor(i, jewel.Color(random(255),
#define PIN_NEOPIXEL2 8 random(255), random(255)));
#define PIN_NEOPIXEL_RING 9 }
jewel.show();
#define NUM_PIXELS_JEWEL 7 delay(50);
#define NUM_PIXELS_NEOPIXEL1 1
#define NUM_PIXELS_NEOPIXEL2 1 // NeoPixel 1 mode
#define NUM_PIXELS_NEOPIXEL_RING 6 neopixel1.setPixelColor(0,
Adafruit_NeoPixel jewel = neopixel1.Color(random(255), random(255),
Adafruit_NeoPixel(NUM_PIXELS_JEWEL, PIN_JEWEL, NEO_GRB random(255)));
+ NEO_KHZ800); neopixel1.show();
Adafruit_NeoPixel neopixel1 = delay(50);
Adafruit_NeoPixel(NUM_PIXELS_NEOPIXEL1, PIN_NEOPIXEL1,
NEO_GRB + NEO_KHZ800); // NeoPixel 2 mode
Adafruit_NeoPixel neopixel2 = neopixel2.setPixelColor(0,
Adafruit_NeoPixel(NUM_PIXELS_NEOPIXEL2, PIN_NEOPIXEL2, neopixel2.Color(random(255), random(255),
NEO_GRB + NEO_KHZ800); random(255)));
Adafruit_NeoPixel neopixelRing = neopixel2.show();
Adafruit_NeoPixel(NUM_PIXELS_NEOPIXEL_RING, delay(50);
PIN_NEOPIXEL_RING, NEO_GRB + NEO_KHZ800);
// NeoPixel Ring mode
void setup() { for (int i = 0; i < NUM_PIXELS_NEOPIXEL_RING;
jewel.begin(); i++) {
jewel.setBrightness(50); neopixelRing.setPixelColor(i,
neopixel1.begin(); neopixelRing.Color(sin(millis() * 0.001 + i * 0.1) *
neopixel1.setBrightness(50); 128 + 128, sin(millis() * 0.001 + i * 0.1 + 2 * PI /
neopixel2.begin(); 3) * 128 + 128, sin(millis() * 0.001 + i * 0.1 + 4 *
neopixel2.setBrightness(50); PI / 3) * 128 + 128));
neopixelRing.begin(); }
neopixelRing.setBrightness(50);
Servo, LCD, Ultrasonic:
void loop() {
#include <LiquidCrystal.h>
int potValue =
#include <Servo.h>
analogRead(potPin);
int angle = map(potValue, 0,
const int lcdRs = 12, lcdEn = 11, lcdD4 =
1023, 0, 180);
5, lcdD5 = 4, lcdD6 = 3, lcdD7 = 2;
servo.write(angle);
LiquidCrystal_I2C lcd(lcdRs, lcdEn, lcdD4,
lcdD5, lcdD6, lcdD7);
// Read ultrasonic sensor value
digitalWrite(trigPin, HIGH);
const int servoPin = 9;
delayMicroseconds(10);
Servo servo;
digitalWrite(trigPin, LOW);
int duration = pulseIn(echoPin,
const int trigPin = 10;
HIGH);
const int echoPin = 11;
int distance = duration * 0.034 /
2;
const int potPin = A0;
// Display distance on LCD
void setup() {
lcd.setCursor(0, 1);
lcd.begin(20, 4);
lcd.print("Distance: ");
lcd.setCursor(0, 0);
lcd.print(distance);
lcd.print("Servo, LCD, Ultrasonic");
lcd.print(" cm");
servo.attach(servoPin);
pinMode(trigPin, OUTPUT);
delay(100);
pinMode(echoPin, INPUT);
}
pinMode(potPin, INPUT);
}
Different Servo Rotations:
#include <Servo.h> void loop() {
val1 =
Servo myservo1; analogRead(potpin1);
Servo myservo2; val1 = map(val1, 0, 1023,
Servo myservo3; 0, 180
Servo myservo4; myservo1.write(val1);
int potpin1 = 0;
int potpin2 = 1; val2 =
int potpin3 = 2; analogRead(potpin2);
int potpin4 = 3; val2 = map(val2, 0, 1023,
int val1; 0, 180);
int val2; myservo2.write(val2);
int val3; val3 =
int val4; analogRead(potpin3);
void setup() { val3 = map(val3, 0, 1023,
0, 180);
myservo1.attach(9); myservo3.write(val3);
val4 =
myservo2.attach(6); analogRead(potpin4);
val4 = map(val4, 0, 1023,
myservo3.attach(5); 0, 180);
myservo4.write(val4);
RGB with Buzzer:
const int redPin = 9;
const int greenPin = 10; } else {
const int bluePin = 11; // Blue
const int buzzerPin = 12; analogWrite(redPin, 0);
const int potPin = A0; analogWrite(greenPin, 0);
analogWrite(bluePin, brightness);
void setup() { }
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT); if (potValue < 341) {
pinMode(bluePin, OUTPUT); tone(buzzerPin, 200, 100);
pinMode(buzzerPin, OUTPUT); } else if (potValue < 682) {
pinMode(potPin, INPUT); tone(buzzerPin, 400, 100);
} } else {
tone(buzzerPin, 600, 100);
void loop() { }
int potValue = analogRead(potPin);
int brightness = map(potValue, 0, 1023, delay(100);
0, 255); }

if (potValue < 341) {


// Red
analogWrite(redPin, brightness);
analogWrite(greenPin, 0);
analogWrite(bluePin, 0);
} else if (potValue < 682) {
// Green
analogWrite(redPin, 0);
analogWrite(greenPin, brightness);
analogWrite(bluePin, 0);
Theft Alaram:
const int pirPin = 2; // PIR sensor output
pin
const int buzzerPin = 3; // Buzzer pin
const int ledPin = 4; // LED pin

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

void loop() {
int pirState = digitalRead(pirPin);
if (pirState == HIGH) {
digitalWrite(buzzerPin, HIGH);
digitalWrite(ledPin, HIGH);
delay(5000); // Alarm duration (5
seconds)
digitalWrite(buzzerPin, LOW);
digitalWrite(ledPin, LOW);
}
delay(50); // Debounce delay
}
Rock Paper Scissors Game:
#include<LiquidCrystal.h void setup() delay(100); case 3:
> { noTone(12); tone(12,131);
#include <Servo.h> lcd.begin(16,2); servo_3.write(120); delay(100);
lcd.setCursor(0,0); lcd.setCursor(0,0); noTone(12);
LiquidCrystal lcd.print(" Rock Paper and lcd.print(" It's...."); servo_9.write(120);
lcd(A0,A1,A2,A3,A4,A5); "); lcd.setCursor(0,1); lcd.setCursor(0,0);
volatile long A; lcd.setCursor(0,1); lcd.print(" lcd.print(" It's....");
lcd.print(" Scissor Game "); Stone...."); lcd.setCursor(0,1);
float delay(4000); digitalWrite(red1, lcd.print("
checkdistance_11_10() lcd.clear(); HIGH); Scissor....");
{ A = 0; delay(1000); digitalWrite(red3,
digitalWrite(11, LOW); pinMode(11, OUTPUT); servo_3.write(179); HIGH);
delayMicroseconds(2); pinMode(10, INPUT); digitalWrite(red1, LOW); delay(1000);
digitalWrite(11, HIGH); pinMode(12, OUTPUT); lcd.clear(); servo_9.write(179);
delayMicroseconds(10); pinMode(red1, OUTPUT); delay(500); digitalWrite(red3,
digitalWrite(11, LOW); pinMode(red2, OUTPUT); break; LOW);
float distance = pinMode(red3, OUTPUT); case 2: lcd.clear();
pulseIn(10, HIGH) / 58.00; servo_3.attach(3); // stone tone(12,131); delay(500);
delay(10); servo_6.attach(6); // paper delay(100); break;
return distance; servo_9.attach(9); // noTone(12); }
} scissor servo_6.write(120); }
servo_3.write(179); lcd.setCursor(0,0); }
Servo servo_3; servo_6.write(179); lcd.print(" It's....");
Servo servo_6; servo_9.write(179); lcd.setCursor(0,1);
Servo servo_9; } lcd.print(" Paper....");
void loop() digitalWrite(red2,
int red1 = 2; { HIGH);
int red2 = 4; if (checkdistance_11_10() < delay(1000);
int red3 = 5; 10) { servo_6.write(179);
int speaker = 12; A = random(0, 4); digitalWrite(red2, LOW);
switch (A) { lcd.clear();
case 1: delay(500);
Range Graph:
const int trigPin = 2;
if (thisLed < ledLevel) {
const int echoPin = 3;
digitalWrite(ledPins[thisLed],
const int ledCount = 8;
HIGH);
int ledPins[] = {4, 5, 6, 7, 8, 9, 10, 11};
} else { // turn off all pins higher
void setup() {
than the ledLevel:
pinMode(trigPin, OUTPUT);
digitalWrite(ledPins[thisLed],
pinMode(echoPin, INPUT);
LOW);
for (int thisLed = 0; thisLed < ledCount;
}
thisLed++) {
}
pinMode(ledPins[thisLed], OUTPUT);
delay(50);
}
}
Serial.begin(9600);
}
void loop() {
int duration, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration * 0.034 / 2;
Serial.print("Distance: ");
Serial.print(distance);
Serial.println("cm");
int ledLevel = map(distance, 0, 400, 0,
ledCount);
for (int thisLed = 0; thisLed < ledCount;
thisLed++) {
Bidirectional Display:
#include <LiquidCrystal.h>
int in = 15; ppl = constrain(ppl, 0, 50);
int inpr = 16; lcd.setCursor(0, 0);
int out = 14; lcd.print("PEOPLE IN:");
int outpr = 17; lcd.setCursor(11, 0);
int ppl = 0; lcd.print(ppl);
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); if (ppl >= 20) {
bool pi = 0; lcd.setCursor(0, 1);
bool po = 0; lcd.print("PLEASE WAIT");
void setup() { delay(1000);
pinMode(15, INPUT); }
pinMode(14, INPUT); if (ppl <= 19) {
pinMode(16, OUTPUT); lcd.setCursor(0, 1);
pinMode(17, OUTPUT); lcd.print("PLEASE VISIT");
lcd.begin(16, 2); delay(1000);
} }
void loop() { }
lcd.clear();
digitalWrite(outpr, HIGH);
digitalWrite(inpr, HIGH);
pi = digitalRead( in );
po = digitalRead(out);
if (pi == 1) {
ppl--;
delay(500);
} else if (po == 1) {
ppl++;
delay(500);
}
Home Lighting:
#include <Adafruit_NeoPixel.h>
#define PIN 3
#define NUMPIXELS 12

Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB +


NEO_KHZ800);
const int trigPin = 5;
const int echoPin = 6;
const int buzzerPin = 2;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(buzzerPin, OUTPUT);
pixels.begin();
pixels.show();
pixels.setBrightness(50);
}
void loop() {
long duration, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW
Multiple tone with RGB:
int but1 = 2; void loop() if( b6 == 1 ){
int but2 = 3; { tone(buzzer,800,100)
int but3 = 4; int b1 = ;
int but4 = 5; digitalRead(but1); }
int but5 = 6; int b2 = if( b7 == 1 ){
int but6 = 7; digitalRead(but2); tone(buzzer,900,100)
int but7 = 8; int b3 = ;
int but8 = 9; digitalRead(but3); }
int b4 = if( b8 == 1 ){
int buzzer = 13; digitalRead(but4); tone(buzzer,1000,10
int b5 = 0);
void setup() digitalRead(but5); }
{ int b6 = delay(10);
pinMode(but1,INPUT); digitalRead(but6); }
pinMode(but2,INPUT); int b7 =
pinMode(but3,INPUT); digitalRead(but7);
pinMode(but4,INPUT); int b8 =
pinMode(but5,INPUT); digitalRead(but8);
pinMode(but6,INPUT); if( b1 == 1 ){
pinMode(but7,INPUT); tone(buzzer,300,100);
pinMode(but8,INPUT); }
pinMode(buzzer,OUTPUif( b2 == 1 ){
T); tone(buzzer,400,100);
}
} if( b3 == 1 ){
tone(buzzer,500,100);
}
Temperature Display:
#include<LiquidCrystal.h>

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7


= 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

float celsius;
int temp = A1;

void setup(){
pinMode(temp,INPUT);
}

void loop(){
celsius =
analogRead(temp)*0.004882814;
celsius = (celsius - 0.5) * 100.0;

lcd.setCursor(0,1);
lcd.print("Temp: ");
lcd.print(celsius);
lcd.print(" C");
delay(1000);
lcd.clear();
}
Smoke and Temperature
with Buzzer indicator:
const int smokePin = 2; // Smoke sensor pin
const int tempPin = 3; // Temperature sensor
pin
const int buzzerPin = 4; // Buzzer pin

void setup() {
pinMode(smokePin, INPUT);
pinMode(tempPin, INPUT);
pinMode(buzzerPin, OUTPUT);
}

void loop() {
int smokeValue = digitalRead(smokePin);
float temperature = getTemperature(tempPin);

if (smokeValue == HIGH || temperature > 30)


{
tone(buzzerPin, 1000, 200); // Buzz for
200ms
delay(500); // Wait for 500ms
}
}

float getTemperature(int tempPin) {


return temperatureValue;
}
Grass cutter:
const int switch1Pin = 2; // if (switch1State == HIGH) {
Switch 1 pin // Turn Motor 1 clockwise
const int switch2Pin = 4; // digitalWrite(motor1Pin1, HIGH);
Switch 2 pin digitalWrite(motor1Pin2, LOW);
const int motor1Pin1 = 6; // } else {
Motor 1 pin 1 // Turn Motor 1 counterclockwise
const int motor1Pin2 = 7; // digitalWrite(motor1Pin1, LOW);
Motor 1 pin 2 digitalWrite(motor1Pin2, HIGH);
const int motor2Pin1 = 8; // }
Motor 2 pin 1
const int motor2Pin2 = 9; // if (switch2State == HIGH) {
Motor 2 pin 2 // Turn Motor 2 clockwise
digitalWrite(motor2Pin1, HIGH);
void setup() { digitalWrite(motor2Pin2, LOW);
pinMode(switch1Pin, INPUT); } else {
pinMode(switch2Pin, INPUT); // Turn Motor 2 counterclockwise
pinMode(motor1Pin1, OUTPUT); digitalWrite(motor2Pin1, LOW);
pinMode(motor1Pin2, OUTPUT); digitalWrite(motor2Pin2, HIGH);
pinMode(motor2Pin1, OUTPUT); }
pinMode(motor2Pin2, OUTPUT); }
}

void loop() {
int switch1State =
digitalRead(switch1Pin);
int switch2State =
digitalRead(switch2Pin);
Buzzer with PIR Sensor:
const int pirPin = 13; // PIR sensor pin
const int buzzerPin = 3; // Buzzer pin
const int relayPin = 2; // Relay pin

void setup() {
pinMode(pirPin, INPUT);
pinMode(buzzerPin, OUTPUT);
pinMode(relayPin, OUTPUT);
}

void loop() {
int pirState = digitalRead(pirPin);

if (pirState == HIGH) {
tone(buzzerPin, 1000, 200); // Buzz for 200ms
digitalWrite(relayPin, HIGH); // Turn on the light bulb
delay(500); // Wait for 500ms
} else {
digitalWrite(relayPin, LOW); // Turn off the light bulb
}
}
Drone:
const int pwm = 9 ; digitalWrite(in_1,LOW) ;
const int in_1 = 3 ; digitalWrite(in_2,HIGH) ;
const int in_2 = 2 ; delay(3000) ;

void setup() digitalWrite(in_1,HIGH) ;


{ digitalWrite(in_2,HIGH) ;
pinMode(pwm,OUTPUT) ; delay(1000) ;
}
pinMode(in_1,OUTPUT) ;
pinMode(in_2,OUTPUT) ;
}

void loop()
{
digitalWrite(in_1,HIGH) ;
digitalWrite(in_2,LOW) ;
analogWrite(pwm,255) ;
delay(3000) ;

digitalWrite(in_1,HIGH) ;
digitalWrite(in_2,HIGH) ;
delay(1000) ;
Temperature Controlled By
Fan:
const int tempPin = 2; // Temperature lcd.setCursor(0, 0); // Set cursor to first
sensor pin row
const int relayPin = 3; // Relay pin lcd.print("Temperature: ");
const int lcdRS = 4; // LCD RS pin lcd.print(temperature);
const int lcdEN = 5; // LCD EN pin lcd.print(" C");
const int lcdD4 = 6; // LCD D4 pin
const int lcdD5 = 7; // LCD D5 pin if (temperature > 25) {
const int lcdD6 = 8; // LCD D6 pin digitalWrite(relayPin, HIGH);
const int lcdD7 = 9; // LCD D7 pin lcd.setCursor(0, 1);
lcd.print("Fan: ON");
#include <LiquidCrystal.h> } else {
digitalWrite(relayPin, LOW);
LiquidCrystal_I2C lcd(lcdRS, lcdEN, lcd.setCursor(0, 1);
lcdD4, lcdD5, lcdD6, lcdD7); lcd.print("Fan: OFF");
}
void setup() { delay(1000); // Wait for 1 second
pinMode(tempPin, INPUT); }
pinMode(relayPin, OUTPUT);
lcd.begin(16, 2); // Initialize LCD float getTemperature(int tempPin) {
display return temperatureValue;
} }

void loop() {
float temperature =
getTemperature(tempPin);
Car Parking Alerter:
const int ultrasonic1Trig = 2; void loop() {
const int ultrasonic1Echo = 3; int distance1 = getDistance(ultrasonic1Trig,
const int ultrasonic2Trig = 4; ultrasonic1Echo);
const int ultrasonic2Echo = 5; int distance2 = getDistance(ultrasonic2Trig,
ultrasonic2Echo);
const int ultrasonic3Trig = 6;
int distance3 = getDistance(ultrasonic3Trig,
const int ultrasonic3Echo = 7;
ultrasonic3Echo);
const int potPin = A0; int potValue = analogRead(potPin);
const int lcdRS = 8; lcd.setCursor(0, 0); // Set cursor to first row
const int lcdEN = 9; lcd.print("Distance 1: ");
const int lcdD4 = 10; lcd.print(distance1);
const int lcdD5 = 11; lcd.print(" cm");
const int lcdD6 = 12; lcd.setCursor(0, 1); // Set cursor to second
const int lcdD7 = 13; row
lcd.print("Distance 2: ");
#include <LiquidCrystal.h> lcd.print(distance2);
lcd.print(" cm");
LiquidCrystal_I2C lcd(lcdRS, lcdEN,
lcd.print(" Distance 3: ");
lcdD4, lcdD5, lcdD6, lcdD7);
lcd.print(distance3);
void setup() { lcd.print(" cm");
pinMode(ultrasonic1Trig, OUTPUT); lcd.setCursor(0, 2); // Set cursor to third row
pinMode(ultrasonic1Echo, INPUT); lcd.print("Pot Value: ");
pinMode(ultrasonic2Trig, OUTPUT); lcd.print(potValue);
pinMode(ultrasonic2Echo, INPUT);
pinMode(ultrasonic3Trig, OUTPUT); delay(1000); // Wait for 1 second
pinMode(ultrasonic3Echo, INPUT); }
pinMode(potPin, INPUT); int getDistance(int trigPin, int echoPin) {
lcd.begin(16, 2); digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
}
digitalWrite(trigPin,
Smart Blind Stick:
void setup()
if (dis2<100)
{
{
pinMode(12, OUTPUT);
tone(12, 700);
}
}
long duration1, dis1,duration2,
else
dis2,duration3, dis3;
{
void loop()
noTone(12);
{
}
noTone(12);
pinMode(4, OUTPUT);
pinMode(0, OUTPUT);
digitalWrite(4, LOW);
digitalWrite(0, LOW);
delayMicroseconds(2);
delayMicroseconds(2);
digitalWrite(4, HIGH);
digitalWrite(0, HIGH);
delayMicroseconds(2);
delayMicroseconds(2);
digitalWrite(4, LOW);
digitalWrite(0, LOW);
pinMode(5, INPUT);
pinMode(1, INPUT);
duration3=pulseIn(5, HIGH);
duration1=pulseIn(1, HIGH);
dis3= (duration3*0.034)/2;
dis1= (duration1*0.034)/2;
if (dis1<100)
{tone(12, 500)}
if (dis3<100)
else
{
{ noTone(12); }
tone(12, 700);
pinMode(2, OUTPUT);
}
digitalWrite(2, LOW);
else
delayMicroseconds(2);
{
digitalWrite(2, HIGH);
noTone(12);
delayMicroseconds(2);
}
digitalWrite(2, LOW);
delay(100);
pinMode(3, INPUT);
}
duration2=pulseIn(3, HIGH);
Automatic Traffic Light:
int sv = 3;
int valh = 0;
int valv = 0; int th1 = 3000;
int rv = 5; int th2 = 400;
int av = 6; int tv1 = 3000;
int vv = 7; int tv2 = 400;
int rh = 11; if (valh == HIGH && valv == LOW) {
int ah = 12; Serial.println("Aumentar
Horizontal");
int vh = 13;
th1 = th1 * 2;
void setup() th2 = th2 * 2;
{ } else if (valh == LOW && valv ==
for (int i = 5; i <= 13; i+ HIGH) {
+) { Serial.println("Aumentar Vertical");
pinMode(i, tv1 = tv1 * 2;
OUTPUT); tv2 = tv2 * 2;
} }
pinMode(sh, INPUT); semaforoHorizontal(th1, th2);
pinMode(sv, INPUT); semaforoVertical(tv1, tv2); void semaforoVertical(int t1, int t2) {
Serial.begin(9600); } digitalWrite(rh, HIGH);
void semaforoHorizontal(int t1, int t2)digitalWrite(vv, HIGH);
}
{ delay(t1);
void loop() digitalWrite(rv, HIGH);
{ digitalWrite(vv, LOW);
digitalWrite(vh, HIGH); digitalWrite(av, HIGH);
valh = digitalRead(sh); delay(t1); delay(t2);
valv = digitalRead(sv); digitalWrite(vh, LOW); digitalWrite(rh, LOW);
Serial.print("Horizontal: digitalWrite(ah, HIGH); digitalWrite(av, LOW);
"); delay(t2); }
Serial.println(valh); digitalWrite(rv, LOW);
Serial.print("Vertical: "); digitalWrite(ah, LOW);
}
Home Automation:
void loop() {
const int motorForward = 2; int pirState = digitalRead(pirPin);
const int motorBackward = 3; if (pirState == HIGH) {
const int pirPin = 4; digitalWrite(ledPin, HIGH);
const int ledPin = 13; lcd.setCursor(0, 1);
const int potPin = A0; lcd.print("Motion Detected!");
const int rs = 12, en = 11, d4 = int potValue = analogRead(potPin);
5, d5 = 4, d6 = 3, d7 = 2; int motorSpeed = map(potValue, 0, 1023, 0, 255);
LiquidCrystal_I2C lcd(rs, en, d4, analogWrite(motorForward, motorSpeed);
d5, d6, d7); lcd.setCursor(0, 2);
lcd.print("Motor Speed: ");
void setup() { lcd.print(motorSpeed);
pinMode(motorForward, } else {
OUTPUT); digitalWrite(ledPin, LOW);
pinMode(motorBackward, analogWrite(motorForward, 0);
OUTPUT); lcd.setCursor(0, 1);
pinMode(pirPin, INPUT); lcd.print("No Motion");
pinMode(ledPin, OUTPUT); lcd.setCursor(0, 2);
pinMode(potPin, INPUT); lcd.print("Motor Speed: 0");
lcd.begin(20, 4); }
lcd.setCursor(0, 0); float temperature =
lcd.print("Home Automation tempSensor.getTempCByIndex(0);
System"); lcd.setCursor(0, 3);
} lcd.print("Temperature: ");
lcd.print(temperature);
lcd.print(" C");

delay(1000);
}
Distance Finder:
#include <LiquidCrystal.h>

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 =


3, d7 = 2;
LiquidCrystal_I2C lcd(rs, en, d4, d5, d6, d7);
const int trigPin = 2;
const int echoPin = 3;
void setup() {
lcd.begin(20, 4);
lcd.setCursor(0, 0);
lcd.print("Distance Finder");
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
int duration, distance;
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = duration * 0.034 / 2;
lcd.setCursor(0, 1);
lcd.print("Distance: ");
lcd.print(distance);
lcd.print(" cm");
delay(1000);
}
Alcohol Detector:
#include <Adafruit_NeoPixel.h> uint32_t color;
if (gasValue < 200) {
#define PIN 6 color = pixels.Color(0, 255, 0); //
#define NUM_PIXELS 12 Green
} else if (gasValue < 400) {
Adafruit_NeoPixel pixels = color = pixels.Color(255, 255,
Adafruit_NeoPixel(NUM_PIXELS, 0); // Yellow
PIN, NEO_GRB + NEO_KHZ800); } else {
color = pixels.Color(255, 0, 0); //
const int gasSensorPin = A0; Red
}
void setup() {
pixels.begin(); // Set pixel color
pixels.setBrightness(50); for (int i = 0; i < NUM_PIXELS; i+
pinMode(gasSensorPin, INPUT);+) {
} pixels.setPixelColor(i, color);
}
void loop() { pixels.show();
int gasValue =
analogRead(gasSensorPin); delay(1000);
Serial.print("Gas Value: "); }
Serial.println(gasValue);
Sign Language Translation:
void loop() { boolean
#include <LiquidCrystal.h> for (int i = 0; i < 5; i++) { matchFlexSensorReading
flexSensorReadings[i] = s(int
const int flexSensorPins[] = {A0, analogRead(flexSensorPins[i]); flexSensorReadings[],
A1, A2, A3, A4}; } String
signLanguageTranslation = signLanguageCode) {
// Define the pins for the LCD translateSensorReadings(flexSensorRea for (int i = 0; i < 5; i++)
display dings); {
const int lcdRS = 12; if
const int lcdEN = 11; lcd.setCursor(0, 0); (flexSensorReadings[i] >
const int lcdD4 = 5; lcd.print(signLanguageTranslation); 500 &&
const int lcdD5 = 4; signLanguageCode.charA
const int lcdD6 = 3; Serial.println(signLanguageTranslation); t(i) == '1') {
const int lcdD7 = 2; continue;
delay(100); } else if
int flexSensorReadings[5]; } (flexSensorReadings[i]
<= 500 &&
String signLanguageTranslation String translateSensorReadings(int signLanguageCode.charA
= ""; flexSensorReadings[]) { t(i) == '0') {
String signLanguageDictionary[][2] = { continue;
LiquidCrystal_I2C lcd(lcdRS, {"hello", "01010"}, } else {
lcdEN, lcdD4, lcdD5, lcdD6, {"goodbye", "10101"}, return false;
lcdD7); {"thank you", "11011"}, }
}; }
void setup() { for (int i = 0; i < 3; i++) { return true;
Serial.begin(9600); if }
(matchFlexSensorReadings(flexSensorR
lcd.begin(16, 2); eadings, signLanguageDictionary[i][1]))
} {
return signLanguageDictionary[i][0];
}
}
Food Reduction System:
#include <LiquidCrystal.h> void loop() {
#include <DallasTemperature.h> int gasValue = analogRead(gasSensorPin);
Serial.print("Gas Value: ");
const int lcdRs = 12, lcdEn = 11, Serial.println(gasValue);
lcdD4 = 5, lcdD5 = 4, lcdD6 = 3,
lcdD7 = 2; float temperature =
LiquidCrystal_I2C lcd(lcdRs, lcdEn, tempSensor.getTempCByIndex(0);
lcdD4, lcdD5, lcdD6, lcdD7); Serial.print("Temperature: ");
Serial.print(temperature);
const int gasSensorPin = A0; Serial.println(" C");
const int tempSensorPin = 2;
const int potPin = A1; int potValue = analogRead(potPin);
Serial.print("Potentiometer Value: ");
DallasTemperature Serial.println(potValue);
tempSensor(tempSensorPin);
// Display values on LCD
void setup() { lcd.setCursor(0, 1);
lcd.begin(20, 4); lcd.print("Gas: ");
lcd.setCursor(0, 0); lcd.print(gasValue);
lcd.print("Environmental Monitor"); lcd.setCursor(0, 2);
pinMode(gasSensorPin, INPUT); lcd.print("Temp: ");
pinMode(tempSensorPin, INPUT); lcd.print(temperature);
pinMode(potPin, INPUT); lcd.print(" C");
tempSensor.begin(); lcd.setCursor(0, 3);
} lcd.print("Pot: ");
lcd.print(potValue);

delay(1000);
}
Gas Alarm:
const int gasSensorPin = A0;
const int buzzerPin = 9;
const int ledPin = 2; // or A1 for LED

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

void loop() {
int gasValue = analogRead(gasSensorPin);
Serial.print("Gas Value: ");
Serial.println(gasValue);

if (gasValue > 400) { // adjust threshold value as needed


tone(buzzerPin, 1000, 500); // play alarm sound
digitalWrite(ledPin, HIGH); // turn on LED
} else {
noTone(buzzerPin); // stop alarm sound
digitalWrite(ledPin, LOW); // turn off LED
}

delay(1000);
}
Simple counter:
const int buttonPin = 9;
int digit = digits[number % 10];
const int digitPins[] = {2, 3, 4, 5, 6, 7, 8};
int value = digitValues[digit];
int count = 0
void setup() {
pinMode(buttonPin, INPUT); for (int i = 0; i < 7; i++) {
for (int i = 0; i < 7; i++) { digitalWrite(digitPins[i], (value & (1 << i)) ? HIGH :
pinMode(digitPins[i], OUTPUT); LOW);
} }
} }
void loop() {
int buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
count++;
displayNumber(count);
delay(500); // debounce delay
}
delay(100);
}
void displayNumber(int number) {
int digits[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int digitValues[] = {
0b0111111, // 0
0b0000110, // 1
0b1011011, // 2
0b1001111, // 3
0b1100110, // 4
0b1101101, // 5
0b1111101, // 6
0b0000111, // 7
0b1111111, // 8
0b1101111 // 9
};

You might also like