Skills Dev V: Working with Networking

Made by Yujin Wu, Sohyun Jin and Yiming Jiao

An awesome project where we connect three argon together (and disturb each other)

Created: December 6th, 2023

0
Servo servo;

int servoPin = A2;
int switchPin = D5;
int curSwitchState;
int ledPin = D2;

int servoPos;
int first = 1;


void setup()
{
    pinMode( switchPin , INPUT_PULLUP); // sets pin as input
    pinMode( ledPin , OUTPUT ); // sets pin as output
    servo.attach( servoPin );
    servo.write(0);
    servoPos = 0;
    curSwitchState = digitalRead(switchPin);
    Particle.variable("servoPos", servoPos);
    Particle.variable("buttonState", curSwitchState);
    Particle.subscribe("rotate", handleRemoteRotate);
}


// Last time, we wanted to continously blink the LED on and off
// Since we're waiting for input through the cloud this time,
// we don't actually need to put anything in the loop

void loop() {
    int newSwitchState = digitalRead(switchPin);    
    
    if( newSwitchState == LOW ){
        digitalWrite( ledPin, HIGH);
    }else{
        digitalWrite( ledPin, LOW);
    }

    if (curSwitchState != newSwitchState) {
        Particle.publish("triggerRotate");
        rotateServo(); 
        curSwitchState  = newSwitchState;
    }
    
    delay(1000);
}


int handleRemoteRotate(const char *event, const char *data) {
    rotateServo();
    return 1;
}


int rotateServo() {
    if (servoPos == 0) {
        servoPos = 180;
        servo.write(180);
        return 1;
    } else if (servoPos == 180) {
        servoPos = 0;
        servo.write(0);
        return 1;
    } else {
        return -1;
    }
}
Click to Expand
0

Here is our code to make a subscription of 'rotate' via Webhook. We also added the token of recipient to Webhook in [integrations] on Particle. 

Event Name:  triggerRotate

{

"name": "rotate",

"data": "hello: {{PARTICLE_EVENT_VALUE}}}",

"private": "true",

"access_token": "{recipient's token}"

}

0

Outcome: 

In this project, we explored using Webhook to trigger information for rotating servo motors. Since we are three in a pair, we convey the same signal in one way like A to B, B to C, C to A. 

Process: 

We start experiment with led. By pushing the bottom on each controller, the other's led should be blinking. Then we start to using motor and switch to control and display. Every time the controller's switch pushed, it's motor will rotate and also triggering the other device's motor to rotate.

Next Steps: 

As our final project proposed, we are planing to use hall effect sensor and magnet to trigger the rotation of motors.

Reflection: 

  It was fun to see the series of transferring while telling apart where the servo rotation is triggered from. Once person 'A' switches on the one's circuit board, it directly triggers its servo and in a second conveys the same signal to 'B's servo motor. Once 'B' receives the signal, one can start the triggering to send the signal to one and 'C'. In a row, we could make round signal-transfer-points.


0
0

Above: a demonstration video (full screen)

0

Above two images: circuit board

x
Share this Project

Courses

48-675 Designing for the Internet of Things 24

· 11 members

A hands-on introductory course exploring the Internet of Things and connected product experiences.


Focused on
About

An awesome project where we connect three argon together (and disturb each other)