Week3: DAY1 more sensors

Once again, Do you remember how to read sensors

-digital sensor (PushButton)
-analog sensor (photoCell)

Challenge:
Connect push button or photocell to your Arduino and check the input on SerialMonitor.

challenge1

——code———
int photocellValue=0;
int buttonValue=0;

int buttonPin=5;
int photocellPin=A4;
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
// specify the pin mode, is it input or output?
pinMode(buttonPin,INPUT);
pinMode(photocellPin,INPUT);
}

// the loop routine runs over and over again forever:
void loop() {
// read the input on photocellpin:
photocellValue = analogRead(photocellPin);

Serial.print(“photocell: “);
Serial.print(photocellValue);

// read the input on buttonPin:
buttonValue= digitalRead(buttonPin);

// print out the value you read:
Serial.print(” button: “);
Serial.println(buttonValue);

delay(100); // delay in between reads for stability
}

——————-
More analog sensors
Resistive
- flex sensor
- soft pot
- temperature

Soft pot Round
IMG_2773

Soft Pot straight
IMG_2772

Flex (bend) sensor
IMG_2771

Temperature sensor
IMG_2766

Analog output
- proximate
- Gyro
- 3 Axis Accelerometer

3 Axis Accelerometer
IMG_2769

More digital sensors
- motion sensor
- tilt switch
- Hall effect sensor

Motion sensor
IMG_2770

Tilt Switch
IMG_2768

TONE library

Now, we can connect small speaker and use TONE library to make music!
Well, it does not make a great sound, but it is a good start.

Open tonePitchFollower from Examples/Digital/tonePitchFollower

This sketch will “play a pitch that changes based on a changing analog input”
Let’s first play sound with potentiometer

Here is how you to connect:
tone_conn

What we cover:
tone()

Challenge:
Can you use other kinds of analog sensors to control the pitch of the sound produced?

Challenge:
Add Servo motor to make a strange instrument that plays music and moves at the same time

Challenge:
Can we use digital sensors to play sound like keyboard?

https://github.com/mikst/101

Leave a Reply