11. Input devices¶
For this week I have realized what I have to do is the same of what I did in Week9-Embedded programming where I used Echo Hello Board that I have designed in Week7-Electronics Design as I added phototransitor in the basic echo hello board from the begining.
Board Design and Fabricarion¶
For more details about board design and fabrication visit Week7-Electronics Design
My Schematic of Echo Hello Board¶
Board Routes Design¶
ToolPath For Traces Calculated by using Fab Modules¶
Board Components¶
Board Soldering¶
Board Testing¶
Board Programming:¶
For more details about board design and fabrication visit Week9-Embedded programming
Attiny44 Pins Configurations¶
Refering to the Attiny44 datasheet
My code¶
I started my code with adding a library for serial code which I will be using to get values from the phototransistor.
#include <SoftwareSerial.h>
After that, I have defined my TX and RX pins
#define RX PA1 // *** D3, Pin 2 #define TX PA0 // *** D4, Pin 3
then I have defined my pins in the code for
const int buttonPin = PA3; const int ledPin = PA7;
const is abbreviation of constant which declares the variable to be constant numbers and it cannot be altered by the program and int is a datatype variable that holds a whole number between -32,768 and 32,767.
So I used const int to define my pins on the software. where float is a datatype used to represent a fraction. This entails the use of decimal points for floating point numbers. and I used it for the values of phototransistor.
float lightSens = 0.0;
after that I have added the functions that I want them to be run once only when the board is powered in the void setup section.
void setup() { pinMode(PA2,INPUT); //phototransistor pin pinMode(ledPin, OUTPUT); Serial.begin(9600); //opens serial port, sets data rate to 9600 bps Serial.println("hi there"); }
I used pinmode to determine the input and output pins from the board and according to my schematic board that I have done in Electronics Design Week
and Serial begin is a funtion that sits the data rate in bits per second (baud) for serial data transmission
where serial. printIn funtion is a funtion that prints data and as I have wrote it on the void setup it will print data just once
void loop() { lightSens = analogRead(PA2); if ( lightSens >= 300 ){ Serial.println(lightSens); digitalWrite(ledPin, LOW); } else { digitalWrite(ledPin, HIGH); //digitalWrite(ledPin, LOW); } }
for the voild loop first I have defined the array of lightSense as its the data that comes from PA2 which is the phototransistor
I added the if command which says if data that comes from the phototransistor is more or equal than 300 as the data is increased whith darkness and decrease whith the lightness, the LED pin should be off and else which means when the data from the phototransistor is less than 300, the LED should be on
Code Input Results¶
Embedded Programming from ZAINABARAHMAN on Vimeo.
Problem Faced:¶
I had a problem with finding the proper FTDI Driver as everytime I download one, it does not show in my PC and maybe because my PC is Windows 10. However, I overcome with the problem as I found the proper one and you can download it here
Ultrasonic Sensor¶
for the ultra-sonic Sensor I used my arduino board that I made in week 12 : the output week
here the Ultrasonic Ranging Module HC - SR04
code used: