Site Tools


Sidebar

Content

pub:cm_water_level_sensor_module

CM+Water level sensor module

The module is a simple water level sensor. It measures the water volume by the printed wires exposed to the air on the module. The more water on the surface, more wires connected. Thus, the area of electrified wires gets larger, so the output voltage will increase. The surface of the sensor is gilded to prolong its life.


The schematic diagram:


Water Level sensor Module
1 Analog output
2 Analog output
CM Module
1 Analog output
2 Analog output
S Digital output
A Analog output
- GND
+ 3.3V

Microbit

Operating steps
1. First, we need to prepare the following experimental materials:
1 * microbit
1 * microbit expansion board
1 * USB cable
1 * CM module
1 * water level sensor module
- Several Jumper wires

Now connect the water level sensor to one end of the comparator whose the other end is connected to micro:bit.
connection diagram:


Experimental code:
makecode:

Python code:

  #-----------------------------------------------------------
# File name   : Waterlevel.py
# Description : Waterlevel sensor.
# Author      : jason
# E-mail      : jason@adeept.com
# Website     : www.adeept.com
# Date        : 2018/10/28
#-----------------------------------------------------------
from microbit import *
 
while True:
    # define potentiometer pin
    waterlevel = pin0.read_analog()
    print(waterlevel)
    sleep(1000)
 

Click “flash” and download the code onto the micro:bit. Effect Picture:




Arduino

Components
- 1 * Adeept Arduino UNO R3 Board
- 1 * Water Level Sensor Module
- 1 * CM Module
- 1 * USB Cable
- 1 * 4-Pin Wires
- 1 * 2-Pin Female to Female Wires

Build the circuit:


Adeept UNO R3 Board CM Module Water Level Sensor Module
D8 S
A0 A
5V +
GND -
1 2
2 1

Code:

  /***********************************************************
File name: _35_WaterLevelSensorModule.ino
Description: Now, when UNO collect water level sensor module data,
             you will see the data in the serial monitor 
 
Website: www.adeept.com
E-mail: support@adeept.com
Author: Tom
Date: 2017/03/20 
***********************************************************/
int waterlevelPin = 0;                 // water level sensor module A pin connected to analog pin 0
void setup() 
{                
  pinMode(waterlevelPin, INPUT);       //Set Analog 0 port mode, the INPUT for the input
  Serial.begin(9600);                 // opens serial port, sets data rate to 9600 bps
}
void loop() 
{
 Serial.print("Water level sensor data: "); //send data to the serial monitor
 Serial.println(analogRead(0));             //send data to the serial monitor
 delay(1000);                                //delay 1 s
}

Compile and download the sketch to the UNO R3 board.


Open Serial Monitor of the Arduino IDE. Take a bottle with some water. Place the Water Level Sensor module in the water at end and add water into the bottle. You will see the value of water level displayed on the window and changes as you add water.



Raspberry pi

Components
- 1 * Raspberry Pi
- 1 * GPIO Extension Board
- 1 * 40-Pin GPIO Cable
- 1 * Breadboard
- 1 * Water Level Module
- 1 * LM393 CM(Comparator) Module
- 1 * ADC0832 Module
- 1 * 2-Pin Wires
- 1 * 3-Pin Wires
- 1 * 4-Pin Wires
- 1 * 5-Pin Wires

Step 1: Build the circuit


C code:

  /*
 * File name   : waterLevel.c
 * Description : .
 * Website     : www.adeept.com
 * E-mail      : support@adeept.com
 * Author      : Jason
 * Date        : 2016/06/14
 */
#include <wiringPi.h>
#include <stdio.h>
 
typedef unsigned char uchar;
typedef unsigned int  uint;
 
#define     ADC_CS    0
#define     ADC_DIO   1
#define     ADC_CLK   2
 
uchar get_ADC_Result(void)
{
	//10:CH0
	//11:CH1
	uchar i;
	uchar dat1=0, dat2=0;
 
	digitalWrite(ADC_CS, 0);
 
	digitalWrite(ADC_CLK,0);
	digitalWrite(ADC_DIO,1);	delayMicroseconds(2);
	digitalWrite(ADC_CLK,1);	delayMicroseconds(2);
	digitalWrite(ADC_CLK,0);
 
	digitalWrite(ADC_DIO,1);    delayMicroseconds(2); //CH0 10
	digitalWrite(ADC_CLK,1);	delayMicroseconds(2);
	digitalWrite(ADC_CLK,0);
 
	digitalWrite(ADC_DIO,0);	delayMicroseconds(2); //CH0 0
 
	digitalWrite(ADC_CLK,1);	
	digitalWrite(ADC_DIO,1);    delayMicroseconds(2);
	digitalWrite(ADC_CLK,0);	
	digitalWrite(ADC_DIO,1);    delayMicroseconds(2);
 
	for(i=0;i<8;i++)
	{
		digitalWrite(ADC_CLK,1);	delayMicroseconds(2);
		digitalWrite(ADC_CLK,0);    delayMicroseconds(2);
 
		pinMode(ADC_DIO, INPUT);
		dat1=dat1<<1 | digitalRead(ADC_DIO);
	}
 
	for(i=0;i<8;i++)
	{
		dat2 = dat2 | ((uchar)(digitalRead(ADC_DIO))<<i);
		digitalWrite(ADC_CLK,1); 	delayMicroseconds(2);
		digitalWrite(ADC_CLK,0);    delayMicroseconds(2);
	}
 
	digitalWrite(ADC_CS,1);
 
	pinMode(ADC_DIO, OUTPUT);
 
	return(dat1==dat2) ? dat1 : 0;
}
 
int main(void)
{
	uchar adcVal;
	uchar level;
 
	if(wiringPiSetup() == -1){
		printf("setup wiringPi failed !");
		return 1; 
	}
 
	pinMode(ADC_CS,  OUTPUT);
	pinMode(ADC_CLK, OUTPUT);
 
	while(1){
		pinMode(ADC_DIO, OUTPUT);
		adcVal = get_ADC_Result();
		level = 255 - adcVal;
		printf("analog value: %03d   level: %d\n", adcVal, level);
 
		delay(100);
	}
 
	return 0;
}

Python code:

  #!/usr/bin/env python
import ADC0832
import time
 
def init():
	ADC0832.setup()
 
def loop():
	while True:
		res = ADC0832.getResult()
		level = 255 - res
		print 'analog value: %03d  level: %d' %(res, level)
		time.sleep(0.1)
 
if __name__ == '__main__':
	init()
	try:
		loop()
	except KeyboardInterrupt: 
		ADC0832.destroy()
		print 'The end !'

For C language users:

Step 2: Edit and save the code with vim or nano.

(code path: /home/Adeept_Sensor_Kit_for_RPi_C_Code/30_waterLevel/waterLevel.c) 


Step 3: Compile

$ sudo gcc waterLevel.c -o waterLevel -lwiringPi 


Step 4: Run

$ sudo ./waterLevel 


For Python users:

Step 2: Edit and save the code with vim or nano.

(code path: /home/Adeept_Sensor_Kit_for_RPi_Python_Code/30_waterLevel.py) 


Step 3: Run

$ sudo python 30_waterLevel.py 


Take a bottle with some water. Place the Water Level Sensor module in the water at end and add water into the bottle. You will see the value of water level displayed on the terminal and changes as you add water.


Data link: http://www.adeept.com/learn/
Video: http://www.adeept.com/video/

pub/cm_water_level_sensor_module.txt · Last modified: 2019/01/04 10:04 by Adeept