Ahad khan
Published

Water Quality App

We want to monitor the quality of tap water coming into a house, maintain its supply and save water all through the use of a simple App.

ExpertWork in progress3,524
Water Quality App

Things used in this project

Hardware components

Android device
Android device
×1
Raspberry Pi 2 Model B
Raspberry Pi 2 Model B
×1
Libelium Smart Water wireless sensor
×1
Solenoid Valve
×1

Software apps and online services

muzzley

Story

Read more

Schematics

Starter Schematic

Wiring up the components on a breadboard. The corresponding Raspberry Pi 2/MinnowBoard Max sections

Code

Starter Code

C#
Run this code on Raspberry Pi 2/MinnowBoard Max and use it to control an LED. We use GPIO interrupts to detect when the button is pressed and toggle the LED in response.
buttonPin = gpio.OpenPin(BUTTON_PIN);
ledPin = gpio.OpenPin(LED_PIN);
// Initialize LED to the OFF state by first writing a HIGH value
// We write HIGH because the LED is wired in a active LOW configuration
ledPin.Write(GpioPinValue.High); 
ledPin.SetDriveMode(GpioPinDriveMode.Output);

// Check if input pull-up resistors are supported
if (buttonPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
	buttonPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
else
	buttonPin.SetDriveMode(GpioPinDriveMode.Input);

// Set a debounce timeout to filter out switch bounce noise from a button press
buttonPin.DebounceTimeout = TimeSpan.FromMilliseconds(50);

// Register for the ValueChanged event so our buttonPin_ValueChanged 
// function is called when the button is pressed
buttonPin.ValueChanged += buttonPin_ValueChanged;

private void buttonPin_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs e)
{
	// toggle the state of the LED every time the button is pressed
	if (e.Edge == GpioPinEdge.FallingEdge)
	{
		ledPinValue = (ledPinValue == GpioPinValue.Low) ?
			GpioPinValue.High : GpioPinValue.Low;
		ledPin.Write(ledPinValue);
	}


// need to invoke UI updates on the UI thread because this event
// handler gets invoked on a separate thread.
var task = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => {
	if (e.Edge == GpioPinEdge.FallingEdge)
	{
		ledEllipse.Fill = (ledPinValue == GpioPinValue.Low) ? 
			redBrush : grayBrush;
		GpioStatus.Text = "Button Pressed";
	}
	else
	{
		GpioStatus.Text = "Button Released";
	}
});

Credits

Ahad khan

Ahad khan

1 project • 4 followers
Thanks to Andy Larkin .

Comments