Nathan FeggelerCooper RhodesReeves Rowan
Published

Group 22 IOT Project | Fall 2023

A better way to wake up for all the sleepy heads out there. Enhances your phone alarm to ensure you wake up and have a productive day.

IntermediateShowcase (no instructions)15 hours98
Group 22 IOT Project | Fall 2023

Things used in this project

Hardware components

Photon 2
Particle Photon 2
×3
Adafruit Waterproof DS18B20 Digital temperature sensor
Adafruit Waterproof DS18B20 Digital temperature sensor
×1
Photo resistor
Photo resistor
×1
IR Transmitting and Receiving
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Micro USB cable
TinyCircuits Micro USB cable
×1
SparkFun Solder-able Breadboard - Mini
SparkFun Solder-able Breadboard - Mini
×3
Breadboard (generic)
Breadboard (generic)
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)
Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free
Wire Stripper & Cutter, 32-20 AWG / 0.05-0.5mm² Solid & Stranded Wires
Wire Stripper & Cutter, 32-20 AWG / 0.05-0.5mm² Solid & Stranded Wires

Story

Read more

Custom parts and enclosures

IR & Light Stand Cad Model

Temperature Sensor Mount Cad Model

Particle Photon Box Cad Model

Schematics

IR & Light Stand Circuit Diagram

Temperature Sensor Circuit Diagram

Servo Circuit Diagram

Code

IR & Light Sensor Code

C/C++
// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_IO_Particle.h>

// This #include statement was automatically added by the Particle IDE.
#include <ServoIn.h>

SerialLogHandler logHandler;
// This #include statement was automatically added by the Particle IDE.

const int irSensorPin = 2;
const int photoresistorPin = A2;

Servo myServo;


void setup() {
   myServo.write(110);
    Serial.begin(9600);
    pinMode(irSensorPin, INPUT);
   
    myServo.attach(4);
    
    
}

void loop() {
int temp = 1;
int IrSensorValue = 69420;

int sensorValue = digitalRead(irSensorPin);

// Print the sensor value
  Serial.print("IR Sensor Value: ");
  Serial.println(sensorValue);
 
    myServo.write(40);   // move the servo back to 40 degrees (starting position)
    delay(1000);        // wait for a second
    myServo.write(110);

   int lightValueNEW;
    int lightValue = analogRead(photoresistorPin);
    
    int sensorValueNew;
    


  
  lightValueNEW = String(lightValue).toInt();
  sensorValueNew = String(sensorValue).toInt();

    if(lightValue < 850){
        Particle.publish("Light Baby Gurl");
        Particle.variable("LightData", lightValue);
        
       Particle.publish("LightDataNEW", "lightValueNEW",PUBLIC);
    }else{
        Particle.publish("Dark");
    }
   
   
   if( sensorValue < 1){
       Particle.variable("SensorValue", sensorValueNew);
       Particle.publish("IN IF");
       Particle.publish("sensorValue", "sensorValueNew", PUBLIC);
   }
 

  // Delay for 2 seconds
  delay(300);

}

Servo Code

C/C++
// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_PWMServoDriver.h>

Servo myservo;


void myHandler(const char *event, const char *data){
    
    if(strcmp(data, "lightValue")>0){
        myservo.write(0);
  delay(250);  // Wait for 1 second
Particle.publish("high light ");
  // Move the servo to 30 degrees
  myservo.write(110);
  delay(250);  // Wait for 1 second

  // Move the servo to the initial position (0 degrees)
  myservo.write(0);
  delay(250);  // Wait for 1 second

  // Move the servo to 30 degrees
  myservo.write(110);
  delay(250);  // Wait for 1 second
    }
    
    
}
void myHandler2(const char *event, const char *data){
    
    if(strcmp(data, "sensorValueNew")<1){
        
        Particle.publish("in servo loop ");
        myservo.write(180);
        delay(200);  // Wai
        myservo.write(0);
    }
}




void setup() {
Particle.publish("Start up complete");
Particle.subscribe("LightData", myHandler);
Particle.subscribe("sensorValue", myHandler2);
myservo.attach(A5);
}

Temperature Sensor Code

C/C++
// This #include statement was automatically added by the Particle IDE.
#include <OneWire.h>

// This #include statement was automatically added by the Particle IDE.
#include <spark-dallas-temperature.h>

// Data wire is conntec to the Arduino digital pin 4
#define ONE_WIRE_BUS D2

#define DS18_h

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
SerialLogHandler logHandler; 
// Pass our oneWire reference to Dallas Temperature sensor 
DallasTemperature sensors(&oneWire);

int i = 0;

void setup()
{
  Serial.begin(9600);
  sensors.begin();
    Particle.subscribe("TempValue", myHandler3);
    
    int  TempValueNEW;
}

void loop(){ 
  // Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus
  sensors.requestTemperatures(); 
  float x = sensors.getTempFByIndex(i);
  Particle.publish("Temp", String (x), PRIVATE);
  delay(2000);
  i++;
  
  TempValueNEW = String(TempValue).toInt();
  
  Particle.variable("TempData", TempValue);
        
       Particle.publish("TempDataNEW", "TempValueNEW",PUBLIC);
       
       delay(10000);
  
  
}

Credits

Nathan Feggeler
1 project • 0 followers
Cooper Rhodes
1 project • 0 followers
Reeves Rowan
1 project • 0 followers
Thanks to Tyler Bletcsh.

Comments