What is an Input Device?

 

An input device is an equipment/Component used to provide data and control signals to an information processing system such as a Micro Controller. Examples of input devices include Sensors, Cameras etc.

 

Sensors & Transducers

A sensor is a transducer whose purpose is to detect some characteristic of its environments. It detects events or changes in quantities and provides a corresponding output, generally as an electrical or optical signal. Transducers are measurement devices used to change one kind of energy to another. Energy may include electrical, mechanical, electromagnetic, chemical, acoustic, and thermal energy.

 

 

Assignment:

Individual

-Measure something: add a sensor to a microcontroller board that you have designed and read it

 

Group

-Measure the analog levels and digital signals in an input device

 

Software :

-Eagle

-Mods

-Arduino IDE

 

Materials :

-FR1

-Eelectronic Components

-Sensors

-Datasheets

 

Accomplised

 

-Understood how to connect an input device in a circuit

-Read datasheet of the used input device

-Learnt the difference between analog and digital values

-Designed, milled and soldered a board with 2 Sensors

-Read the data from the sensors

 

 

Group Work

 

Download Files

Devices which perform an "Input" function are commonly called Sensors because they "sense" a physical change in some characteristic that changes in response to some excitation, for example, heat or force and convert that into an electrical signal. Devices which perform an "Output" function are generally called Actuators and are used to control some external device, for example, movement or sound.

Analogue and Digital Sensors

 

Analogue Sensors

 

Analog Sensors produce a continuous output signal or voltage which is generally proportional to the quantity being measured. Physical quantities such as Temperature, Speed, Pressure, Displacement, Strain etc are all analog quantities as they tend to be continuous in nature. For example, the temperature of a liquid can be measured using a thermometer or thermocouple which continuously responds to temperature changes as the liquid is heated up or cooled down.

Digital Sensors

 

As its name implies, Digital Sensors produce a discrete digital output signals or voltages that are a digital representation of the quantity being measured. Digital sensors produce a Binary output signal in the form of a logic “1” or a logic “0”, (“ON” or “OFF”). This means then that a digital signal only produces discrete (non-continuous) values which may be outputted as a single “bit”, (serial transmission) or by combining the bits to produce a single “byte” output (parallel transmission).

My Input Devices

 

As its name implies, Digital Sensors produce a discrete digital output signals or voltages that are a digital representation of the quantity being measured. Digital sensors produce a Binary output signal in the form of a logic “1” or a logic “0”, (“ON” or “OFF”). This means then that a digital signal only produces discrete (non-continuous) values which may be outputted as a single “bit”, (serial transmission) or by combining the bits to produce a single “byte” output (parallel transmission).

Passive InfraRed

 

PIR sensors allow you to sense motion, almost always used to detect whether a human has moved in or out of the sensors range. They are small, inexpensive, low-power, easy to use and don't wear out. For that reason, they are commonly found in appliances and gadgets used in homes or businesses. They are often referred to as PIR, "Passive Infrared", "Pyroelectric", or "IR motion" sensors.

 

How PIRs Work

 

The PIR sensor itself has two slots in it, each slot is made of a special material that is sensitive to IR. The lens used here is not really doing much and so we see that the two slots can 'see' out past some distance (basically the sensitivity of the sensor). When the sensor is idle, both slots detect the same amount of IR, the ambient amount radiated from the room or walls or outdoors. When a warm body like a human or animal passes by, it first intercepts one half of the PIR sensor, which causes a positive differential change between the two halves. When the warm body leaves the sensing area, the reverse happens, whereby the sensor generates a negative differential change. These change pulses are what is detected.

The PIR Sensor

 

The IR sensor itself is housed in a hermetically sealed metal can to improve noise/temperature/humidity immunity. There is a window made of an IR-transmissive material (typically coated silicon since that is very easy to come by) that protects the sensing element. Behind the window are the two balanced sensors.

Lenses

 

PIR sensors are rather generic and for the most part vary only in price and sensitivity. The lens is just a piece of plastic, but that means that the detection area is just two rectangles. Usually, we'd like to have a detection area that is much larger. To do that, we use a simple lens such as those found in a camera: they condense a large area (such as a landscape) into a small one (on film or a CCD sensor). For reasons that will be apparent soon, we would like to make the PIR lenses small and thin and moldable from cheap plastic, even though it may add distortion. For this reason, the sensors are actually Fresnel lenses:

Phototransistor

 

A Phototransistor is an electronic switching and current amplification component which relies on exposure to light to operate. When light falls on the junction, reverse current flows which are proportional to the luminance. Phototransistors are used extensively to detect light pulses and convert them into digital electrical signals. These are operated by light rather than electric current. Providing a large amount of gain, low cost and these phototransistors might be used in numerous applications.

 

How Phototransistor Work

 

Phototransistors work in a similar way to photoresistors commonly known as LDR (light dependent resistor) but are able to produce both current and voltage while photoresistors are only capable of producing current due to change in resistance. Phototransistors are transistors with the base terminal exposed. Instead of sending current into the base, the photons from striking light activate the transistor. This is because a phototransistor is made of a bipolar semiconductor and focuses the energy that is passed through it. These are activated by light particles and are used in virtually all electronic devices that depend on the light in some way. All silicon photosensors (phototransistors) respond to the entire visible radiation range as well as to infrared. In fact, all diodes, transistors, Darlington's, triacs, etc. have the same basic radiation frequency response.

Each Senor comes with a datasheet. The datasheet explains the package information of the sensor, description, and features. Also is a schematic of the sensor. Characteristics of the sensor such as power and temperature information are also provided. These are the datasheet of the sensors I used.

https://www.electronics-notes.com/articles/electronic_components/transistor/what-is-a-phototransistor-tutorial.php

https://www.elprocus.com/phototransistor-basics-and-advantages/

ATTINY 44- SSU

 

I decide to go with attiny 44 for this week's assignment. So to get started I had to go through the datasheet and pinouts to understand where to connect my input devices. Since both my sensors were analog in nature, I will have to keep in mind to connect them appropriately.

Since the I wanted to sensors like PIR and IR which are analog in nature, the coding for the same has to be considered. Hence I read the data sheet for the same. Converting the analog values is an essential part of the process.

 

Analog to Digital Conversion(ADC)

 

An Analog to Digital Converter (ADC) is a very useful feature that converts an analog voltage on a pin to a digital number. By converting from the analog world to the digital world, we can begin to use electronics to interface to the analog world around us. Not every pin on a microcontroller has the ability to do analog to digital conversions. In an Attiny 44, the following are the analog pins.

ADC Pins in Attiny 44

There are 8 ADC pins.ADCs can vary greatly between microcontroller. The ADC on the Attiny 44 is a 10-bit ADC meaning it has the ability to detect 1,024 (210) discrete analog levels. Some microcontrollers have 8-bit ADCs (28 = 256 discrete levels) and some have 16-bit ADCs (216 = 65,536 discrete levels).

The way an ADC works is fairly complex. There are a few different ways to achieve this feat. However, the AVR family microcontrollers use "successive approximation ADC" method.

 

Relating ADC Value to Voltage

 

The ADC reports a ratiometric value. This means that the ADC assumes 5V is 1023 and anything less than 5V will be a ratio between 5V and 1023.

Analog to digital conversions are dependant on the system voltage. Because we predominantly use the 10-bit ADC of the Arduino on a 5V system, we can simplify this equation slightly:

If your system is 3.3V, you simply change 5V out with 3.3V in the equation. If your system is 3.3V and your ADC is reporting 512, what is the voltage measured? It is approximately 1.65V.

If the analog voltage is 2.12V what will the ADC report as a value?

Rearrange things a bit and we get:

Ahah! The ADC should report 434.

Arduino and ADC

 

analogRead()

 

Reads the value from the specified analog pin. The Arduino board contains a 6 channel (8 channels on the Mini and Nano, 16 on the Mega), 10-bit analog to digital converter. This means that it will map input voltages between 0 and 5 volts into integer values between 0 and 1023. This yields a resolution between readings of 5 volts / 1024 units or, .0049 volts (4.9 mV) per unit. The input range and resolution can be changed using analogReference().

 

It takes about 100 microseconds (0.0001 s) to read an analog input, so the maximum reading rate is about 10,000 times a second.

Working of ADC

 

The following diagram explains the parts and the process involved in converting signals.

Each labeled part is explained in detail below.

 

1. PINS

These are the ADC pins on an Attiny 44. The analog sensors are connected to these. Attiny 44 has 8 ADC pins

 

2. Multiplexer

A multiplexer (also sometimes spelled as multiplexor) is a device that can select from several different input signals and transmit either one or more output signals. A demultiplexer is a device that can take a single signal carrying multiple payloads and divide it into several streams.

3. Aref

Another pin which can optionally be used as an external voltage reference pin.

 

4. Clock

The ADC has two fundamental operation modes: Single Conversion and Free Running. In Single Conversion mode, you have to initiate each conversion. When it is done, the result is placed in the ADC Data register pair and no new conversion is started. In Free Running mode, you start the conversion only once, and then, the ADC automatically will start the following conversion as soon as the previous one is finished.

 

The analog to digital conversion is not instantaneous, it takes some time. This time depends on the clock signal used by the ADC. The conversion time is proportional to the frequency of the ADC clock signal, which must be between 50kHz and 200kHz.

 

If you can live with less than 10-bit resolution, you can reduce the conversion time by increasing the ADC clock frequency. The ADC module contains a prescaler, which divides the system clock to an acceptable ADC clock frequency. You configure the division factor of the prescaler using the ADPS bits

5 .Successive Approximations

The algorithm / methodology that converts analog signals to digital signals. This type of conversion is mostly used in AVR microcontrollers.

 

6 .Register

There are four registers related to the operation of the ADC: ADC Multiplexer Select Register (ADMUX), ADC Control and Status Register (ADCSR), ADC Data Register Low (ADCL) and ADC Data Register High (ADCH).

 

ADMUX

 

This register is used to select which of the 8 channel (between ADC0 to ADC7) will be the input to the ADC. Since there are 8 possible inputs, only the 3 least significant bits of this register are used. The following table describes the setting of ADMUX.

You can see that it's possible to load a register with the desired input number and write it to ADMUX directly, as the register does not contain any other flags or setting bits.

If these bits are changed during a conversion, the change will have no effect until this conversion is complete.

 

ADCSR

ADEN (ADC Enable) bit : Setting this bit enables the ADC. By clearing this bit to zero, the ADC is turned off. Turning the ADC off while a conversion is in progress will terminate this conversion.

 

ADSC (ADC Start Conversion) bit : In Free Running Mode, you must set this bit to start the first conversion. The following conversions will be started automatically. In Single Conversion Mode, you must set it to start each conversion. This bit will be cleared by hardware when a normal conversion is completed. Remember that the first conversion after the ADC is enabled is an extended conversion. An extended conversion will not clear this bit after completion.

 

ADFR (ADC Free Running Select) bit : If you want to use the Free Running Mode, you must set this bit.

 

ADIF (ADC Interrupt Flag) bit : This bit is set when an ADC conversion is completed. If the ADIE bit is set and global interrupts are enabled, the ADC Conversion Complete interrupt is executed. ADIF is cleared by hardware when executing the corresponding interrupt handling vector. Alternatively, ADIF is cleared by writing a logical 1 (!) to the flag. This has a nasty side effect : if you modify some other bit of ADCSR using the SBI or the CBI instruction, ADIF will be cleared if it has become set before the operation.

 

ADIE (ADC Interrupt Enable) bit : When the ADIE bit is set and global interrupts are enabled, the ADC interrupt is activated and the ADC interrupt routine is called when a conversion is completed. When cleared, the interrupt is disabled.

 

ADPS (ADC Prescaler Select ) bits : These bits determine the division factor between the AVR clock frequency and the ADC clock frequency. The following table describes the setting of these bits :

ADCL and ADCH

These registers hold the result of the last ADC conversion. ADCH holds the two most significant bits, and ADCL holds the remaining bits.

 

When ADCL is read, the ADC Data Register is not updated until ADCH is read. Consequently, it is essential that both registers are read and that ADCL is read before ADCH.

 

Design

 

As I explained earlier I wanted my board to sense motion and light on an object. So I use PIR and phototransistor for that purpose. Additionally, I wanted to add an LED to the circuit. The LED must blink when certain conditions are met. For eg. When the object is at a certain distance from the sensor and is lit to a certain lux level.

 

To design the components of the circuit I used Neil's board as my reference.

PIR does not require any additional components as the package comes with all necessary arrangements, but the phototransistor needs to be connected in a way.

So the additional resistor must be added. Its called a base resistor. High values of base resistor Rb prevent low levels of light from raising the current levels in the collector-emitter circuit and in this way ensuring a more reliable digital output.

 

There are online Rb calculators such as this.

https://www.electronicproducts.com/Transistor_Switch_Saturation_Calculator.aspx

So after sketching out the basic circuit, these are the list of components required.

 

Component list:

1x ATtiny44

2x 10kΩ resistors

1x 499Ω resistors

1x 1kΩ resistors

1x 1uF Capacitor

1x FTDI Header

1x 6 pin AVRISP Header

1x White LED

 

Sensors:

1x PIR

1xPhototransistor

 

 

Eagle

 

Once I had decided the list of components, I started designing in eagle. The following drawing shows the component list and their names

Components and Names

Once all the components were placed on the board I connected them using the same tags.

Connecting Components

Once the scheme was over, took it to board files. To know about the detailed process of drawing a scheme and working on the board file, please click HERE.

Auto-routing in the board file did not work out great in the beginning. Had to modify the layout a bit until I got it right. I had altered the design rules to suit my needs.

Board File

Once the auto-routing was done, I altered the traces a little and drew the outline. Exported as png. I made 3 files. One for traces, one for cutting and one for drilling. As all these sensors are through-hole components drilling the board is necessary. I exported the drawing as png and took it to Krita to make final files for tracing, drilling and cutting. (More About Krita Click Here)

Krita

Editing File

Trace File

Drill File

Cut File

Trace , Drill and Cut

I took it to milling. At first glance, the traces looked fine and the design looked pretty neat.

Board

So having milled my board I soldered them with the necessary components.  After soldering I checked the connections using the multimeter to check if the connections and soldering was in order

Checking with Multi-Meter

But there was a problem in the board. There was a short circuit somewhere and I couldn't figure out where. At first, I thought it was soldering error. So I started desoldering and checking for errors. It took me a while to figure out what the problem was. It was not the soldering but the board itself. The traces were touching each other in two places, which I did not notice.

Improper Traces

Having figured out the problem I corrected the trace file, re-milled and soldered the board again.

Final Soldered Board

This picture explains the board and its components

Component Explanation

Programming

 

As I had mentioned earlier the basic idea of the board is to satisfy two conditions. Check for motion and check for light on the object. When two conditions are satisfied the LED is supposed to glow. Having this in mind I went through some of the programs available on the internet and formulated a program for my board with the help of a friend at the lab. The first step is to connect the board to FabISP for programming. The following pinout explains how I connected my ISP

I then plugged in my ISP into my USB port and fired up Arduino IDE. Setting the right board is necessary for programming and I have explained this in Week9.

The first step in programming any new board is to burn the bootloader.

A bootloader is basically a program that loads an operating system when an IC is turned on.

Bootloader

Since all the connections were right I didn't have any problems with the bootloader program. It was successful. I then compiled and uploaded my program for PIR + PT.

Board and Sensors

PIR + Phototransistor

Code

#define PT 7

#define PIR 1

#define LED 2

 

int pirState;

int ptValue;

 

void setup() {

  //Serial.begin(9600);

  pinMode(LED, OUTPUT);

  pinMode(PIR, INPUT);

  digitalWrite(LED, LOW);

}

 

void loop()

{

  ptValue = analogRead(PT);

  pirState = digitalRead(PIR);

 

  if (pirState == 1 && ptValue<= 900 )

  {

    digitalWrite(LED,HIGH);

  }

else

{

  digitalWrite(LED,LOW);

}

}

The program was uploaded successfully but I had a problem with the sensor. It took me a while to figure out what the problem was. The sensor was DEAD.!! I had googled the problem and seems like a lot of people had a similar issue.

Circuit

So I decided to change the PIR sensor and try the program again.

Mini PIR and PIR

And this time the board worked fine. This sensor was bigger with an inbuilt potentiometer to adjust delay and range. The LED glowed when both the conditions were met.

 

Now since the PIR is a motion detector I wanted to swap it with IR which is a distance sensor. The IR that we had in our lab had four PINS. VCC, GND, Analog out and Digital Out. I connected to an analog pin. I modified the previous program slightly.

IR + Phototransistor

IR + Phototransistor

Code

#define PT 7

#define IR 1

#define LED 2

 

int irState;

int ptValue;

 

void setup() {

  //Serial.begin(9600);

  pinMode(LED, OUTPUT);

  pinMode(IR, INPUT);

  digitalWrite(LED, LOW);

}

 

void loop()

{

  ptValue = analogRead(PT);

  irState = analogRead(IR);

 

  if (irState <= 500 && ptValue<= 750 )

  {

    digitalWrite(LED,HIGH);

  }

else

{

  digitalWrite(LED,LOW);

}

}

The sensors worked perfectly. The Following video explains the programming and working part of my sensors.

Reading Serial Data

 

To Read the serial Data from the board an FTDI cable is required. I had soldered the FTDI head for this purpose on the board. J.travis Russett 's input week was very helpul for me to understand and how to use an FTDI cable and also programming the arcduino for this purpose. I followed the instructions provided by him to read the data.

Even so, I had problems reading the data. I changed multiple bands and checked to read yet very unsuccessful. I made a very simple mistake that took a long time to realize and rectify. I did not specify the right pins of the FTDI to read the data from RX and TX.

Setting Pin

Code

#define IR 1

#define LED 2

 

// Using an ATTiny44

#include <SoftwareSerial.h>

SoftwareSerial mySerial(0,4);     // RX PA1 12, TX PA0 13 (flipped)

 

int irState;

 

void setup() {

  mySerial.begin(19200);   //Serial.begin(19200);

 

  pinMode(LED, OUTPUT);

  pinMode(IR, INPUT);

  digitalWrite(LED, LOW);

}

void loop()

{

  irState = analogRead(IR);

 

 mySerial.println("IR");

 mySerial.println(irState);

  delay(1000);

 

}

I was able to read the Serial data from the sensor in my arduino program. The serial Monitor can be accessed from the tools menu or by pressing the shortcut Ctrl + Shift + M

I tried reading the data for IR and Phototransistor and the following video explains the process.

Serial Data For Phototransistor

Code

#define PT 7

#define LED 2

 

// Using an ATTiny44

#include <SoftwareSerial.h>

SoftwareSerial mySerial(0,4);     // RX PA1 12, TX PA0 13 (flipped)

 

int ptState;

 

void setup() {

  mySerial.begin(19200);   //Serial.begin(19200);

 

  pinMode(LED, OUTPUT);

  pinMode(PT, INPUT);

  digitalWrite(LED, LOW);

}

void loop()

{

  ptState = analogRead(PT);

 

 mySerial.println("Phototransistor");

 mySerial.println(ptState);

  delay(1000);

 

}

Week 11 Group Work:

 

The assignment was to Measure the analog levels and digital signals in an input device. Electronics is new to all of us and we had to experiment and learn using online tutorials to understand how to complete this assignment. Hence the work was not split but a collective effort. However each one of us had to read about the assignment individually and then we had a discussion on how to go about with the test.

https://www.youtube.com/watch?v=W89sh1I8j0Q

https://learn.sparkfun.com/tutorials/how-to-use-an-oscilloscope

http://www.ni.com/white-paper/53183/en/

These are some of the articles that I went through, and as shown in the video we used LDR to test but in out case we provided current to LDR and that when light changes the voltage changes resulting in bending of the curve.

Conclusion

 

The week took me step closer to my final project. Choosing the right sensor was quite confusing in the beginning. Even be it a distance sensor there is a wide variety of them and choosing the right one for your purpose is important. In my case I wanted two sensor that measures distance and light. Also each sensor has a way in which it has to be connected in a circuit. This week had a lot of research and studying to do. Though it was interesting, it was also trying at times as it was difficult to understand why certain things were done the way they were. Overall it was a great week, with lots to learn.

Files

 

All files can be downloaded from HERE

WEEK 11

The week of Sensors. The week was about understanding input devices and using them in a circuit to measure something. Neil started with the type of connections for input devices and jumped into different input devices, classified as per their field. The best part was each topic had a board layout, program and a video to explain its purpose. I guess all circuits will have some kind of input devices, and this week was very important to understand them.