hi so i was trying to use the sensor for detecting bank notes for my project
but when i tried putting stuff for it to detect, the led at the sensor did turned on but the value in the serial monitor is still 1
is there any way i could fix this?
The problem is probably in the sketch that you did not post, the circuit that we know nothing about, the physical layout of devices or the sensor that we have no details of. To add to that we don't know how the project is powered or which Arduino board you are using
Not with your level of experience.
The forum would like to help, but it can't. You have given only 1% of the information the forum would need in order to help.
Suggest you read the forum guide in the sticky post at the top of most forum sections.
my bad,
the board im using is arduino mega r3
the code is kinda lengthy but here,
(i only have problems with ir sensor for now)
#include <Adafruit_I2CRegister.h>
#include <Adafruit_SPIDevice.h>
#include <Adafruit_BusIO_Register.h>
#include <Adafruit_TCS34725.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#include <EEPROM.h>
#include <Servo.h>
//calculations
int paid = 0; int price = 0; int change = 0; int remainder = 0;
//keypad
char key ; int value; bool l00p = false; int digit = 0;
//coin to be given back
int coin10 = 0; int coin5 = 0; int coin2 = 0; int coin1 = 0;
//stock
int stock1 = EEPROM.read(1); int stock2 = EEPROM.read(2);
int stock5 = EEPROM.read(5); int stock10 = EEPROM.read(10);
//ir sensor
int ir1 = 22; int ir2 = 23; int ir5 = 24; int ir10 = 25; int irB = 26;
//ir read
int irst1 = digitalRead(ir1); int irst2 = digitalRead(ir2);
int irst5 = digitalRead(ir5); int irst10 = digitalRead(ir10);
int irstB = digitalRead(irstB);
//motor
int input1 = 27; int input2 = 28; //motor A
int input3 = 29; int input4 = 30; //motor B
//keypad
byte rowpin[4]={9,8,7,6};
byte colpin[4]={5,4,3,2};
char keyz[4][4]={
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
Keypad kpd=Keypad(makeKeymap(keyz), rowpin, colpin, 4, 4);
//liquidcrystal
LiquidCrystal_I2C lcd(0x27, 16, 2);
//tcs34725
Adafruit_TCS34725 tcs = Adafruit_TCS34725();
//servo
Servo servo1 ;
Servo servo2 ;
Servo servo5 ;
Servo servo10 ;
void setup()
{
//servo
servo1.attach(10); servo2.attach(11);
servo5.attach(12); servo10.attach(13);
//printing
Serial.begin(9600);
lcd.backlight(); lcd.init(); Serial.println(l00p);
//pinMode
pinMode(ir1, INPUT); pinMode(ir2, INPUT);
pinMode(ir5, INPUT); pinMode(ir10, INPUT);
pinMode(input1, OUTPUT); pinMode(input2, OUTPUT);
pinMode(input3, OUTPUT); pinMode(input4, OUTPUT);
//lcd print
lcd.setCursor(0, 0); lcd.print("A : calculate ");
lcd.setCursor(0, 1); lcd.print("B : view stock"); //choices
}
void loop()
{
key = kpd.getKey();
Serial.print(key);
if(key == 'A'){
Serial.println("A pressed");
lcd.clear();
inputPage();
} else if (key == 'B'){
Serial.println("B pressed");
Serial.println(l00p);
lcd.clear();
stockPage();
}
}
//CASE A
// insert money and set price page
int inputPage(){
lcd.setCursor(0, 0); lcd.print("price : "); Serial.println("inputPage");
lcd.setCursor(0, 1); lcd.print("paid : ");
l00p = false;
while (l00p == false){
delay(100);
lcd.setCursor(8, 0); lcd.print(price);
lcd.setCursor(8, 1); lcd.print(paid);
irstB = digitalRead(irstB); Serial.println(irstB);
if (irstB == 0){
Serial.println("bank detected!!!");
digitalWrite(input2, 1); digitalWrite(input3, 1);
bankDetect(); delay(20000);
digitalWrite(input2, 0); digitalWrite(input3, 0);
}
key = kpd.getKey(); charToInt();
if (key != NO_KEY ){
if (key >= '0' && key <= '9'){
numberAdd();
}
}
if (key == '*'){
l00p = true; lcd.clear(); delay(100); setup();
}
if (paid > price){
l00p = true; changePage();
}
}
}
//char to int
int charToInt(){
if (key >= '0' && key <= '9'){
value = key - '0';
}
}
//money addition
int numberAdd(){
if (digit == 0){ //ones digit
if (price == 0){
price = value ; digit++; Serial.println(digit);
}
} else if (digit < 3) {
if (price < 100){
price = price * 10 + value ; digit++; Serial.println(digit);
}
}
Serial.println("NumberAdd");
}
//detect bank with tcs
int bankDetect(){
uint16_t r, g, b, c, colorTemp, lux;
tcs.getRawData(&r, &g, &b, &c);
colorTemp = tcs.calculateColorTemperature(r, g, b);
lux = tcs.calculateLux(r, g, b);
if (g > b && g > r){ //green bank
paid = paid + 20; Serial.println("20 baht bank");
} else if (b > g && b > r){ //blue bank
paid = paid + 50; Serial.println("50 baht bank");
} else if (r > g && r > b){ //red bank
paid = paid + 100; Serial.println("100 baht bank");
}
}
//change calculation page
int changePage(){
Serial.println("changePage");
lcd.clear(); lcd.setCursor(0,0); lcd.print("change = ");
change = paid-price; lcd.print(change); remainder = change;
coin10 = remainder/10 ; Serial.println(coin10); //amount of 10b coins
remainder %= 10 ; //amount of leftover coins
coin5 = remainder/5 ; Serial.println(coin5); //amount of 5b coins
remainder %= 5 ; //amount of leftover coins
coin2 = remainder/2 ; Serial.println(coin2); //amount of 2b coins
remainder %= 2 ; //amount of leftover coins
coin1 = remainder/1 ; Serial.println(coin1); //amount of 1b coins
remainder %= 1 ; //amount of leftover coins
changePrint();
if (key == '*'){
lcd.clear(); delay(100); inputPage(); reset();
}
}
//change giver
int changePrint(){
l00p = false;
changeGiver();
while (l00p == false){
Serial.println("changePrint");
lcd.setCursor(0,0); lcd.print("change = "); lcd.print(change); lcd.setCursor(12,0); lcd.print("B");
lcd.setCursor(0,1); lcd.print("10B="); lcd.setCursor(4,1); lcd.print(coin10);
lcd.setCursor(10,1); lcd.print("5B="); lcd.setCursor(13,1); lcd.print(coin5);
delay(100);
lcd.setCursor(0,1); lcd.print(" 2B="); lcd.setCursor(4,1); lcd.print(coin2);
lcd.setCursor(10,1); lcd.print("1B="); lcd.setCursor(13,1); lcd.print(coin1);
delay(100);
key = kpd.getKey();
if (key == '#'){
l00p = true;
successPage();
}
}
}
int changeGiver(){
if (coin1 > 0){
for (int i = coin1; i >= 0; i--){
servo1.write(130); delay(1000); stock1--; EEPROM.update(1, stock1); Serial.print(stock1);
}
} else if (coin2 > 0){
for (int i = coin2; i >= 0; i--){
servo2.write(130); delay(1000); stock2--; EEPROM.update(2, stock2); Serial.print(stock2);
}
} else if (coin5 > 0){
for (int i = coin5; i >= 0; i--){
servo5.write(130); delay(1000); stock5--; EEPROM.update(5, stock5); Serial.print(stock5);
}
} else if (coin10 > 0){
for (int i = coin10; i >= 0; i--){
servo10.write(130); delay(1000); stock10--; EEPROM.update(10, stock10); Serial.print(stock10);
}
}
}
//CASE B
int stockPage(){
l00p = false;
while (l00p == false){
lcd.setCursor(0,0); lcd.print("1:");
lcd.setCursor(2,0); lcd.print(coin1);
lcd.setCursor(4,0); lcd.print("/60 ");
lcd.setCursor(8,0); lcd.print(" 2:");
lcd.setCursor(11,0); lcd.print(coin2);
lcd.setCursor(13,0); lcd.print("/40");
lcd.setCursor(0,1); lcd.print("5:");
lcd.setCursor(2,1); lcd.print(coin5);
lcd.setCursor(4,1); lcd.print("/36");
lcd.setCursor(8,1); lcd.print("10:");
lcd.setCursor(11,1); lcd.print(coin10);
lcd.setCursor(13,1); lcd.print("/30");
coinAdd();
key = kpd.getKey();
Serial.println(l00p);
Serial.println(key); Serial.println("stockPage message shown");
if (key == '#'){
l00p = true;
Serial.println("back to main menu"); successPage();
}
}
}
//coinAdd
int coinAdd(){
if (irst1 == 1){
stock1++; EEPROM.update(1, stock1); delay(100);
}
if (irst2 == 1){
stock2++; EEPROM.update(2, stock2); delay(100);
}
if (irst5 == 1){
stock5++; EEPROM.update(5, stock5); delay(100);
}
if (irst10 == 1){
stock10++; EEPROM.update(10, stock10); delay(100);
}
}
//shows success then go to main menu
int successPage(){
lcd.clear(); Serial.print("main menu");
lcd.setCursor(0,0); lcd.print("returning to");
lcd.setCursor(0,1); lcd.print("main menu...");
delay(500); reset(); setup();
}
//returns to deafult
int reset(){
Serial.println("reset");
paid = 0; price = 0; change = 0; remainder = 0;
value = 0; l00p = true; digit = 0;
coin10 = 0; coin5 = 0; coin2 = 0; coin1 = 0;
stock1 = EEPROM.read(1); stock2 = EEPROM.read(2);
stock5 = EEPROM.read(5); stock10 = EEPROM.read(10);
}
for the circuit it looks something like this (keep in mind the board is uno mega r3 and not 2 uno r3 and also the 9v battery is replaced)
Have look at that last line above.
wow, thank you
The same mistake is also repeated later on, in the function inputPage().
works properly now, thanks!
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.