arduino coding

hello there, I am currently doing a non-invasive glucose monitoring by using infrared method. I will be using NIR LED as transmitter and photodiode as receiver to detect glucose level from my hand. I have been struggling with the arduino coding of how to code to get value and send code to smartphone. Does anyone can help me with the code? Thanks, below attached is the sample i will be following.

Smartphone Based Non-Invasive Glucose Monitoring.pdf (328 KB)

(deleted)

Here''s my code, sorry forgot to insert it above

#include "SoftwareSerial.h"
int BluetoothData;
int analogInPin = A0; // Analog input pin that the potentiometer is attached to
int out =2;
int sensorValue = 0; // value read from the pot
SoftwareSerial HC05(4,5); // RX, TX

void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
pinMode(out, OUTPUT);
HC05.begin(9600);
}

void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
Serial.print("sensor value = " );
Serial.println(sensorValue);

delay(200);

if(sensorValue>700)
{
digitalWrite(out,1);
}
else
{
digitalWrite(out,0);
}
if (HC05.available())
{
BluetoothData=HC05.read();
Serial.println(BluetoothData);
}
}

actually the serial monitor did come out with values, but why is it those values came out, i also dont know...
Just a project for my university , non-commercial.
Anyway thanks for replying me also

Do you want to send the glucose level to the smartphone to Arduino, or from Arduino to the smartphone? I am not sure.

…Arnav

Thanks for replying, the arduino will send the voltage measured at the output of my hardware which is photodiode through bluetooth connection to my smartphone apps. the apps will then convert the voltage into glucose level. Sorry for not being clear. you can go through the pdf i attached for clearer detail if you want… Thanks

Smartphone Based Non-Invasive Glucose Monitoring.pdf (328 KB)

(deleted)

Raphael96:
actually the serial monitor did come out with values, but why is it those values came out, i also dont know...
Just a project for my university , non-commercial.
Anyway thanks for replying me also

Over the serial link, or over the Bluetooth link?

Regardless, forget the Bluetooth for now.
Debug the operation of the sensor working correctly over Serial first..

void loop() {
  // read the analog in value:
  sensorValue = analogRead(analogInPin);
  Serial.print("sensor value = " );
  Serial.println(sensorValue);
}

What values are you receiving?
What values are you expecting?

If you're not getting the values you expect then you have a wiring or hardware problem with your sensor.

Code tags look like this [​code][​/code] by the way .

in serial monitor, sometimes it shows 230, 234, 235, 231, 230 like this and if i reopen arduino ide again, it shows 78, 80, 81, 77, 79, it seems a little bit constant, just sometimes not same as previously, dono why...

my code is to get reading from the analog output of my hardware which is my photodiode and send the value as digital input to my smartphone through Bluetooth which is connected with my arduino.

And do you understand the "if sensor value>700" that part, if can explain to me please, thank you

thanks for replying

hello pcbbc, so how do i debug that code section? is my analogread that part used correctly? i am expecting the serial monitor will show the voltage measured at photodiode which is the output of my hardware and will be converted into glucose level at my developed apps. Thanks

Raphael96:
hello pcbbc, so how do i debug that code section? is my analogread that part used correctly? i am expecting the serial monitor will show the voltage measured at photodiode which is the output of my hardware and will be converted into glucose level at my developed apps. Thanks

The first step of any new programming project is to get the individual parts working. You cannot hope to send anything via Bluetooth (or anything meaningful at any rate) if you cannot first accurately read your sensor value.

So start with just a program that reads sensor values and outputs them to the IDE serial monitor window with Serial.println()
Are you getting the values you expect?
If not, why not?

Once you have the values you expect, only then proceed to the next step - add in the Bluetooth.
In fact you may even have a step where you have ONLY Bluetooth (remove the sensor) to familiarise yourself with the Bluetooth module and check it works as you expect…

You get those values from the sensor, or from the Bluetooth?
Your program writes both to serial output and NEITHER of them are in the format you provided (a comma separated list of values).
Copy and paste the actual text from the serial monitor window so we can see what you are getting and how it ties up with what you are sending.

Also the read function gets a single character (byte) and returns the ASCII code for it.
So if we assume those values are not sensor values, and are the values output to serial after the BluetoothData=HC05.read(); line…
78, 80, 81, 77, 79 would mean you sent “NPQMO”
230, 234, 235, 231, 230 doesn’t make much sense as standard ASCII though.

Are these real examples of the data bytes you are receiving, or are you “making up” examples?
What did you send the Bluetooth module as test data?
Why are you feeling the need to reading anything, when presumably you want to send the sensor value you read previously?

below attached is the images taken of the 200+ values shown on the serial monitor and the connection of my hardware, sorry it maybe very messy. erm i will explain about hardware connection first for this reply

everything will start from the ir led which is at the most right side of the circuit, it will attenuate the incoming light and the photodiode will convert the light into voltage, the analog signal received from the photodiode is converted into digital signal by arduino nano. then arduino nano will send the voltage value to the apps through bluetooth connection.

tx of bluetooth is connected to rx of arduino nano and vice versa (brown and purple wire)
5v of bluetooth is connected to 5v of arduino nano (grey wire)
ground of bluetooth module is connected to the ground of arduino nano (black wire)
anode of ir led is connected to cathode of photodiode (grey and yellow wire)
anode of photodiode is connected to A0 of arduino nano which i assumed as analog signal (green wire)
(left)1kohm resistor is connected to anode of photodiode and d2 of arduino nano (white wire)
(right)1kohm resistor is connected to 5v of arduino nano (blue wire)

sorry the previous reply failed to upload images, so now about my code. I should get the values from the sensor which will be ADC from the arduino itself, then finally bluetooth will send the values to the phone apps. so how should i write the code of get the reading from the photodiode as analog input and digitalized before adding the bluetooth function. pin a0 and pind2 will be the 2 pins of arduino nano i will be using. Sorry for my beginner knowledge and thanks for replying

WhatsApp Image 2020-06-19 at 16.05.33 (1)-converted.pdf (201 KB)

(deleted)

Sorry, but pictures of Dupont connectors, components in solder-less breadboards and descriptions of pin wirings don't help us much.

Much better just to sketch out the circuit diagram and post that...

Regardless, you appear to have values of around 232-237 from your sensor.
Is this what you expect under these test conditions?

If not, then what did you expect?
And show the circuit diagram and whatever calculations or measurements you did that explain why this is not what you expected.

Are you saying you sometimes also get values around 78-81?
As your sensor seems to be just exposed to incident light, and not in a controlled environment directly coupled with the IR emitter, that is perhaps not surprising.
What happens if you cover the sensor?

If the readings are correct, then next step we can move onto trying to send them via Bluetooth.
Although as already pointed out the code in post #2 doesn't actually send anything...

i have attached the breadboard and schematic diagram just without bluetooth,

tx of bluetooth is connected to rx of arduino nano and vice versa
5v of bluetooth is connected to 5v of arduino nano
ground of bluetooth module is connected to the ground of arduino nano.

So by using multimeter to meausre voltage at 1 pin of cathode and 1 at the end of 1k resistor which is connected to the d2 of arduino nano, i got 430mV. So, does it means that in serial monitor also have to show around 430mV also?

Formula: glucose conc. =(voltage-0.8633)/0.00185. Should i include this in IDE or at my developing apps there better? Thats the only calculation for this project. If i cover the sensor, it seems no difference just reading might be different whenever i reset the connection to IDE.

“Although as already pointed out the code in post #2 doesn’t actually send anything…” for this sentence, i am still not clear of it. Thanks

If you post your code as described in the how to use this forum sticky, more members will read it.
When you post your schematic, a hand drawn circuit in jpg or png is far preferable over a pretty Fritzing picture.

Alright thanks for the advice SteveMann.