Badr M
Published © GPL3+

What Should I Wear Today

A fun build for kids! An indicator that shows them what to wear based on the weather of the day.

BeginnerFull instructions provided2 hours691
What Should I Wear Today

Things used in this project

Hardware components

Argon
Particle Argon
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Li-Ion Battery 100mAh
Li-Ion Battery 100mAh
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×1

Software apps and online services

AWS Lambda
Amazon Web Services AWS Lambda

Story

Read more

Code

python_lambda

Python
The python function that orchestrates the weather reading translation and servo movements
import json
import requests

def get_weather():
    url = "https://api.openweathermap.org/data/2.5/weather?q=Riyadh&appid=TOKEN_HERE&units=metric"
    r = requests.get(url)
    return r.json()
 
    
def lambda_handler(event, context):
    weather = get_weather()
 
    print(weather)
    print("***current tempreture***")
    print(weather['main']['temp'])
    
    degree_cat=((float(weather['main']['temp'])-10)*180)/40
    print("***Deg Cat***")
    print(degree_cat)
    
    if degree_cat <10:
        degree_cat=10
    
    
    r = requests.post('https://api.particle.io/v1/devices/e00fce6897f8a208490db287/MoveTo', data = {'access_token':'TOKEN HERE', 'arg': degree_cat}) 
    
 
    return {
        'statusCode': 200,
        'body': json.dumps('Hello from Lambda!')
    }

Argon code

Java
The code deployed on argon
Servo myservo;  // create servo object to control a servo
                // a maximum of eight servo objects can be created

int pos = 0;    // variable to store the servo position

void setup()
{                                 
  Particle.function("MoveTo", moveServoTO);  

    myservo.attach(D2);   // attach the servo on the D0 pin to the servo object
//    myservo.write(25);    // test the servo by moving it to 25°
    pinMode(D7, OUTPUT);  // set D7 as an output so we can flash the onboard LED
    
     Particle.publish("Setup Module", "STarting", PRIVATE);
}


int moveServoTO(String command)
{   
    myservo.attach(D2); 
    
    int newPos = command.toInt();
    myservo.write(newPos);       
       
    Particle.publish("**Servo Moving TO **"+command, "position:"+ command, PRIVATE);
        
        
    delay(3000);
        
    myservo.detach();

        
        return 1;               // return a status of "1"
    
  //  return 0;
}

void loop()
{
  // empty because we call the gong function via the cloud
}

Credits

Badr M
5 projects • 4 followers
Contact

Comments

Please log in or sign up to comment.