Described your design and fabrication process using words/images/screenshots.
Explained the programming process/es you used and how the microcontroller datasheet helped you.
Explained problems and how you fixed them.
Included original design files and code.
This week, I wanted to continue with the output assignment. The global goal was to connect week's 10 board to a hall sensor to measure the speed and distnce of a bike. The hall effect sensor is something I will be using for my final project for calculating angular speed, so I think everything I have leart during this week will be useful. The scheme was like this:
During Output week, I managed to make the LCD work using Neil's code and also found a code for counting laps and measuring speed and distance with arduino. I just needed to make everything work out together. It seemed easier that it ended up being. First thing I did, was looking at Neil's magnetic field board to check out I was not missing any important part. As I wanted to use this board with my output board, the chip was already on the other board, and so were the capacitor and the resistance. This ended up with a very tiny board. It was only the pads for soldering the Hall efect sensor and the 3 pin connector.
After a little while I realised I needed a pull-down resistor for the hall effect sensor, so I redid the eagle and milled it again.
I used an A1302KLHLT-T hall effect sensor. It is an obsolete part and it has been substituted by the A1308. This info is explained at the beginning of the datasheet where I learnt about the operation voltage, necesary to know if it will work with the battery I prettend to use. There is no problem as it works between 4.5-6 V, and I will be using 5V from a voltage regulator. I also checked the pin configuration of the sensor. I also checked the supply current as it will determine if the sensor works. In this case it works with 11 mA. There is a lot more info in the datasheet, but that is the one I checked for my assignment.
I strugle a little bit with the code, as ATtiny don't have arduino serial communication I couldn't go through the code. I decided to connect my hall sensor and the LCD to an arduino board, I went through the whole code and managed to make it work.
Afterwards I checked the pins equivalence between ATtiny 84 and arduino and changed them on the code. When I compiled, for some reason it din't work. My LCD was static reading V= 130.50 Km/s D=1.88 m , but the sensor wasn't reading anything. After a couple agonic moments I realised I had changed the pin number on "pinMode(7,INPUT);" line, but I had forgoten to do it on the " Actualstate1=digitalRead(4); delay(10); Actualstate2=digitalRead(4);" lines, so the sensor was not comunicating with the ATtiny.
Once this was fixed, my speedmeter worked fine, even though I still had the problem of the quality of the magnet and for getting a proper read I had to almost touch the sensor with the magnet. I will try with neodimiun magnets later on, which I thing will fix this problem. This issue was a problem when I built up the whole system (using the balance bike fork I made for week 7), as the magnet was not powerfull enough I didn't get the reading from the sensor with a few cm distance.
The code I have modified for calculating the speed and distance, for a ATtiny 84 PCB is:
//Julia Leirado's code modified from sebalabs.blogspot.com.es/2015/11/arduino-12-parte-3-velocimetro-de.html
#include
LiquidCrystal lcd(5,4,3,2,1,0);
int Actualstate1=0;
int Actualstate2=0;
int lastState=0;
int counter=0;
float radious_cm=30.0; //ingresar radio de la rueda en cm
float pi=3.1416;
float wheelPerimetre=2*pi*(radious_cm/100); //Calcula Perimetro en metros
float distance=0;
float distKM=0;
int timer1=0;
int timer2=0;
int timer3=0;
float timer4=0;
float sp=0;
void setup(){
//pinMode(4,OUTPUT);
pinMode(7,INPUT);
//Serial.begin(19200);
lcd.begin(16,2);
}
void loop(){
Actualstate1=digitalRead(4);
delay(10);
Actualstate2=digitalRead(4);
//Si los estados no son iguales, el sketch no hace nada.
if (Actualstate1 == Actualstate2) {
if (Actualstate1 != lastState){
if (Actualstate1 == HIGH) {
counter = counter + 1;
/* Serial.print ("Laps ");
Serial.println(counter);*/
dist();
velocity();
}
}
}
lastState= Actualstate1;
/* if (counter%2 == 0 ) {
digitalWrite(4, LOW);
}
else {
digitalWrite(4, HIGH);
}*/
LCD();
}
void dist(){
distance=wheelPerimetre*counter;
distKM=distance/1000;
/* if(distance<=999){
Serial.print("Distance m= ");
Serial.println(distance);
}
else{
Serial.print("Distance Km= ");
Serial.println(distKM);
}*/
}
void velocity(){
if(counter%2 == 0){
timer1=millis();
}else{
timer2=millis();
}
timer3=abs(timer1-timer2);
timer4=(((timer3/1000.0)/60.0)/60.0); //hours
sp=((wheelPerimetre/1000)/timer4);// km per hour
/*Serial.print("timer1 = ");
Serial.println(timer1);
Serial.print("timer2 = ");
Serial.println(timer2);
Serial.print("timer3 = ");
Serial.println(timer3);
Serial.print("timer4 = ");
Serial.println(timer4);*/
/* Serial.print("speed = ");
Serial.print(sp);
Serial.println("km/h");*/
}
void LCD(){
//lcd.print("hello");
lcd.clear();
lcd.print("V=");
lcd.print(sp);
lcd.print("Km/s");
lcd.setCursor(0,1);
if(distance<=999){
lcd.print("D=");
lcd.print(distance);
lcd.print("m");
}
else{
lcd.print("D=");
lcd.print(distKM);
lcd.print("Km");
}
return;
}