© 2017 The Programmator. Theme WPBoot by Just Free Themes.
In this post I’ll elaborate on a proof of concept for the Automated Greenhouse. This was also the perfect time to test Windows IoT for controlling the Arduino.
You’ll need a development machine supporting Visual Studio 2015, an Arduino, a relay and an LED. You can get an official Arduino on their website, or some aftermarket copy if you’re an equally cheap bastard as myself.
Setting up your windows 10 develop machine and Arduino are beautifully described in this Microsoft article and really shouldn’t cause much of a trouble. In my example, I’m not using a Bluetooth shield though, but a simple USB connector. Worth mentioning is that I had to set the Baud-rate to 57600 in order to get the data stream from and to my Arduino to work.
For the greenhouse project, I will need relays to control electrical elements that would draw too much current for the Arduino’s sensitive circuits, such as water valves, a water pump, a lamp, you get the idea.
My PoC is to be able to control a relay, attached to an Arduino digital output pin, from a Windows Universal App, and make that relay control an RGB led acting as the high current device. Green will be the Normal Open condition, and Red will be the Normal Closed condition.
I’ve taken pictures while I’m mastering schematics drawing class. Hopefully these pictures are clear enough for you to recreate the setup. Leave a note in the comments section if not and I’ll see what I can do about it. 😉
The yellow wire coming out the relay is the normally open condition wire, that’s when the Signal to the relay (green wire coming from digital pin 2 on the Arduino) has PinState.LOW. The white wire, makes the red LED light up. That’s when the circuit is closed and the high current device would be activated.
If you followed the tutorial in The setup above, you’ll have yourself a project with a main xaml file in front of you (unless you’re now browsing AliExpress for electrical treats). In the MainPage.xaml.cs codefile, I used a (God forbid) endless while loop to toggle the relay.
In the code block below, you can see how I set digital pin 2 to be an output pin. This is the signal pin for our relay.
And in this block, I use that digital pin 2 to change the state of the relay by setting it in a HIGH/LOW state.
Running this code locally toggles the relays on/off state, which in turn toggles the LED. Success!