Professional Documents
Culture Documents
JHD12864E To Arduino
JHD12864E To Arduino
Arduino Forum
Using Arduino => Programming Questions => Topic started by: robywhite on May 06, 2016, 05:17
am
How to write turbidity sensor coding for arduino??can someone help me..
Use a 5V arduino board, and read the analog signal. Try the sensor in clear and dirty water and see what
values you get for the analog value.
hook you Analog output form the sensor to Arduingo A0 and Ground to G provide power, open up a serial
monitor at 9600 Baud and you should be able to see what is being sent with this code:
output should read somewhere between 0 ~ 1024 on the serial display
Code: [Select]
/*
AnalogReadSerial
Reads an analog input on pin 0, prints the result to the serial monitor.
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
Hi,
I am using one of these sensors for teaching purposes, and I considered that:
https://forum.arduino.cc/index.php?action=printpage;topic=398900.0 1/3
9/18/2018 Print Page - Turbidity sensor coding
1. The output voltage (Vout) of the sensor is inversely proportional to turbidity, so,
2. The clear water have a 0% turbidity, and
3. Turbidity of 100% means a fully opaque object,
So, I proposed the following equation for turbidity (in relative percent units):
I also incorporated a push button to calibrate de sensor with clear water, in order to get Vclear (output
voltage for clear water). I also used EEPROM library to store and recover the last calibration Vclear value
in ROM.
int buttoncalib = 2; // The pin location of the push sensor for calibration. Connected to Ground and
// pin D2.
void setup()
{
Serial.begin(9600);
pinMode(buttoncalib, INPUT_PULLUP); //initializes digital pin 2 as an input with pull-up resistance.
// LCD display
lcd.begin (16,2);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Turbidity Sensor");
//Serial display
Serial.println("Hi... welcome to your turbidity sensor");
EEPROM.get(0, Vclear); // recovers the last Vclear calibration value stored in ROM.
delay(3000); // Pause for 3 seg
}
void loop()
{
pushcalib = digitalRead(2); // push button status
if (pushcalib == HIGH) {
// If the push button is not pushed, do the normal sensing routine:
for (int i=0; i < n; i++){
sensor += analogRead(A1); // read the input on analog pin 1 (turbidity sensor analog output)
delay(10);
}
sensorValue = sensor / n; // average the n values
voltage = sensorValue * (5.000 / 1023.000); // Convert analog (0-1023) to voltage (0 - 5V)
https://forum.arduino.cc/index.php?action=printpage;topic=398900.0 2/3
9/18/2018 Print Page - Turbidity sensor coding
// Serial display
Serial.print(sensorValue);
Serial.print(", ");
Serial.print(voltage,3);
Serial.print(", ");
Serial.print(turbidity,3);
Serial.print(", ");
Serial.println(Vclear,3);
// Display LCD
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Volts=");
lcd.print(voltage,2);
lcd.setCursor(0,1);
lcd.print("Turbidity=");
lcd.print(turbidity,2);
lcd.print("%");
} else {
https://forum.arduino.cc/index.php?action=printpage;topic=398900.0 3/3