Skills Dev IV: Jody - Motors & Movement

Made by jmadala

Create an interaction using a motor like the servo, fan, or solenoid that can communicate with me. Ideally, the motor would create the notification generated from an online source using IFTTT, but since the exercise said we did not have to hook up to live data I instead tested this using the Particle cloud.

Created: December 5th, 2020

0

Intention

My goal was to play with a handful of different motors and get comfortable with different motor wirings and code. I wound up making an email notification system that would connect via IFTTT to my servo and show me a red paper exclamation point alert. Per the exercise, I did not use real data (not connected to IFTTT) but I was able to test and show functionality using the Particle cloud. 

0

Using the servo

I started with the servo because it seemed the easiest to wire up ad get the satisfaction of something actually working! 

0
// Define the varibles and call Servo library with an instance called "myServo"
int servoPin = A3;
Servo myServo;
int servoPos = 0;


void setup() {
// Attach the Servo to pin A3 as a reference
myServo.attach (A3);
// Register variable servoControl to particle cloud (input named 'servo') to control Servo from cloud
Particle.function ("servo", servoControl);
// Keep a cloud variable for the current position
Particle.variable ("servoPos", &servoPos, INT);

}

void loop() {

}

int servoControl(String command)
{
    
    // convert string command from Particl cloud to an integer we can use
    int newPos = command.toInt();
    // constrain the entered position so it is between 0 - 180
    servoPos = constrain( newPos, 0, 180);
    // set the Servo
    myServo.write( servoPos);
    // finished
    return 1;

}
Click to Expand
0
IMG 0772
Jody Techy - https://youtu.be/kjR8x1txI98
0

Paper Signal -> email alert! 

My goal is to have a red paper exclamation point that is attached to my servo's arm component increment up each time an email arrives in my inbox. I felt this would be a gentler and more meaningful visualization of the accumulation of email versus the red circle with a count that notifications currently use. Personally, 10 unread emails is enough for me to "feel the email pileup" and at that point, I would like the red paper exclamation point up at 90 degrees which is the max distance it can go (constrained to that upper limit). I would use IFTTT to connect this up, but for purposes of the video below, I tested the functionality using the Particle cloud for now.

Ideally, the system would reset to zero when I've read all my unread emails that came in (not sure how I would do this) but, at a minimum, I could use delay ( ) or millis ( ) to have the whole thing reset to zero after a certain amount of time has passed. 

0
// Define the varibles and call Servo library with an instance called "myServo"
int servoPin = A3;
Servo myServo;
int servoPos = 0;


void setup() {
// Attach the Servo to pin A3 as a reference
myServo.attach (A3);
// Register variable servoControl to particle cloud (input named 'servo') to control Servo from cloud
Particle.function ("email", servoControl);
// Keep a cloud variable for the current position
Particle.variable ("servoPos", &servoPos, INT);

}

void loop() {

}

int servoControl(String command)
{
    
    // convert string command from Particl cloud to an integer we can use
    int newPos = command.toInt();
    // constrain the entered position so it is between 0 - 180
    servoPos = constrain( newPos, 0, 90);
    // set the Servo
    myServo.write( servoPos);
    // finished
    return 1;

}
Click to Expand
0
IMG 0782
Jody Techy - https://youtu.be/2RJPvN21RxA
0

Next - the Fan! 

I used to the setup for the solenoid (though my solenoid did not work) for the fan and show it's ability to turn and blow a couple of paper fragments held on a string. The video shows the live demo and below are two pictures showing the setup as well as the corresponding code.

0
fan
Jody Techy - https://youtu.be/Kcrf9mJ1n9g
0
int solPin = D2;

bool shouldActivate = false;

void setup()
{
  Particle.function( "activate", activateSolenoid );

  pinMode(solPin, OUTPUT);
}

void loop()
{
  if( shouldActivate ){
    doSolenoid(  );
    shouldActivate = false;

  }
  delay( 100 );

}

void doSolenoid(  ){
  for( int i = 0; i < 100; i++ )
  {
    digitalWrite(solPin, HIGH);
    delay( 100 ) ;
    digitalWrite(solPin, LOW);
    delay( 100 );
  }
}


int activateSolenoid( String command ){
  shouldActivate = true;
  return 1;

}
Click to Expand
0

Reflection

I was excited when the servo initially worked and was very satisfied. Working with the solenoid was more challenging that I thought it would be, and I was very worried about ruining my board and components with bad wiring. Even after checking the setup repeatedly, I could not get it to work. I tried both setups - the one we saw in the class demo and the one included in the tutorial (diode placed slightly differently). I gave up and used the fan instead and that worked!

I used the trusty servo which gave me some breathing room not to worry about wiring and code, but instead think about what I would actually enjoy making to solve a problem that I had. But I was glad to use the fan as well and make a simple demo - a stronger fan would allow me to put a clear glass over over it with a pile of small, white paper hope punch-outs and make my own snow globe (inspired by Zimoun). The brushless fan can only move one or two paper fragments, but still good enough to show how a globe could work. 

x
Share this Project

Courses

About

Create an interaction using a motor like the servo, fan, or solenoid that can communicate with me. Ideally, the motor would create the notification generated from an online source using IFTTT, but since the exercise said we did not have to hook up to live data I instead tested this using the Particle cloud.