Tone Output

Lab: Tone Output Using An Arduino

I used a pressure sensor for the condition of sound and its frequency

void setup() {
  // put your setup code here, to run once:
}

void loop() {
  int press1 = analogRead(A0);
  // put your main code here, to run repeatedly:
  Serial.println(press1);
  
  if(press1 < 200) {
      tone(8, press1);
  } else {
    noTone(8);
  }

Although it is natural, when I press harder the frequency goes low and sound will disappear.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/5a701338-52a1-473a-882e-45214de8775b/IMG_7952.mov

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/1a394da1-cf9d-4fd8-80fc-2c9b18c8693c/image.jpg

I use a 10k Ohm for pressure sensor.

Servo Motor Control

Lab: Servo Motor Control with an Arduino

I put my circuit as below image.

I use my Arduino Micro for this assignment, it of course worked!

First I was mistaken about my circuit of force-sensing sensor. (The ranges go from around 600 to 100)

So I fixed it and wrote code again.

Code here

#include "Servo.h" 
Servo servoMotor;
int servoPin = 3;
void setup() {
  // put your setup code here, to run once:
  servoMotor.attach(servoPin);
}

void loop() {
  int press1 = analogRead(A0);
  // put your main code here, to run repeatedly:
  Serial.println(press1);
  int servoAngle = map(press1, 0, 1023, 0, 179);
  servoMotor.write(servoAngle);
}