Week11. Input devices¶
This week, I will create a circuit using an input device that uses sensors.
Group Assignment¶
The content of our group assignment is here.
Week11 Group Assignment
Impressions¶
Input data is indicated by a change in voltage.
In addition to using it as it is, I wanted to know how to use a filter to limit it.
Input Devices¶
Use echo Hello world circuit created in Week 9 and add two Grove connectors
Design¶
-
Schematic
-
Board
Cut out¶
I cut the board in three times and took it out.
-
Circuit
-
Holes
-
Round
-
Cutout & Soldering
Programming¶
The program used uses Arduino and Processing,
and sends the input from the sensor to the PC by serial communication.
Arduino¶
The following program was created by Arduino and written.
// Using GroveConnectors #define GROVE_R1 PA2 // Right pin1 #define GROVE_R2 PA3 // Right pin2 #define GROVE_L1 PA7 // Left pin1 #define GROVE_L2 PB2 // Left pin2 // Using Serial I/O // ATTiny44 is not available Hardware Serial // Alternative SoftwareSerial Library #include <SoftwareSerial.h> SoftwareSerial softSerial(0,1); // RX, TX // Variable value int sensorValue_X; int sensorValue_Y; void setup() { // put your setup code here, to run once: pinMode(GROVE_R1,INPUT); pinMode(GROVE_R2,OUTPUT); // notused pinMode(GROVE_L1,INPUT); pinMode(GROVE_L2,OUTPUT); // notused softSerial.begin(19200); } void loop() { // read the value from the sensor: if(softSerial.available()){ softSerial.read(); // analogRead sensorValue_X = constrain(analogRead(GROVE_R1), 0, 254); sensorValue_Y = constrain(analogRead(GROVE_L1), 0, 254); // write x value softSerial.write(sensorValue_X); // write y value softSerial.write(sensorValue_Y); } // wait 100 mill second delay(100); }
Processing¶
The following program was created by Processing and communicated with the circuit.
import processing.serial.*; public static final int HEADER_BYTE = 0xFF; // checkPort Flag boolean isCheckPort = false; int portNumber = 0; // SerialClass object Serial port; // Serial Input(Byte) int[] serialInput = {0,0}; void setup(){ size(300, 300); String[] ports = Serial.list(); if(isCheckPort){ for(int i = 0; i < ports.length; i++){ println(i + ": " + ports[i]); } }else{ // port port = new Serial(this, ports[portNumber], 19200); port.write('a'); } } void draw(){ background(102); // x1,y1,x2,y2 line(20,20,20,300); line(20,20,300,20); // text,x,y text("X",150,15); text("Y",10,150); // x1,y1,x2,y2 rect(20, 20,serialInput[0] , serialInput[1]); } // serialEvent void serialEvent(Serial serial){ if(port.available() >= 2){ serialInput[0] = port.read(); serialInput[1] = port.read(); port.write('a'); } }
Result¶
The following sensors are connected to the Grove Connector
* Variable resister (Right Side)
- Light sensor (Left Side)
I connected the sensor and circuit, sent the read value to the PC, and displayed it with Processing.