0% found this document useful (0 votes)
28 views

Da 2

This document summarizes three Arduino lab assignments completed by Suyash Agarwal using Tinkercad. The first assignment involved using an ultrasound sensor, LED display and 7 segment display to measure and display distance in cm and inches. The second used a gas sensor and buzzer to detect smoke and trigger an alarm. The third used a potentiometer to control the brightness of an LED.

Uploaded by

suyash agarwal
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)
28 views

Da 2

This document summarizes three Arduino lab assignments completed by Suyash Agarwal using Tinkercad. The first assignment involved using an ultrasound sensor, LED display and 7 segment display to measure and display distance in cm and inches. The second used a gas sensor and buzzer to detect smoke and trigger an alarm. The third used a potentiometer to control the brightness of an LED.

Uploaded by

suyash agarwal
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/ 7

LAB ASSIGNMENT 2

(Tinkercad)

By- Suyash Agarwal


20BBS0123
Q1 Distance

Tinkercad link= https://www.tinkercad.com/things/31iswT0vilD

Packages used:-
1. #include "Adafruit_LEDBackpack.h"
2. #include <Adafruit_LiquidCrystal.h>

Sensors used:-
1. Ultrasound sensor
2. 16X2 led display
3. 7 segment Clock display
Code:-
#include "Adafruit_LEDBackpack.h"
#include <Adafruit_LiquidCrystal.h>

//suyash 20BBS0123
Adafruit_LiquidCrystal lcd_1(0);

float cm = 0;

Adafruit_7segment led_display1 = Adafruit_7segment();


long readUltrasonicDistance(int triggerPin, int echoPin)
{
pinMode(triggerPin, OUTPUT);
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
pinMode(echoPin, INPUT);
return pulseIn(echoPin, HIGH);
}

void setup()
{
Serial.begin(9600);
led_display1.begin(112);
lcd_1.begin(16, 2);
}

void loop()
{
cm = 0.01723 * readUltrasonicDistance(7, 7);
delay(100);
Serial.println(cm);
led_display1.println(cm);
led_display1.writeDisplay();
lcd_1.setCursor(0, 0);
lcd_1.print("Cm =");
lcd_1.setCursor(4, 0);
lcd_1.print(cm);

float inch=0.3937*cm;

lcd_1.setCursor(0, 1);
lcd_1.print("inch =");
lcd_1.setCursor(6, 1);
lcd_1.print(inch);

delay(100);
}
Q2 Smoke alarm

Tinkercad link= https://www.tinkercad.com/things/4LRhyCv0Y3x

Sensors used:-
1. Buzzer
2. Gas sensor
Code:-
// C++ code
// Suyash Agarwal 20BBS0123
#define BUZZER_PIN 13
#define PIN_GAS A3

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

void loop()
{
int value = analogRead(PIN_GAS);
if (value>=100){
tone(BUZZER_PIN, 250);
}
if(value<100)
{
noTone(BUZZER_PIN);
}

Serial.println(analogRead(PIN_GAS));
delay(250);
}
Q3 Control using potentiometer

Tinkercad link= https://www.tinkercad.com/things/f2rIGkX5Yx3

Objects used:-
1. Potentiometer
2. Led
Code:-
int a = 0;
int b = 0;

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

void loop()
{
a = analogRead(A0);
b = map(a, 0, 1023, 0, 255);
analogWrite(9, b);

You might also like