The code is running and working as shown. However I'd like to monitor the val read at sensorPin ie. A0.
So I save the value read at A0 in val:
val=analogRead(sensorPIN);
Then I test if the value read is LOW or HIGH - I know! I should use a digital port for this, but I was unsure if the circuit could deliver a proper HIGH so I decided to use an analog port instead. I guess the price is a little slower running code
while(val<300) { ....
I reckon the nano reads up to 5VDC in 1024 steps on the analog ports!? When I try to run, the serial monitor shows that the val is LOW - also when I measure up above 4V on A0!? val<300 should mean that only voltages < approx 1.5V are measured as LOW!?
I have had the nano only for a week now. Uses the old bbotloader. I have had another problem with it already: A temperature measurement (project shown under Forum: Scientific Measurement) involving an NTC resistor showed results that gave me a suspicion that the declaration of long ints did not work on the nano!?
Please post your full sketch. If possible you should always post code directly in the forum thread as text using code tags (</> button on the toolbar). This will make it easy for anyone to look at it, which will increase the likelihood of you getting help. If the sketch is longer than the forum will allow then it's ok to add it as an attachment. Don't put your code in some external file service like dropbox, etc. We shouldn't need to go to an external website just to help you. I do feel it's reasonable to post a link to code hosted on GitHub or similar code hosting sites since that's an platform specifically designed for this sort of thing
Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read. If you're using the Arduino Web Editor then you will not have access to this useful tool. I recommend using the standard Arduino IDE instead.
Please remove unnecessary blank lines from your code before posting to the forum. One or two to separate code into logical sections is fine but large spaces for no reason or random blank lines just make for more scrolling when we're trying to read your code.
The contents of val are not bound to the analogRead() function on some pin. All that you are storing in val is the one-time output of analogRead(). If you use val in the while statement, somewhere in the body of the statement, you must call analogRead() again, and assign the output to val.