In this tutorial we'll create a simple circuit that sense light using a photoresistor.
What we need:
Alternatively use codebender
}
Update
Video demo
What we need:
- Arduino
- Photo cell (CDS Photoresistor)
- 10K Resistor
- Breadboard or perforated pcb
Alternatively use codebender
By hitting the 'light' command in the serial monitor we will get a print out of what it interprets as the amount of light in a qualitative manner. Thus is 'Dark', 'Dim', 'Light', 'Bright', 'Very_Bright'. You can change thresholds readings with values that suits your conditions.
OK, now we are ready to take advantage of the above example and make an assistive illumination system. As we already know we can capture serial messages from Jubito and trigger corresponding events. To make it happen we need to create one event handler with the name 'Dark' that will execute the 'plug-A-on' launcher of this example.
To do so, navigate to Control Panel/Instruction Sets/Add New Event Handler and enter the name and the action. When sensor submits 'Dark', the 'plug-A-on' launcher will be executed and turn on a light that is plugged to a wireless power outlet.
Notice: The above example to take effect, we need to let the loop continuous running and print out conditions than waiting for a 'light' command to be send. The modified sketch should be...
void loop(void) {
// Light measurement
photocellReading = analogRead(photocellPin);
// We'll have a few threshholds, qualitatively determined
if (photocellReading < 10) {
Serial.println("Dark");
} else if (photocellReading < 200) {
Serial.println("Dim");
} else if (photocellReading < 500) {
Serial.println("Light");
} else if (photocellReading < 800) {
Serial.println("Bright");
} else {
Serial.println("Very_Bright");
}
}
delay(1000);
}
But still you can use a scheduler and evaluator that applies to original sketch. Follow this article to see how you can do that.
Update
So we come back to see how we can make a running daemon with a scheduler that evaluates the light conditions.
First we need to create a launcher that executes the 'light' command we set to arduino sketch and fetch the state. Then we need a new Instruction Set that invokes it.
First we need to create a launcher that executes the 'light' command we set to arduino sketch and fetch the state. Then we need a new Instruction Set that invokes it.
From the Instruction Set menu click Add New Launcher and give a name and the judo API call to send the 'light' command to the serial port.
After that create a new Instruction Set that invoke the launcher and make the evaluation with the 'Dark' condition. Type a name of your choise and the evaluation that follows...
{ evalBool("*getlight" == "Dark"); plug-A-on; ; }
The '*getlight' pointer will invoke the 'getlight' launcher and get its returning. Then it will be replaced by the condition data ('Dark', 'Dim', 'Light', etc) and proceed to evaluation. If condition is true the 'plug-A-on' launcher will be triggered, else nothing will happen.
The last thing to do to make it a runnable daemon is to create a new schedule that call the above Instruction Set within an interval.
From Scheduler menu click Add New enter a name, <Repeat> on the period dropdown, interval in milliseconds (the example use 60000ms which is 1 minute) and finally the 'evallight' Instruction Set as the action.
From Scheduler menu click Add New enter a name, <Repeat> on the period dropdown, interval in milliseconds (the example use 60000ms which is 1 minute) and finally the 'evallight' Instruction Set as the action.
Video demo
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.