ULTRA SONIC DISTANCE FINDER
Let's do this
This is a very simple project
This is a very simple project
Supplies
1x arduino
1x lcd display
1x potentiometer
1x HC-05 Ultra sonic sensor
Jumper wires
Bread board
1x lcd display
1x potentiometer
1x HC-05 Ultra sonic sensor
Jumper wires
Bread board
Connection
Connect the lcd , hc-05 and arguing as per the scheamatic above.
Coding
#include
#include
int contrast=75;
LiquidCrystal lcd(12,11,5,4,3,2);
#define redPin 9
#define greenPin 10
#define bluePin 8
// Arduino pin numbers
const int SWpin = 6; // digital pin connected to switch output
const int Xpin = 0; // analog pin connected to X output
const int Ypin = 1; // analog pin connected to Y output
int r,b,g,a,n;
void setup() {
pinMode(SWpin, INPUT);
digitalWrite(SWpin, HIGH);
lcd.begin(16,2);
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
r=0;
b=127;
g=0;
a=0;
}
void loop() {
if(digitalRead(SWpin)==0)
{
a=a+1;
};
if(a==4)
{
a=1;
};
switch(a)
{
case 1:
lcd.clear();
lcd.print("Red: ");
n=analogRead(Ypin);
if(n==0&r>0)
{
r=r-1;
}
if(n>1000&r<225)
{
r=r+1;
}
lcd.print(r);
setColor(r,g,b);
break;
case 2:
lcd.clear();
lcd.print("Blue: ");
n=analogRead(Ypin);
if(n==0&b>127)
{
b=b-1;
}
if(n>1000&b<225)
{
b=b+1;
}
lcd.print(b);
setColor(r,g,b);
break;
case 3:
lcd.clear();
lcd.print("Green:");
n=analogRead(Ypin);
if(n==0&g>0)
{
g=g-1;
}
if(n>1000&g<225)
{
g=g+1;
}
lcd.print(g);
setColor(r,g,b);
break;
}
delay(100);
}
void setColor(int red, int green, int blue)
{
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}
#include
int contrast=75;
LiquidCrystal lcd(12,11,5,4,3,2);
#define redPin 9
#define greenPin 10
#define bluePin 8
// Arduino pin numbers
const int SWpin = 6; // digital pin connected to switch output
const int Xpin = 0; // analog pin connected to X output
const int Ypin = 1; // analog pin connected to Y output
int r,b,g,a,n;
void setup() {
pinMode(SWpin, INPUT);
digitalWrite(SWpin, HIGH);
lcd.begin(16,2);
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
r=0;
b=127;
g=0;
a=0;
}
void loop() {
if(digitalRead(SWpin)==0)
{
a=a+1;
};
if(a==4)
{
a=1;
};
switch(a)
{
case 1:
lcd.clear();
lcd.print("Red: ");
n=analogRead(Ypin);
if(n==0&r>0)
{
r=r-1;
}
if(n>1000&r<225)
{
r=r+1;
}
lcd.print(r);
setColor(r,g,b);
break;
case 2:
lcd.clear();
lcd.print("Blue: ");
n=analogRead(Ypin);
if(n==0&b>127)
{
b=b-1;
}
if(n>1000&b<225)
{
b=b+1;
}
lcd.print(b);
setColor(r,g,b);
break;
case 3:
lcd.clear();
lcd.print("Green:");
n=analogRead(Ypin);
if(n==0&g>0)
{
g=g-1;
}
if(n>1000&g<225)
{
g=g+1;
}
lcd.print(g);
setColor(r,g,b);
break;
}
delay(100);
}
void setColor(int red, int green, int blue)
{
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}
Video YOUTUBE
https://youtu.be/5f5YZDTalh0