Lab: Analog Input, Analog Output with Tone & ServoMotors

Before Start:

Analog In with an Arduino:

GOAL: Connect a variable resistor to a microcontroller and read it as an analog input.

https://itp.nyu.edu/physcomp/labs/labs-arduino-digital-and-analog/analog-in-with-an-arduino/

Tone Output Using an Arduino:

GOAL: generating simple tones on an Arduino.

https://itp.nyu.edu/physcomp/labs/labs-arduino-digital-and-analog/tone-output-using-an-arduino/

Servo Motor Control with an Arduino:

GOAL: control a servomotor’s position from a microcontroller using the value returned from an analog sensor

https://itp.nyu.edu/physcomp/labs/labs-arduino-digital-and-analog/servo-motor-control-with-an-arduino/

Prepartion:

pre-set Arduino & breadboard, jumper wires, potentiometer, resistors (10k, 100, 220), 8 ohm speaker, Force Sensing Resistor (FSR), LEDs

PART I : ANALOG INPUT

Add a potentiometer and LED:

A 220-ohm resistor is connected to digital pin 9. Then the anode of LED to the other side of the resistor. and the LED’s cathode to ground. The wiper of the potentiometer is connect to analog in pin 0 of module.

Program:

Result:

the brightness of the LED changes, yeah!

Replace the LED with a speaker:

Update the Code:


Try tone(pinNumber, frequency); first, but the code can get pinNumber. Change pinNumber to 9 to make the code work. When I went back to read the code, I realized the better way is change pinNumber to ledPin (and change variable name, too)

Result:

the tone goes up and down as I turn the pot, yeah!


PART II : ANALOG OUTPUT WITH TONE

(start with the same pre-set arduino)

Connect the Sensors and Speaker:

Connect a FSR to analog pin 0, and the 8-ohm speaker connects to pin 8. A 100-ohm resistor is with the speaker and a 10k-ohm resistor is with the FSR,

Check the sensor and the speaker:

Write some code to check both the sensor input range and the speak works.

Use 1 second delay to check the speaker, and the result is not obvious enough for me so I add the delay time to 5 seconds to see the result.

the range I got is 0 to ~900 for the sensor.

Test Result:

Play Tones: Codes and result

Read the analog input and map the result to a range from 100 to 1000. The tone() command is to set the frequency of the speaker.


PART III: ANALOG OUTPUT WITH SERVOMOTORS

(start with the same pre-set arduino)

Connect an Analog Input Sensor and a Servo:

Analogt input connected to pin 0. A FSR is connected in the same way in Part II. An RC servmoter is connected to digital pin3.

Hvave some trouble in identiy three lines on the servo . And there is no specification comes with the servo. Solved by trying differenct combinations and seeing the feekback from the servo.

Program the Microcontroller:

the servo library is added at the beginning of the code.

analogRead () is for reading and pringting out the info from the sensor to find out the range of the sensor. Since I use the same one in PART II, the range stays the same: 0 to ~900. Then the result is mapping to 0 to 179 to fit the range of the sensor in degrees. The mapped value is stored in servoAngle.

Result:

servoAngle print out successfully but I am not sure if servo itself worked corretly. Need more time to feagure it out.

Previous
Previous

Lab: Serial Input & Output with P5.js

Next
Next

Lab: Digital Input and Output