Da 2
Da 2
(Tinkercad)
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;
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
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
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);