Hello, im working a simple project, calculating xray film density
but im facing problem at the begining, the sensor reading not dispaying zero, the value is 0.44
im using photodiode as a sensor, and IR light as a light source.
how to make it zero at first?
this is the sketch
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
#include <math.h>
int buttonPin = A1; //untuk kaki tombol start pada arduino (A1)
int buttonState = 0; //keadaan saat tombol 0
int lastButtonState = 0; //keadaan sebelum tombol 0
int buttonPushCounter = 0;
void setup() {
lcd.begin(16,2);
Serial.begin(9600);
lcd.setCursor(6, 0);
lcd.print("ALAT");
lcd.setCursor(3, 1);
lcd.print("DENSITOMETER");
delay(2000);
lcd.clear();
lcd.setCursor(4, 0);
lcd.print("BERBASIS");
lcd.setCursor(3, 1);
lcd.print("ARDUINO UNO");
delay(2000);
lcd.clear();
lcd.setCursor(4, 0);
lcd.print("--OLEH--");
delay(2000);
lcd.clear();
lcd.setCursor(2, 0);
lcd.print("FIRDA ASMITA");
lcd.setCursor(5, 1);
lcd.print("14.023");
delay(2000);
lcd.clear();
lcd.setCursor(2, 0);
lcd.print("PEMBIMBING I");
delay(2000);
lcd.clear();
lcd.setCursor(1, 0);
lcd.print("IR. Risnawaty");
lcd.setCursor(3, 1);
lcd.print("Aliyah, MT");
delay(2000);
lcd.clear();
lcd.setCursor(2, 0);
lcd.print("PEMBIMBING II");
delay(2000);
lcd.clear();
lcd.setCursor(2, 0);
lcd.print("Wahyu Ikhra");
lcd.setCursor(0, 1);
lcd.print("Wirawan, Amd.Tem");
delay(2000);
lcd.clear();
}
void loop() {
lcd.setCursor(2,0); // lcd.setCursor untuk meletakkan baris dan kolom huruf pada LCD
lcd.print("Tekan Start"); //lcd.print untuk menampilkan text pada sebuah LCD 2x16
buttonState = digitalRead(buttonPin); // membaca nilai tombol tekan (sensor digital)
if (buttonState != lastButtonState) { // jika nilai sekarang tidak sama dengan nilai terakhir
if (buttonState == HIGH) { //nilai sekarang sama dengan HIGH tau logika 1
buttonPushCounter++;
lcd.clear();
}
}
lastButtonState = buttonState;
if (buttonPushCounter % 2 == 0){
lcd.clear();
lcd.setCursor(1,0);
lcd.print("DENSITAS FILM");
int PD = analogRead(A0); // nilai x dalam bentuk data ADC
float SensOut = PD*(5/1024.0); // nilai x dalam bentuk tegangan (volt)
float hasil = (0.6883*SensOut)+0.4416);
//float hasil = -log10(10.23 /PD);
Serial.print(hasil);
lcd.setCursor(5,1);
lcd.print(hasil);
lcd.setCursor(10,1);
lcd.print("OD");
delay(100);
}
}
so you do this math to calculate hasil which I assume is your value
int PD = analogRead(A0); // nilai x dalam bentuk data ADC
float SensOut = PD*(5/1024.0); // nilai x dalam bentuk tegangan (volt)
float hasil = (0.6883*SensOut)+0.4416);
--> if SensOut is 0 then hasil will be 0.4416.
SensOut being a very simple direct linear modification of analogRead(A0) (between 0 and 1023) it's easy to see that SensOut will always be positive or null - between 0 and 5 actually - and thus hasil will ALWAYS be between 0.4416 and 3,8831
So long story short, min value of SensOut (no signal on pin A0) being 0, means min value of hasil will be 0.4416 and so your display is fine... I'd say double check your formulas...
PS/ Your set up will be quickly boring to watch with 16 seconds delays to display all your "advertising" text... I'd get rid of it or make it go quicker... but your call of course
J-M-L:
so you do this math to calculate hasil which I assume is your value
int PD = analogRead(A0); // nilai x dalam bentuk data ADC
float SensOut = PD*(5/1024.0); // nilai x dalam bentuk tegangan (volt)
float hasil = (0.6883*SensOut)+0.4416);
--> if `SensOut` is 0 then `hasil` will be 0.4416.
`SensOut` being a very simple direct linear modification of analogRead(A0) (between 0 and 1023) it's easy to see that `SensOut` will always be positive or null - between 0 and 5 actually - and thus `hasil` will ALWAYS be between 0.4416 and 3,8831
So long story short, min value of `SensOut` (no signal on pin A0) being 0, means min value of `hasil` will be 0.4416 and so your display is fine... I'd say double check your formulas...
PS/ Your set up will be quickly boring to watch with 16 seconds delays to display all your "advertising" text... I'd get rid of it or make it go quicker... but your call of course
Thank you. I have covered the problem, i set the value if the value is under 0.46, it will be display zero on LCD screen.
but as you said, the ad text at the beginning is too long wait. I want to keep the ad, but sometimes its can be skipped, but i dont know how.
can you make if the button pressed, the ad will be skipped and program jump to the next function?
Yes for the button but will need to be pressed before you boot with the code in #3 otherwise you enter the if and get all the 16 seconds
Alternatively don't use delay(), do an active wait using millis() and check if button is pressed then you set a flag and use it to skip everything else
unsigned long startChrono;
boolean showAdverising = (digitalRead(buttonPin) == HIGH) ; // buttonPin is your button pin number, set up as INPUT_PULLUP, wired this way pin <---> button <---> GND
// ====== first display ======
if (showAdverising) {
lcd.setCursor(4, 0);
lcd.print("BERBASIS");
lcd.setCursor(3, 1);
lcd.print("ARDUINO UNO");
// delay(2000); // ==> that's what we want to change as can't be interrupted
startChrono = millis();
while (millis()-startChrono <= 2000) { // 2000 is duration to wait in ms, so 2 seconds
if (digitalRead(buttonPin) == LOW) { // check if button is pressed
showAdverising = false; // button is pressed, remember user decision
break; // and exit the while loop immediately
}
lcd.clear();
}
// ===== second display =======
if (showAdverising) {
... // repeat same thing for the next text
}
// ===== third display ======
...
Of course this bloc of code displaying 2 lines on the LCD if advertising is OK and waiting could be made as a function displayAdvertising() which would take as parameters the two text to display, position on screen and duration so that you don't have to repeat all the code
Yes - did not mean to pick on your exact code - was more pointing out that using delay() will get the user to wait although she/he has presssed the button and does not know this is taken into account or not - Hence the recommendation of using millis()