Skip to content

Instantly share code, notes, and snippets.

@katiemicak
Last active January 24, 2017 21:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save katiemicak/ef47b786486a6af0b8651554d3e2b6c4 to your computer and use it in GitHub Desktop.
Save katiemicak/ef47b786486a6af0b8651554d3e2b6c4 to your computer and use it in GitHub Desktop.
KatieCam
/************************ Adafruit IO Config *******************************/
// visit io.adafruit.com if you need to create an account,
// or if you need your Adafruit IO key.
#define IO_USERNAME "**************"
#define IO_KEY "********************************"
/******************************* WIFI **************************************/
// the AdafruitIO_WiFi client will work with the following boards:
// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
// - Feather M0 WiFi -> https://www.adafruit.com/products/3010
// - Feather WICED -> https://www.adafruit.com/products/3056
#define WIFI_SSID "ocadu-embedded"
#define WIFI_PASS "internetofthings"
// comment out the following two lines if you are using fona or ethernet
#include "AdafruitIO_WiFi.h"
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);
/******************************* FONA **************************************/
// the AdafruitIO_FONA client will work with the following boards:
// - Feather 32u4 FONA -> https://www.adafruit.com/product/3027
// uncomment the following two lines for 32u4 FONA,
// and comment out the AdafruitIO_WiFi client in the WIFI section
// #include "AdafruitIO_FONA.h"
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);
/**************************** ETHERNET ************************************/
// the AdafruitIO_Ethernet client will work with the following boards:
// - Ethernet FeatherWing -> https://www.adafruit.com/products/3201
// uncomment the following two lines for ethernet,
// and comment out the AdafruitIO_WiFi client in the WIFI section
// #include "AdafruitIO_Ethernet.h"
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
/Take a reading from an Ultrasonic sensor and post it to Adafruit.IO
// edit the config.h tab and enter your Adafruit IO credentials
#include "config.h"
#include <NewPing.h>
#define TRIGGER_PIN 14 // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN 12 // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
int sensorVal; //variable to hold the value from the sensor
int prevSensorVal;
int sensorChangeThreshold = 2;
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
// set up the 'distVal' feed
AdafruitIO_Feed *distVal = io.feed("distVal");
void setup() {
// start the serial connection
Serial.begin(115200);
// wait for serial monitor to open
while(! Serial);
Serial.print("Connecting to Adafruit IO");
// connect to io.adafruit.com
io.connect();
// wait for a connection
while(io.status() < AIO_CONNECTED) {
Serial.print(".");
delay(500);
}
// we are connected
Serial.println();
Serial.println(io.statusText());
}
void loop() {
// io.run(); is required for all sketches.
// it should always be present at the top of your loop
// function. it keeps the client connected to
// io.adafruit.com, and processes any incoming data.
io.run();
//getValue from Sensor
sensorVal = sonar.ping_cm();
if(abs((prevSensorVal-sensorVal))>sensorChangeThreshold) //check if there has been enough of a change in the value
{
// save randVal to the 'myRandoVal' feed on Adafruit IO
distVal->save(sensorVal);
//print the value to the serial monitor so you can check if its working
Serial.print("sending -> ");
Serial.println(sensorVal);
}
prevSensorVal=sensorVal;
}
var sensorVal1;
var fillValue;
var aiokey = "**************************************";
var feedName = "*************";
function setup() {
createCanvas(1200,1000);
setInterval(askAIO,800);
}
function draw() {
background(255);
// fill(255,0,0);
// noStroke();
// ellipse(canvas.width/2,canvas.height/2,sensorVal1,sensorVal1);
if((sensorVal1>=0)&&(sensorVal1<=30))
{
fillValue=20;
}else if((sensorVal1>30)&&(sensorVal1<=60))
{
fillValue=60;
}else if((sensorVal1>60)&&(sensorVal1<=90))
{
fillValue=100;
}else if((sensorVal1>90)&&(sensorVal1<=120))
{
fillValue=150;
}else if((sensorVal1>120)&&(sensorVal1<=180))
{
fillValue=200;
}else{
fillValue=225;
}
fill(fillValue);
rect(200, 50, 800, 600);
}
function receivedData(data)
{
sensorVal1 = parseInt(data.value);
println(sensorVal1);
}
function askAIO()
{
loadJSON("https://io.adafruit.com/api/feeds/"+feedName+"/data/last.json?x-aio-key="+aiokey, receivedData);
}
@hannan-sultan
Copy link

can you provide the wiring diagrams?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment