• WORK
  • ABOUT
  • LABS
  • BLOG
Menu

WAWA LABS

  • WORK
  • ABOUT
  • LABS
  • BLOG
Screen Shot 2019-10-01 at 7.51.25 PM.png
Screen Shot 2019-10-01 at 7.51.15 PM.png
Screen Shot 2019-10-01 at 7.51.37 PM.png
Screen Shot 2019-10-01 at 7.51.48 PM.png
Screen Shot 2019-10-01 at 7.51.25 PM.png Screen Shot 2019-10-01 at 7.51.15 PM.png Screen Shot 2019-10-01 at 7.51.37 PM.png Screen Shot 2019-10-01 at 7.51.48 PM.png

ANALOG - Servo Motor Control

October 1, 2019
//1. Find out range of sensor
void setup() {
  Serial.begin(9600);       // initialize serial communications
} 
 
void loop() {
  int analogValue = analogRead(A0); // read the analog input
  Serial.println(analogValue);      // print it
}


//2.Map the result into 0-179
void setup() {
  Serial.begin(9600);       // initialize serial communications
} 
 
void loop()
{
  int analogValue = analogRead(A0); // read the analog input
  Serial.println(analogValue);      // print it
 
  int servoAngle = map(analogValue, 0, 1023, 0, 359);
//}


So I had a questions on this step.

Where does 9600 come from: ‘Serial.begin(9600)’

Screen Shot 2019-10-01 at 8.12.05 PM.png

Where does 1023 come from: ‘int servoAngle = map(analogValue, 0, 1023, 0, 179)’

Screen Shot 2019-10-01 at 7.46.58 PM.png

//3.
#include <Servo.h> // include servo library

Servo servoMotor;
int servoPin = 9;

void setup() {
Serial.begin(9600);
servoMotor.attach(servoPin);
}

void loop() {
int analogValue = analogRead(A0);
Serial.println(analogValue);

//0-1023
int servoAngle = map(analogValue,0,1023, 0,360);
Serial.println(servoAngle);
servoMotor.write(analogValue);

Creative Application

Idea sketch

IMG_0108.jpg IMG_0107.jpg IMG_0105.jpg IMG_0109.jpg
← Digital INPUT/OUTPUT - Tone outputINPUT/ OUTPUT →

© 2021 All Rights Reserved