hallo pals , am a new guy to this programming and i am in issues here ...kindly may someone write a code using arduino uno , two ultrasonic sensors and lcd 20 by 4 lines .. i want to av a bin that writes BIN USABLE
wen it senses any approaching user within a distnce of 2m....and at the same time open the bin using a servo....the second sensor sees the level of litter and wen the bin is full it writes USE NEXT BIN KINDLY, BIN FULL
on the lcd.... please help me out fwends
please help me out fwends
This forum is not a code writing service (unless you post in the Gigs and Collaborations section)
Why don't you try to do it yourself and come back if/when you have problems.
patrix:
hallo pals , am a new guy to this programming and i am in issues here ...kindly may someone write a code using arduino uno , two ultrasonic sensors and lcd 20 by 4 lines .. i want to av a bin that writesBIN USABLE
wen it senses any approaching user within a distnce of 2m....and at the same time open the bin using a servo....the second sensor sees the level of litter and wen the bin is full it writesUSE NEXT BIN KINDLY, BIN FULL
on the lcd.... please help me out fwends
we are here to help you avoid mistakes and to help you when you need a hand.
the typical path is that you write out your step-by-step wants.
measure distance
display on LCD
turn on servo when level is at X
turn off servo when level is at Y
then, you get the parts needed and do step #1
get the sensor to work.
have problems ? tell us what went wrong, what you did, and we should be able to help you learn and help you make it work.
there are lots of sites that will get you working with your ultra-sonic sensor.
I think the most common library is the newping library.
google search for arduino newping
and you should find lots of help with step #1
As a note, if it is not working, but is seems like it should..... increase the delaymicroseconds to about 29. the newer sensors need a bit more time to work.
well, i tried this :
//LCD
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4);
//Ultrasonic variable and pins declaration
int trigPin1 = 9 ;
int echoPin1 = 10 ;
int trigPin2 = 11 ;
int echoPin2 = 12 ;
int servo = 13;
int BUZZER = 8;
int i=0;
float dist, duration;
void setup(){
//LCD
Serial.begin(9600);
lcd.init();
lcd.backlight();
//HC-SR04 proximity1
pinMode (trigPin1, OUTPUT);
pinMode (echoPin1, INPUT);
//HC-SR04 proximity2
pinMode (trigPin2, OUTPUT);
pinMode (echoPin2, INPUT);
pinMode (BUZZER,OUTPUT);
pinMode (servo,OUTPUT);
lcd.setCursor(1,0);
lcd.print("welcome,");
lcd.print("save envnt ");
lcd.setCursor(1,2);
lcd.print("bin usable");
delay(20000);
}
void loop()
{
//READ DATA FOR THE ULTRASONIC
digitalWrite ( trigPin1, LOW );
delayMicroseconds ( 5 );
digitalWrite ( trigPin1, HIGH );
delayMicroseconds ( 10 );
digitalWrite ( trigPin1, LOW );
pinMode ( echoPin1, INPUT );
duration = pulseIn( echoPin1, HIGH );
// convert the time into a distance
dist = ( duration / 2 ) / 29.11 ;
Serial.print(dist);
Serial.println(". ");
delay(3000);
digitalWrite ( trigPin2, LOW );
delayMicroseconds ( 5 );
digitalWrite ( trigPin2, HIGH );
delayMicroseconds ( 10 );
digitalWrite ( trigPin2, LOW );
pinMode ( echoPin2, INPUT );
duration = pulseIn( echoPin2, HIGH );
dist = (duration/2) / 29.1; //obtain distance
}
dist=(aver[0]+aver[1]+aver[2])/3; //average distance by 3 measurements
if ( dist<50 ) {
//if hand on the distance 10...30 cm
servo.attach(servoPin);
delay(1);
servo.write(90);
delay(5000); //wait 5 seconds
servo.write(0);
delay(1000);
servo.detach();
}
Serial.print(dist);
}
delay(1000);
{
// convert the time into a distance
}
void clear_lcd();
lcd.clear();
delay(50);
lcd.setCursor(1,0);
lcd.print("use next bin");
digitalWrite ( BUZZER, HIGH );
delay(3000);
digitalWrite ( BUZZER, LOW );
delay(30000);
}
now try this:
Perhaps you might try a little harder and get your code at least to compile.
You have a lot of code which is outside any function and that's not allowed. Check your braces {}. Perhaps you have just finished loop() way too early.
Also you are using variables that you have not defined anywhere. You have a function 'void clear_lcd();' that does nothing because of that ;. But that doesn't really matter because it's never called from anywhere. You read the distance from the first ultrasonic sensor then just throw it away and use the same variables for the second sensor. And there's nothing in loop() that makes any attempt to write "BIN USABLE" to the LCD.
Steve
Speaking of which, you need to go and read the forum instructions so that you can go back and modify your original post (not re-post it) - using the "More -> Modify" option below the right hand corner of your post - to mark up your code as such using the "</>" icon in the posting window. Just highlight each section of code (or output if you need to post that) from the IDE and click the icon. In fact, the IDE has a "copy for forum" link to put these markings on a highlighted block for you so you then just paste it here in a posting window.
It is inappropriate to attach it as a ".ino" file. People can usually see the mistakes directly and do not want to have to actually load it in their own IDE. And that would also assume they are using a PC and have the IDE running on that PC.
But don't forget to use the "Auto-Format" (Ctrl-T) option first to make it easy to read. If you do not post it as "code", it can be quite garbled and is always more difficult to read.
Also tidy up your blank space. Do use blank lines, but only between functional blocks.