Meanwhile I want to do real-time voltage monitoring and applying for bio-reactor using MEGA 2560.
I connected the bio-reactor with an external 100 ohm resistor in series like the schematic sketch attached below. My intention was to monitor the voltage over the resistor using ANALOG IN pin and then use to monitored voltage as reference to program to change the applied voltage at PWM pin.
It looked very simple but never worked so I want to seek some help here.
It's not clear from your pictures where the ground is on your "bioreactor". The PWM output gives a time ratioed +5 volts with respect to Arduino ground so any current due to the Arduino source must flow into the cathode and out the anode to the Arduino ground. You have a 100 ohm resistor anode to ground and the voltage across the resistor goes to the Arduino analog input so this input is actually measuring current 0 to 50 ma scaled 0 to 5 volts. Is this what you intended?
Big question: what voltage do you read at the analog input pin?
Note that I am referring to conventional current flow, not electron flow above. This can confuse people not familiar with electrical engineering.
the ground of my bioreactor is also Arduino GND, I want to connect the bioreactor and the resistor in series so that they share the voltage applied from PWM pin and have the same current (current is what I am interested). I intend to measure the voltage cross the resistor, so should I connect ANALOG INPUT pin to current cathode side of the resistor or the current anode side?
when I connect ANALOG INPUT pin to the current cathode side of the resistor, I read either 0 or about 2.5 volt which does not make any sense since I set the max applied voltage from PWM to be 2.5 volt.
While it has been done... using the arduino in an active feedback loop is problematic due to the possibility of delayed response and over or under correction. Using a library like PID may help.
So you are interested in measuring current and have a circuit which should do this. I don't see a problem here.
What kind of meter are you using to measure the voltage? The old fashioned analog meter will read average voltage of the PWM but a digital meter may sample the voltage and simply tell you what it found in the sample; 0 volts or 2.5 volts in you case.
And 2.5 volts seems very low for the PWM output. What current are you drawing from it? I wouldn't go over perhaps 20--30 ma. If too high it will suck down the voltage. Get hold of a meter which reads average volts and see what the voltage is across the 100 ohm resistor so calculate the current.
I'm not really up to speed on electrochemical processes but I'm sure they can be very non-linear so you should be suspicious of using PWM as opposed to pure analog volts. Perhaps you could put an RC filter on the PWM.
Just a thought.