Week #13

Input Devices





This week focuses on input devices. Input devices are used to sense the environment around us, you can sense and track different parameters using sensors and have them create a certain action based on that input.


Learning:


Group Assignments

Testing Analog Levels and Digital Signals

In this part we measured the level of a Push Button in its two states, Normal and Pressed. The push button (normally open) is connected to Vcc through 10kOhm resistor, so in its normal state the level will be 5 V (digitally high). When pressed the level will be 0 V (digitally low).

ID_16

Using the Digital Multimeter, in the normal state the measured value is 5.05 V (digitally 1 or high), and when pressed, the measured value is -1.1 mV (digitally 0 or low).

ID_17

We used Oscilloscope to measure the same input signal. To connect the oscilloscope probe, connect the spring loaded end (hock or clamp) to GND and the pin head to test point, which is the push button signal.

ID_18

Note that voltage scale is 2 V/division and time scale is 500 ms/division.
In the normal state, the signal height is 2.5 vertical divisions, which equals to 5V (2.5 divisions x 2 V/division). When the button is pressed, the level drop to fit over the zero line. The button had been pressed for 2 seconds (4 horizontal divisions x 500 ms/division).

ID_19

Individual Assignments

Ultrasonic Sensor

In this assignment, I want to design a board similar to the board for the final project, Ultrasonic Sensor will be the major input devices in my PCB + Buzzer and some LED's.

An Ultrasonic Sensor is an instrument that measures the distance to an object using ultrasonic sound waves. An ultrasonic sensor uses a transducer to send and receive ultrasonic pulses that relay back information about an object's proximity.

ID_1

PCB Schematic

The schematics of this PCB is almost the same for the previous PCB at week 6 and week 10, with a difference in the inputs to be 4 pin headers for the Ultrasonic Sensor and 6 LED's + 1 Buzzer as output. I removed the power inputs (Voltage Regulator).

ID_2

PCB Layout

For the board layout, I distributed the components as before, with addition of buzzer pin headers and the 4 pin headers for the ultrasonic sensor.
I connected each LED's row leg together. The last two legs with MISO pin, and the middle legs with SCK pin, and the front two legs and buzzer with MOSI pin.

OD_3

I have only one wire "GND" unconnected, so I decided to extend an external wire after finishing the board production.

OD_4

Here's the board ready to be exported.
So, I turned off all layers and kept the Top and Pads, and exported as image.

ID_5

The second image with Dimension and Pads layers.

ID_6

For the Outline image, I painted the inner area with white color and kept the pads holes in black in order to drill it.

ID_7

Mods CAM

After the two images are ready, I opened Mods and import the first image Trace, with the same previously options.

ID_8

Here's the traces toolpath.

ID_9

And for the second image, also the same previously options.

ID_10

And here's the outline toolpath.

ID_11

Soldring


After about an hour, the machine finished making the two images.

ID_12

Here's the components to be soldering.

ID_13

And here's the PCB ready to programming 😁

ID_14

Programming

Final stage is to write the code.

ID_15

The code I used is below 👇

                    
int led1 = 5; //MISO YELLOW int led2 = 4; //SCK WHITE int led3 = 6; //MOSI BUZZER/RED void setup() { pinMode(led1, OUTPUT); pinMode(led2, OUTPUT); pinMode(led3, OUTPUT); } void loop() { digitalWrite(led1, HIGH); delay(1000); digitalWrite(led1, LOW); delay(1000); digitalWrite(led2, HIGH); delay(1000); digitalWrite(led2, LOW); delay(1000); digitalWrite(led3, HIGH); delay(1000); digitalWrite(led3, LOW); delay(1000); }



The second code with the input "Ultrasonic Sensor":

The code I used is below 👇

                    
int Yellow = 5; // PA5 MISO YELLOW int WHITE = 4; // PA4 SCK WHITE int RED = 6; // PA6 MOSI BUZZER/RED int trig = 7; // PA7 > 6 Trig int echo = 8; // PB2 > 5 Echo long duration, distance; int cm = 0; void setup() { Serial.begin(9600); Serial.println("Serial Started..."); pinMode(echo, INPUT); pinMode(trig, OUTPUT); pinMode(Yellow, OUTPUT); pinMode(WHITE, OUTPUT); pinMode(RED, OUTPUT); } void loop() { digitalWrite(trig, LOW); digitalWrite(trig, HIGH); digitalWrite(trig, LOW); int duration = pulseIn (echo, HIGH); cm = duration*0.034/2; Serial.println(cm); if (cm >= 30) { digitalWrite(Yellow, LOW); digitalWrite(WHITE, LOW); digitalWrite(RED, LOW); delay(1000); digitalWrite(Yellow, HIGH); digitalWrite(WHITE, LOW); digitalWrite(RED, LOW); delay(1000); } else if (cm < 30 && cm > 15) { digitalWrite(Yellow, LOW); digitalWrite(WHITE, LOW); digitalWrite(RED, LOW); delay(500); digitalWrite(Yellow, LOW); digitalWrite(WHITE, HIGH); digitalWrite(RED, LOW); delay(500); } else if (cm < 15 && cm > 5) { digitalWrite(Yellow, LOW); digitalWrite(WHITE, LOW); digitalWrite(RED, LOW); delay(250); digitalWrite(Yellow, LOW); digitalWrite(WHITE, LOW); digitalWrite(RED, HIGH); delay(250); } else if (cm <= 5) { digitalWrite(Yellow, LOW); digitalWrite(WHITE, LOW); digitalWrite(RED, HIGH); delay(100); } }



You can download my files here:


Previous Week Next Week