# Skills Dev IV: Working with Outputs - Motors & Movement

Created: December 5th, 2021

0

Project: Weather Display

Objective: create a display to show the weather conditions or temperature for the day using a servo motor to control a plastic arm that would indicate the current weather.

0

Process:

I started to work with the servo motor by creating a function that would take a number (between 0 and 180) as input to represent the angular position and position the servo accordingly.

After successfully getting the initial function to work, I created two new functions that would (1) take temperature between 0 and 100 degrees as input or (2) take weather (mapped to discrete numbers 1 through 4)  and move the servo hand to the corresponding angle for that temperature or weather type.

0
``````int servoPin = D2;
Servo myServo;
int servoPos = 0;

void setup() {
myServo.attach(servoPin);
Particle.function("Temperature", servoTemp);
Particle.function("Weather", servoWeather);

Particle.variable("ServoPos", servoPos);
}

void loop() {

}

int servoTemp(String command) {
int temp = command.toInt();
temp = constrain(temp, 0, 100); //make sure it's within range
servoPos = map(temp, 0, 100, 0, 180);
myServo.write(servoPos);

return 1;
}

int servoWeather(String command) {
int weather = command.toInt();
if (weather == 1){
servoPos = 0;
} if (weather == 2){
servoPos = 45;
} if (weather == 3){
servoPos = 135;
} if (weather == 4){
servoPos = 180;
}
myServo.write(servoPos);

return 1;
}``````
Click to Expand
0

Figure 1. Wiring of servo motor onto Argon

0

Figure 2. Temperature display interface

0

Figure 3. Weather display interface

0

Video 1: Temperature Display

0
dev4 part1
Youngjoo Lee
0

Video 2: Weather Display

0
dev4 part2
Youngjoo Lee