Skip to content

Week 11. Input Devices

This week we learnt about input devices. And as usual, we have both individual assignment and group assignment. - Individual assignment is to measure something: add a sensor to a microcontroller board that you have designed and read it.
- Group assignment is to probe an input device’s analog levels and digital signals using an oscilloscope either a handheld one or a desktop one.

First of all, with the skills learnt in the previous week, I used Eagle to design a new board.

I decided to use similar components from the Week 07 Electronics Design for making the microcontroller. Besides, as we are learning about input devices this week, I will add a Cherry MX keyboard button as the input device.

Item Component Name Quantity
1 10k resistor 1
2 20 MHz resonator 1
3 1uF capacitor 1
4 ATtiny 44 IC 1
5 2x03pin header (AVRISP) 1
6 1x06pin header (FTDI) 1
7 Cherry MX keyboard button 1

(1) I need to add the cherry library.
(2) Create a new project
(3) Add all components into the schematics
(4) Wire them up
(5) Generate the PCB board
(6) Routing

When trying to export the PCB design file for milling, I noticed that I couldn’t export the file correctly. On the one hand, when exporting the traces, I couldn’t hide the button frame. On the other hand, I will have to drill two holes for the two pins of the Cherry MX.

So I decided to replace the Cherry MX with a 6mm button for now. And then I will experiment the Cheery MX later when I have more time.

Besides the Cherry MX keyboard, I also want to try other sensors, so I started my experimentation.

Experiment #1 Light sensor
My mentor told me that I can use a 1206 resistor as a light sensor. so I decided to design a board using a 1206 as the light sensor.
I decide to use the following components:

Item Component Name Quantity
1 10k resistor 2
2 20 MHz resonator 1
3 1uF capacitor 1
4 ATtiny 45 IC 1
5 2x03pin header (AVRISP) 1
6 1x06pin header (FTDI) 1
7 1206 Fab resistor (Light Sensor) 1

Following the same rules to design my board. Since there are only a few components, I use “net” to connect the pins directly instead of using “net” + “name”.

(schematics of the input device - light sensor)

And then I created the board, and then route up the parts, and then export the png files.

(input device - light sensor)

I used Fab Modules to create the .rml files for milling the PCB. However, when I gout the PCB board, I noticed it did not turn out as expected. (Some parts are not supposed to connected, but they did.) I wanted to use a knife to cut off those parts, but then I realized it will be even more time-consuming and the result was not guaranteed. So I decided to redesigned the PCB board.

(the pcb board - light sensor V1)

And here is the updated design.

(the board - light sensor V2 )

I used Fab Modules to output .rml files of the traces and the outline.

And here is the new PCB board!
(PCB board light sensor V2)
I checked and it seemed this time it did cut well. Looking back, I realized the problem of the previous failure was not in the layout of the components, but in the design rules. I forgot the change the settings of the design rules. Lesson learnt!

It did not take me long to solder the components onto the board.To save myself from the trouble of troubleshooting, I used the multimeter to check soldering to see whether the parts are connected correctly and see whether there are any short circuits. Now the multimeter is one of the must-use tools when I am in the lab tinkering with circuits.


And here is the board with all the components soldered to the right places.

(soldered board light sensor V2)

Now it’s time to check whether it works or not!

Apparently there was something wrong with my design, it couldn’t be recognized on my MacBook. So I redesigned the board, and here is the new schematics and the board in Eagle.

And here is the new design.

(schematics of the new design)

(board of the new design)

(freshly-milled PCB board of the new design)

(soldered PCB board)

In case I make other design faults or solder faults (shorts), I used the multimeter to check the circuits. Everything seems to be correct. Then I connected the light sensor with USBTiny and to my MacBook.

I opened Arduino IDE, made settings for this board: board, processor, clock, and programmer.

And click “Burn Bootloader”, and it was successful!!

Time for coding!!

But the coding process was quite frustrating, because the code did not seem to work. The value on the serial monitor did not change no matter the light sensor was in bright or dark environment. After many hours debugging, we found some design faults. Thank you to my local instructor Yufei’s guidance and instruction.

I re-checked my schematics and I realized the previous version was not readable enough especially when I tried to use wires to connect the baord with USB-TTL to my MacBook.

So I drew the components onto my notebook, and tried to clear the confusion.

(hand-drawing schematics to analyze)

(updated schematics)

(design faults)

  • No.1 : the two lines should all be connected to VCC

  • No.2 : R2 should be 1k instead of 10k (got this info from the vendor’s documentation. the color sensor I used CXDSMD026 1206.)

So I desoldered the 10k R2, and soldered a 10k resistor onto the board, and also used solder joint to connect the two lines.

See the new board below. (might be hard to tell the changes, but it’s working!)


With the board fixed, I started to program it.

Arduino + CoolTerm

First of all, I connected my Light Sensor with the USBTiny and then to my MacBook Air.

Choose the right settings for board, processor and clock at Tools.

And upload the following code to the board.

#include "SoftwareSerial.h"

const int analogInPin = PB3;  
int sensorValue = 0;        
int outputValue = 0;       

const int Rx = 1;
const int Tx = 2;
SoftwareSerial mySerial(Rx, Tx);

void setup() {
  pinMode(PB3, INPUT);
  pinMode(Rx, INPUT);
  pinMode(Tx, OUTPUT);

void loop() {
  sensorValue = analogRead(analogInPin);
  outputValue = map(sensorValue, 0, 1023, 0, 255);


Then I disconnected the USBtiny, and connected the Light Sensor with the USB-TTL. And the pins should be connected in the following way:

USB to TTL Light Sensor

And then I connected the USB-TTL to my computer, chose the right port on Arduino.

When I opened the serial monitor on Arduino, I can see the value, when I use flashlight from my phone to increase the light exposure to the light sensor, the value changes, please see the video below.

Another way to visualize light value on the light sensor is to use CoolTerm, which is recommended by my local instructor Yufei.

After installing CoolTerm on my computer. Open the client, and follow this path: Options => Re-Scan Serial Ports => choose the right port (mine is usbserial-1420) and the baudrate (mine is 9600) => OK => Connect

After connected, I can see the value on the CoolTerm window. When the light is creased, the value decreases, you can see from the following video.

C + Python

I also tried C programming + python visualization of the light sensor.

First of all, I downloaded Neil’s C code hello.light.45.c and hello.light.45.make onto my desktop.

I connected the Light Sensor with the USBTiny to my computer.

And then I opened Terminal, type the following code and presse enter/return

make -f hello.light.45.make program-usbtiny

After it showed the following code, it’s flashed with the C code.

I downloaded Fab Academy’s python code to visualize the light sensor data via Python.

After downloading the code, open Terminal and type the following code:

python /dev/cu.usbserial-1420  

and press enter, and a window popped up.

Please note, “/dev/cu.usbserial-1420” is my serial port. You should use your change to your own serial port.

Files for downloading