October 27, 2020

Pcomp2 - Sensors, knobs, and Serial Data

In the chapter, we will learn some basic knowledge about sensors and data…


In the broadest definition, a sensor is a device, module, machine, or subsystem whose purpose is to detect events or changes in its environment and send the information to other electronics, frequently a computer processor. A sensor is always used with other electronics.


1.Serial Data

Using the hello sketch, play with the serial monitor( In the Arduino menu Tools>Serial Monitor) to tell a wee story (3 lines long) based on player input.


You can check my codes and see what printed:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println("what's your name?");
Serial.println("JOJO da!!!");
Serial.println("emmm? ma sa ka?!ah...");


}

void loop() {


if(Serial.available())
{
Serial.print("Hello "); //this will read serial data
String s = Serial.readString();
Serial.println(s);
}
}

2.Potentiometers (Knobs)

Hook up a knob and have it change the brightness of an LED.



3.Light Dependent Resistors

Hook up an LDR. Try making the LED change brightness depending on the light level.



4.Playing with Common Sensors

I tried to use the PIR sensor and buzzer, created an alarm through to detect whether someone enters or is active in the area.



About this Post

This post is written by Siqi Shu, licensed under CC BY-NC 4.0.