Matthew Aggari

Lane Tech HS Sunset Tracker

My project is a neat piece of art that uses a servo and a sunset api to show whether the sun will set early or late each morning.

BeginnerFull instructions provided59
Lane Tech HS Sunset Tracker

Things used in this project

Hardware components

Particle Argon
SG90 Micro-servo motor
SG90 Micro-servo motor
Male/Male Jumper Wires

Software apps and online services

sunset api
Particle Build Web IDE
Particle Build Web IDE

Hand tools and fabrication machines

Hot glue gun (generic)
Hot glue gun (generic)


Read more

Custom parts and enclosures

Custom Fritzing Part for the SG90 servo


Servo routing.

Power connects to 3v3 (red/yellow), ground (brown/green) connects to ground and data is sent through D2 (orange/orange)


Manual code

This is the code that is meant to be flashed to the argon. If you plan to have your project setup to run automatically and be plugged in all the time, uncomment lines 73-76 and comment line 79, If you wish to test times and monitor variables uncomment lines 56 and 62-70 respectively.
#include <ArduinoJson.h>

StaticJsonDocument<512> doc;
// create servo object to control a servo
Servo myservo;  
// variable to store the servo position
int pos = 0;    

void setup()
    // Subscribe to the webhook response event
    Particle.subscribe("hook-response/sunset", myHandler, MY_DEVICES);
    myservo.attach(D2);  // attaches the servo on the D2 pin to the servo object

void loop() {
  // Get some data
  String data = String(180);
  // Trigger the integration
  Particle.publish("sunset", data, PRIVATE);
  // Wait 6 seconds

void myHandler(const char *event, const char *data)
    //retrieving only the hour from the char returned by my webhook and making it into an int
    String colin (":");
    String WordSearch (data);
    int colinPos = WordSearch.indexOf(colin, 0);
    String calcTime = WordSearch.substring(0, colinPos);
    int intCalcTime = calcTime.toInt();
    int finalTime = 0;
    // Converting UTC time to Central time
    if( intCalcTime == 10)
    finalTime = 4;
    else if( intCalcTime == 11)
    finalTime = 5;
    else if( intCalcTime == 12)
    finalTime = 6;
    else if( intCalcTime == 1)
    finalTime = 7;
    else if( intCalcTime == 2)
    finalTime = 8;
    else if( intCalcTime == 3)
    finalTime = 9;
    else if( intCalcTime == 4)
    finalTime = 10;
    else if( intCalcTime == 5)
    finalTime = 11;
    //uncomment line below to test different times
    //finalTime = 7;
    //calculate Servo Angle
    double ServoAngle;
    if (finalTime > 7) 
    ServoAngle= 180;
    ServoAngle = 180-((double)(finalTime-4)/3)*180;
   //Uncomment these printlines to troubleshoot any timezone conversion issues and check variables
    Serial.print("Webhook Sunset ");
    Serial.println("Sunset String " + WordSearch);
    Serial.println("Colin Position " + colinPos);
    Serial.println("Hours String " + calcTime);
    Serial.print("ServoAngle ");

    //uncomment to have code run automatically at the set time everyday
    //if (Time.hour(
    //comment the line below if intending to run automatically as described above
    myservo.write((int)ServoAngle); //this code actually sets the servo angle


Matthew Aggari

Matthew Aggari

2 projects • 2 followers


Add projectSign up / Login