Hello to all,
I am working on a project that uses the ky-008 sensors and receivers. I have them wired up and want them to count and display values on my lcd.
I am having 2 problems at the moment,
First my count only goes to 9, and displays letters a, b, c, d, .... for ever count value.
Second, i can only get one counter working at a time. I believe its in the structure of my if statement, but i am still new and just cant seem to understand why. Any help advice or guidance is appreciated.
code posted below:
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
int Laser1 = 6;
int Detector1 = 7;
int Laser2 = 8;
int Detector2= 9;
char x=0;
char y=0;
void setup()
{
// put your setup code here, to run once:
Serial.begin (9600);
lcd.begin(16,2);
pinMode(Laser1, OUTPUT);
pinMode(Laser2, OUTPUT);
pinMode(Detector1, INPUT);
pinMode(Detector2, INPUT);
}
void loop() {
lcd.clear();
digitalWrite(Laser1, HIGH);
digitalWrite(Laser2, HIGH);
int val1 = digitalRead(Detector1);
delay(200);
if (val1==0)
{x++;
lcd.setCursor(0,0);
lcd.print("Quarters");
delay(2000);
lcd.setCursor(0,1);
itoa(x, "outputx",33);
lcd.print("outputx");
delay(2000);
Serial.println("outputx");}
else
{x=x;
}
int val2 = digitalRead(Detector1);
delay(200);
if (val2==0)
{y++;
lcd.setCursor(0,0);
lcd.print("Dimes");
delay(2000);
lcd.setCursor(0,1);
itoa(y, "outputy",33);
lcd.print("outputy");
delay(2000);
Serial.println("outputy");}
else
{y=y;}}