Hi guys,
I am doing a Salinity Sensor project. However, I am using a photoresistor circuit, together with its corresponding code as shown below; How do I make this code read my Salinity sensor resistance as a measure of voltage and display values as it reads through on the serial monitor.
The Url included below are images that represent my circuit exactly, except that the f5and f6 on the breadboard are connected to my salinity sensor, rather than to the photoresistor.
Thanks
Code:
const int sensorPin = 0;
const int ledPin = 9;
int lightLevel, high = 0, low = 1023;
void setup()
{
pinMode(ledPin, OUTPUT);
}
void loop()
{
lightLevel = analogRead(sensorPin);
manualTune(); // manually change the range from light to dark
well you need to add Serial.begin(115200); in the setup() to open up the communication with your computer (at 115200 bauds, set that in the serial console)
and then in your loop()
just add a Serial.print(lightLevel); before or after you adjusted it.
const int sensorPin = 0; // pin A0
const int ledPin = 9; // light - ensure there is proper current limiting resistor
void setup()
{
Serial.begin(115200);
pinMode(ledPin, OUTPUT);
}
void loop()
{
int sensorLevel = analogRead(sensorPin);
Serial.print("Sensor Value = "); Serial.println(sensorLevel); // sensorLevel between 0 and 1023
sensorLevel = map(sensorLevel, 0, 1023, 0, 255); // this is to convert sensorLevel from 0-1023 to 0-255
analogWrite(ledPin, sensorLevel); // to set the light brightness because it needs a value between 0 and 255
}