Michael Portera
Published © GPL3+

Box Bot: A Box Tops for Education Project

An open source hardware project integrated with Amazon Alexa to encourage families to tinker together and raise money for local schools.

BeginnerFull instructions provided1 hour1,161
Box Bot: A Box Tops for Education Project

Things used in this project

Story

Read more

Schematics

Box Bot Pinout

Code

bt4e

Arduino
Change lines where the comment says "//Edit this line"
#include <WiFiClientSecure.h>
#include <ESP8266WiFi.h>

const char* ssid = "YOUR_SSID"; //Edit this line - add the SSID of our network
const char* password = "YOUR_WIFI_PASSWORD"; //Edit this line - add the wifi password
const int httpsPort = 443; //443 is the standard port used for HTTPS
WiFiClientSecure client; // Initialize the Wifi client library
String uri = "URI_FROM_ALEXA"; //Edit this line
String host = "HOST_FROM_ALEXA"; //Edit this line
String api_key = "API_KEY_FROM_ALEXA"; //Edit this line

int pushbutton = D0; // define the push button
int led1 = D1; // this will define our first LED
int led2 = D2; //this will define our second LED
int led3 = D3; //this will define our third LED
int val; //define a numeric variable to hold our HIGH and LOW signals
int fifty_counter = 0; //this will keep track of our bundle of 50
String PostData = "{\"api_key\": \""+api_key+"\", \"count\": \"1\"}";

void setup()
{
  pinMode(led1, OUTPUT); // LED pin as output
  pinMode(led2, OUTPUT); // LED pin as output
  pinMode(led3, OUTPUT); // LED pin as output
  pinMode(pushbutton, INPUT); //pushbutton as input
  WiFi.begin(ssid, password); //connect to our Wifi network
  delay(10000); // wait 10 seconds for connection
}

void loop()
{
  val=digitalRead(pushbutton); //read the value of the sensor
  if(val == LOW) // if the button is pushed, blink the lights  
  {
    digitalWrite(led1,HIGH);
    digitalWrite(led2,HIGH);
    digitalWrite(led3,HIGH);
    delay(400);
    sendPost(); //function for sending the data to AWS
    fifty_counter++; // increase our variable keeping track of when we reach 50
    if (fifty_counter == 50){ //50 is the number we want the counter to stop for bagging - we can use 5 for testing
      fifty_counter = 0; // Reset the center to zero
      LedRoutine(); //function for blinking the lights 10 times
  }
  }
  else
  {
    digitalWrite(led1,LOW); //keep the lights off
    digitalWrite(led2,LOW);
    digitalWrite(led3,LOW);
  }
}

//If the button has been pushed 50 times, blink the lights 10 times before resetting
void LedRoutine()
{
  for (int i = 0; i <= 10; i++){
    digitalWrite(led1,HIGH);
    digitalWrite(led2,HIGH);
    digitalWrite(led3,HIGH);
    delay(200);
    digitalWrite(led1,LOW);
    digitalWrite(led2,LOW);
    digitalWrite(led3,LOW);
    delay(200);
  }
}

//This is a function to connect to AWS and send notification we've collected a Box Top
void sendPost()
{
    if (client.connect(host, httpsPort)){
      client.println("POST /"+ uri +" HTTP/1.1"); 
      client.println("Host: "+ host);
      client.println("User-Agent: Esp8266");
      client.println("Content-type: application/json");
      client.println("Connection: close");
      client.print("Content-length: ");
      client.println(PostData.length());
      client.println();
      client.println(PostData);
    }
}

Credits

Michael Portera

Michael Portera

4 projects • 15 followers

Comments