Beruflich Dokumente
Kultur Dokumente
COE 410
Lab # 9
Date: 24/04/2017
Introduction
Photon has a total of 8 ADC input pins and 2 DAC output pins . These pins can
be connected to sensors such as temperature and humidity . Also , they can be
connected to potentiometers and LEDs and so on. The functions that are used
in photon for analog are analogRead for analog input and analogWrite for
analog output. On photon we register variables and funtions on the Particle
web server to securely access photons and have the ability to control them via
HTTP request . It also enables users to use other platforms that support HTTP
communication. Figure below demonstrates the registration of variables and
functions.
Q1 )
Code :
void setup() {
pinMode(temp_sensor,INPUT); //set pin A0 to input
Particle.variable("temperature", temp_value); //register variable temp_value
at Particle server
void loop() {
int analogValueTemp = analogRead(temp_sensor); //read the temp sensor
double voltageTemp = 3300* ((double)analogValueTemp / 4095.0); //convert
from unit to into volt
Screenshot :
From browser :
From mobile :
Q2 )
Code :
void loop() {
else if (command=="off") {
digitalWrite(led, LOW); //set LED to LOW
return 0;
}
else {
return -1;
}
}
HTML file :
<!DOCTYPE>
<html>
<body>
<center>
<br>
<br>
<br>
<form
action="https://api.particle.io/v1/devices/3d001f000f47343337373737/led?
access_token=e203b98dca5f2cfe188a89753ef1de26d1e03586"
method="POST">
Tell your device what to do!<br>
<br>
<input type="radio" name="args" value="on">Turn the LED on.
<br>
<input type="radio" name="args" value="off">Turn the LED off.
<br>
<br>
<input type="submit" value="Do it!">
</form>
</center>
</body>
</html>
Screenshots :
LED off :
Led ON :
Q3 )
Code :
void setup() {
pinMode(led, OUTPUT); //set pin to output
Particle.function("an_led", ledan); //declare a particle function so we can
control led
void loop() {
HTML file :
<!DOCTYPE html>
<html>
<body>
<form
action="https://api.particle.io/v1/devices/3d001f000f47343337373737/an_led?
access_token=e203b98dca5f2cfe188a89753ef1de26d1e03586"
method="POST">
LED intensity value:<br>
<input type="text" name="args" value="4095">
<br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
Screenshots :
Conclusion
readings over internet. In addition, we were able to control the internal LED
external LED connected to DAC by sending an int value between 0-4095 over