Professional Documents
Culture Documents
Conductivity Sensor Arduino Code
Conductivity Sensor Arduino Code
Conductivity Sensor Arduino Code
//=============================================================================
#include <SoftwareSerial.h> //Importing a library for Bluetooth communication
//PROGRAMMING VARIABLES
//=============================================================================
SoftwareSerial BTserial(10, 11); // Arduino Reciever (RX) | Arduino Transmitter
(TX)
int sensorValue = 0;
float voltage_threshold = 3.5; //Minimum voltage level required to activate pump
//PROGRAM SETUP
//============================================================================
void setup()
{
BTserial.begin(9600); //setting up the bluetooth serial monitor
Serial.begin(9600); //setting up the normal serial monitor
pinMode(relayPin, OUTPUT); //defning the relayPin as an output.
//When the relayPin is given power, a switch connects the pump and its power
supply.
//When the relayPin is not given power, the switch is left open and the pump is
turned off
}
//MAIN PROGRAM
//============================================================================
void loop() //the code written below iterates continously
{
//The Arduino can supply an output voltage of 5V.
//When reading a voltage from a sensor pin, the voltage (0-5V) is read as digital
value (0-1023)
//Sending the voltage value to the bluetooth serial monitor (which is observed by
the "ArduTooth" mobile app)
//Note: the ";" printed at the end is required for formatting by the app
BTserial.print(voltage);
BTserial.print(" V");
BTserial.print(";");
//If the conductivity sensor voltage is greater than or equal to (symbol: >=) the
predefined threshold voltage, turn on the pump.
//Otherwise, turn off the pump.
if(voltage >= voltage_threshold){
digitalWrite(relayPin, HIGH);
}
else{
digitalWrite(relayPin, LOW);
}