Sunday, June 21, 2020



               How-to-measure-distance-with-arduino
















Ultrasonic sensors are great tools to measure distance without actual contact and used at several places like water level measurement, distance measurement etc. This is an efficient way to measure small distances precisely. In this project we have used an Ultrasonic Sensor to determine the distance of an obstacle from the sensor. Basic principal of ultrasonic distance measurement is based on ECHO. When sound waves are transmitted in environment then waves are return back to origin as ECHO after striking on the obstacle. So we only need to calculate the travelling time of both sounds means outgoing time and returning time to origin after striking on the obstacle. As speed of the sound is known to us, after some calculation we can calculate the distance.   


code.............




Vss = Arduino GND
VDD = Arduino 5V
V0 = Potentiometer center pin
RS = Digital pin  1
RW = Arduino GND
E = Digital pin 2
D4 = Arduino digital pin 3
D5  = Arduino digital pin 4
D6 = Arduino digital pin 5
D7 = Arduino digital pin 6
A = Arduino  5V
K = Arduino GND
Ultrasonic GND = Arduino GND
Ultrasonic 5V = Arduino 5V
Ultrasonic Echo = Arduino digital pin 8
Ultrasonic trig =  Arduino digital pin 9
Potentiometer left pin = Arduino 5V
Potentiometer right pin = Arduino GND

Code:-


#include <LiquidCrystal.h> // includes the LiquidCrystal Library
LiquidCrystal lcd(1, 2, 3, 4, 5, 6); // Creates an LCD object. Parameters:
 (rs, enable, d4, d5, d6, d7) 
const int trigPin = 8;
const int echoPin = 9;
long duration;
int distanceCm, distanceInch;




void setup() {
lcd.begin(16,2); // Initializes the interface to the LCD screen, and specifies the dimensions (width and height) of the display
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}




void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distanceCm= duration*0.034/2;
distanceInch = duration * 0.01330 / 2;
lcd.setCursor(0,0); // Sets the location at which subsequent text written to the LCD will be displayed
lcd.print("Distance: "); // Prints string "Distance" on the LCD
lcd.print(distanceCm); // Prints the distance value from the sensor
lcd.print(" cm");
delay(10);
lcd.setCursor(0,1);
lcd.print("Distance: ");
lcd.print(distanceInch);
lcd.print(" inch");
delay(10);

}

Sunday, June 7, 2020

Smart Dustbin  Arduino



In this project, I will show you How to Make a Smart Dustbin using Arduino,
where the lid of the dustbin will automatically open when you approach with trash. 
The other important components used to make this Smart Dustbin are an Ultrasonic Sensor and 
Servo Motor.

Arduino UNO 
Ultrasonic Sensor Module  
 Servo Motor  
Connecting Wires 
5V Power Supply  




Code
 Servo servo;   
int trigPin = 5;   
int echoPin = 6; 
int servoPin = 7;
int led= 10;
long duration, dist, average; 
long aver[3];   //array for average


void setup() {     
    Serial.begin(9600);
    servo.attach(servoPin); 
    pinMode(trigPin, OUTPUT); 
    pinMode(echoPin, INPUT); 
    servo.write(0);         //close cap on power on
    delay(100);
    servo.detach();
}

void measure() { 
 digitalWrite(10,HIGH);
digitalWrite(trigPin, LOW);
delayMicroseconds(5);
digitalWrite(trigPin, HIGH);
delayMicroseconds(15);
digitalWrite(trigPin, LOW);
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
dist = (duration/2) / 29.1;    //obtain distance
}
void loop() {
  for (int i=0;i<=2;i++) {   //average distance
    measure();             
   aver[i]=dist;           
    delay(10);              //delay between measurements
  }
 dist=(aver[0]+aver[1]+aver[2])/3;   

if ( dist<50 ) {
//Change distance as per your need
 servo.attach(servoPin);
  delay(1);
 servo.write(0); 
 delay(3000);     
 servo.write(150);   
 delay(1000);
 servo.detach();     
}
Serial.print(dist);
}

                How-to-measure-distance-with-arduino Ultrasonic sensors are great tools to measure distance withou...