Recitation 3: Sensors by Jiahui Zhang

Introduction:

In this recitation, we still worked in pairs and built the circuit. I built the circuit connecting with the Joystick Module with my partner You Xu. The analog Joysticks provide two analog input: x and y, and one digital input: z. The most common use of joysticks we see is on the PlayStation as a controller for direction. It provides the most direct feedback as you move the joystick with your thumb.

Building the circuit:

We first decide to try to connect the analog Joystick like the instruction given by Brainy Bits (Here is the link: https://www.brainy-bits.com/arduino-joystick-tutorial/)

One problem I met during the coding was the Serial. begin used in the example was Serial.begin(115200);, but we need to use Serial.begin(9600);. My partner pointed that out and we fixed the problem.

We ran the code and tested it that it actually worked. As we switch the stick and change its direction, the analog reading input number of x and y changes. And when we put the button, the input z, which is defined as “switch” will turn to 0 from 1.

We then decided to connect a LED and a buzzer to the circuit as outputs. 

The LED is controlled by the z (switch). Meanwhile, the buzzer is controlled by the input x. As long as we move the joystick to the left side, the buzzer will ring the melody (because the input x will be greater than 1000). 

How the LED and the buzzer work.

We referred to the example “toneMelody” from Arduino Example library and also the lecture we learned before about how to turn the light on in certain conditions (the if sentence).

Since the Joystick has three input, we decided to add one more component for the output controlled by y. We connect the motor to the circuit and change the code to let the angle of the motor moving correlated to the input y. (Here we referred to the professor’s note of lecture 6).

How the motor works.

And this is the diagram of our final circuit.

Following is our code.

#include “pitches.h”
#include <Servo.h>
Servo servo;
const int SW_pin = 2; // digital pin connected to switch output
const int X_pin = 0; // analog pin connected to X output
const int Y_pin = 1; // analog pin connected to Y output
int melody[] = {
NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4
};

// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
4, 8, 8, 4, 4, 4, 4, 4
};

void setup() {
pinMode(SW_pin, INPUT);
pinMode(3,OUTPUT);
digitalWrite(SW_pin, HIGH);
Serial.begin(9600);
servo.attach(9);
}

void loop() {
int yeah = digitalRead(SW_pin);
int no = analogRead(X_pin);
int okay = analogRead(Y_pin);
Serial.print(“Switch: “);
Serial.print(digitalRead(SW_pin));
Serial.print(“\n”);
Serial.print(“X-axis: “);
Serial.print(analogRead(X_pin));
Serial.print(“\n”);
Serial.print(“Y-axis: “);
Serial.println(analogRead(Y_pin));
Serial.print(“\n\n”);
if(yeah == 0){
digitalWrite(3,HIGH);
}else{
digitalWrite(3,LOW);
}
delay(50);
if(no > 1000){
for (int thisNote = 0; thisNote < 8; thisNote++) {

int noteDuration = 1000 / noteDurations[thisNote];
tone(8, melody[thisNote], noteDuration);

int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
// stop the tone playing:
noTone(8);}
}else{
noTone(8);
}
int mappedokay = map(okay,0,1023,0,180);
servo.write(mappedokay);
delay(50);
}

Question 1:

We intended to create a device that involved multiple outputs in different forms (like sounds, lights, and motions). If our sensor/actuator combination will  be used for pragmatic purposes, people with disabilities in hospital may use it, since they can light up the light by simply pressing a button, and with that same stick, they may control the wheel (or curtain) by the motor. Meanwhile, they can all the nurses in emergency as the set has a buzzer.

Question 2:

I think code is different from the recipe. If you don’t follow the recipe completely, the output (the dishes you make) may still be delicious. But if you write the wrong codes, the output will not even emerge. Meanwhile, it is more likely to an illustration for the machine, since code can be understood as a language both computer and human can understand.

Question 3:

The influence of new media brings a huge impact, or we can say improvement in automatic field, which influcences human social activities, learning, and all perspectives of life in a broader concept. We can see nowadays that the change brought by computer has already been significant in the SNS. Instagram, Twitter, Facebook, and all the interactive, online social way changes our way to make friends and keep contacts with our friends.

One Reply to “Recitation 3: Sensors by Jiahui Zhang”

  1. great job Jiahui!
    two details to consider for the next posts:

    1. Make sure the videos are showing not as links to download.
    2. Copy/Paste the question so if someone else is reading this person can understand what you are answering.

    Anyways, it is good documentation and it is great you added your code too.

Leave a Reply