top of page

TOOL BOX

 1.0 Arduino info

Pinout-NANO33IoT_latest.png

 2.0 Voltage dividers

maxresdefault.jpeg

lab #1: digital input and output with arduino

LabDigitalInOut_schem.png
WechatIMG1499.jpeg
IMG_6477_edited.jpg

Digital Input:

Pushbutton

Digital Output:

Two LEDs

New Code I Learned:

In the setup shown on the left, a digital input will be triggered by the pushbutton. 'HIGH' means there's a current, and the switch is closed, then the output will be sent to LEDs.

week2-1.gif

code

I intended to also try the same setup with two speakers. Luckily, I found two new speakers in the 'Junk Area'. But unluckily, those two speakers did not work. The reason for that is those speakers require an oscillating current, instead of a steady DC current. 

This is a link to a similar project involving this kind of speaker and Arduino. 

And btw, this website () has a lot of interesting Arduino projects. 

Basically, PWM (Pulse Width Modulation) will convert the digital output into an analog output. By changing the duty cycle of PWM, an oscillating output will be created at a certain frequency (PWM pins produce signals at 490Hz or at 980Hz).

In order to make the speaker 'speak', I should also use tone( ), which I will learn more about in Week 3.

IMG_6509.heic

lab #2: ANALOG INput with arduino

LabAnalogInNano_bb.png
potentiater.gif
WechatIMG1510.jpeg

Analog Input:

Potentiemeter

Analog Output:

Red LED

New Code I Learned:

            *A way for Arduino to talk

            *it sends out a PWM to one pin

I spent a lot of time thinking about this setup.

I was initially confused about whether the potentiometer is connected to the LED.

The gif actually shows that I thought, those two components are connected by intentionally adding a green line. However, the analogWrite command in my code is actually telling the LED to do things. Then I was so confused about if it's me that by twisting potentiometer to make the LED dim and light, or it's the Arduino board.

Now, the problem is solved. Two sides are NOT connected. The Arduino board detects the changing voltage of the potentiometer, then transforms it into another digital output.

IMG_6515.heic
ezgif.com-gif-maker.gif
IMG_6512.HEIC

with phototransistor

with force sensing resistor

Analog Input:

Potentiemeter,FSR

When a phototransistor or FSR is connected to Arduino as an output, by using Serial.print, I am able to see some number changes when I cover the light or apply force to the sensor.

LabAnalogInPhotoTransistorNano_bb.png

*Question unsolved:

Left disgram illustrates when a phototransistor is connected. I wonder why the long end is connected to the ground, the short end is connected to the positive?

Possible answer:

The two ends of a phototransistor represent one emitter and one collector. Collector side is connected to the voltage supply; emitter side is connected to the base.

Different tyes of phototransistor will have different assignment to each leg (just like two diagrams shown below). It's unlike LED with a fix assignment that current flow from long leg to the short. In particular, the one I used in lab : "short leg goes to voltage, long leg to the ground".

phototrans.jpeg

Diagram #1

IMG_6517.heic
1-Phototransistor-Circuit.png

Diagram #2

WechatIMG1529.jpeg

Analog Input:

FSR

New Code I Learned:

       *for defining a variable

WechatIMG1546.jpeg
WechatIMG1527.jpeg

Description:

I remember I was actually very struggled with this section because I kept having the negative lightness value. So then I just left it there for that day.

The next day, I re-wrote the code, change the number:

float voltage = sensorReading * (5.0 / 1023.0)

int lightness = map(sensorReading, 0, 1023, 0, 5)

It worked, but I forgot to take a screenshot...

The reason for the negative lightness should be 'out of range', possibly less than 100 (?), then what's converted into 0-5 scale, it is negative.

lab #3: Sensor change detection

IMG_6521.heic
1.jpg

Digital Input:

Pushbutton

New Code I Learned:

"Detect a state change"

11.jpg
2.jpg
22.jpg
3.jpg
33.jpg

"Press Count"

Left shows the first time I try to count the press. The printed numbers are extremely high. The right shows that I add one line at the bottom to let buttonstate return to LOW. The reason for the left result is because the buttonstate is always HIGH so that it is kepting counting the times.

HOWEVER, everytime I push the button, it counts twice. I asked around of other people, they have the same issue. I think this is because, in the code, HIGH/LOW actually also mean a certain number. When I press and release the button, as the voltage drops during the releasing state, it is still comparatively higher voltage than the LOW. That's why, it double counts. 

A way to fix this would be set a strict votage number for HIGH and LOW.

WechatIMG1548.jpeg

"Long press, short press"

Analog Input:

FSR

New Code I Learned:

*data type: long and unsigned long? what are they?

Description:

During the process, I missed a { sign after 'else', so the code did not run.

WechatIMG1549.jpeg
4.jpg
44.jpg

"Detect a peak"

There are in total 3 'if' statements.

* If there is no command after an 'if' statement, the computer will do nothing, right?

e.g. the second 'if' follows no instruction, then sensorValue less than the threshold will not be printed. But why is this 'if' necessary?

why not

   if (sensorValue > peakValue) {

       peakValue = sensorValue;

}

  if (peakValue > threshold ) {

       Serial.println(peakValue);

}

SAD : (

but why?

WX20210924-140222_2x.png
Hey Jeff, I add this section for you to leave any suggestions or comments. NO PRESSURE, you don't have to leave something : )

bottom of page