Sunday, February 24, 2013

ProtoCylon: It's ALIVE

ProtoCylon: It’s ALIVE

 

By Bobby Neal Winters
I wasn’t exactly in a laboratory over a cadaver coaxing the lightning to come it; I didn’t exactly have a hunchback named Igor by my side; but I do have some idea of the elation Dr. Frankenstein may have felt in those first few moments.
It he hadn’t been a fictional character, that is.
Along the way in this adventure, I continually referred to the simple-sounding model that organizes my thought so well: Input, Processing, and Output.  The processing consists of writing computer programs and that scares a lot of people, but throughout my adventure--for that is what is has been, an adventure--the Input and Output have been the most difficult. And of those two, Input has been by far the harder.
In Muscles on the Beast, I had put my robot body together and it would roll, but only with a preprogrammed script.  It had null input; it simply had processing and output.  At that time, I was debating whether to have it process input from ultrasonic sensors or to make it into a line following robot.
I decided to do the easiest; big surprise there.  I made into a bat.  It receives input from ultrasonic sensors.  The heuristic for this robot is for it to go straight ahead until it runs into a wall and then to turn until it gets free.  It tries turning one direction three times and if it is still caught it will try the other.  It will continue in this way until it is either free or its batteries run out.
#include
#define FULL_SPEED 256
#define TRAPPED_DIST 10

// motor pins
int speed1=3;
int speed2=11;
int direction1=12;
int direction2=13;

//distance Sensor pins
const int pingPin =4;
int inPin=2;

//variables concerning distance
int myDist;
boolean trapped;

void setup(){
setMotorPins();
setSensorPins();
}

void loop(){

 //How far is the next obstacle?
 myDist=getDistance();
 //If it is too close, I am trapped
 trapped=(myDist
 switch(trapped){
    case true:
     //If I am trapped, begin the struggle
     getFree();
    case false:
     //If I am not trapped, then quarter speed ahead
     goStraight(0.25,0.5);
     break;
 }

}

void setMotorPins(){

 pinMode(speed1,OUTPUT);
 pinMode(speed2,OUTPUT);  
 pinMode(direction1,OUTPUT);  
 pinMode(direction2,OUTPUT);
 return;
}

void setSensorPins(){
  pinMode(pingPin,OUTPUT);
  return;
}

long getDistance(){
 long duration, cm;

 digitalWrite(pingPin,LOW);
 delayMicroseconds(2);
 digitalWrite(pingPin,HIGH);
 delayMicroseconds(5);
 digitalWrite(pingPin,LOW);  
 pinMode(inPin, INPUT);
 //How long does it take for my pings to get back.
 duration=pulseIn(inPin,HIGH);
 //How far is the next obstacle?
 cm=microsecondsToCentimeters(duration);
 return cm;
}  

void goStraight(float prop, float seconds){
 //prop is the proportion of full speed
 int rate=prop*FULL_SPEED;
 //Convert to microseconds
 int duration=1000*seconds;
 //Use both wheels  
 digitalWrite(direction1,HIGH);
 digitalWrite(direction2,HIGH);
 analogWrite(speed1,rate);  
 analogWrite(speed2,rate);  
 //Run awhile before we do anything else.
 delay(duration);
 return;
}

void goTurn(int dir, float seconds){
 //We will only turn at half speed
 float prop=0.5;
 int rate=prop*FULL_SPEED;
 //How long will we turn?
 int duration=1000*seconds;
 //Switch between the various directions.
 switch(dir){
    case 1:
     digitalWrite(direction1,HIGH);
     digitalWrite(direction2,LOW);
     analogWrite(speed1,rate);  
     analogWrite(speed2,0);     
    break;
    case 2:
     digitalWrite(direction1,LOW);
     digitalWrite(direction2,HIGH);
     analogWrite(speed1,0);  
     analogWrite(speed2,rate);
    break;
    default:
    return;
 }  
 delay(duration);  
 return;
}

void stopMotor(int seconds){
 analogWrite(speed1,0);
 analogWrite(speed2,0);  
 delay(1000*seconds);
 return;
}

long microsecondsToCentimeters(long microseconds)
{
return microseconds / 29 / 2;
}

void getFree(){
 //First try one direction
 int sense=0;
 int count=0;
 //Struggle until no longer trapped.
 while(trapped){
    ++count;
    goTurn(sense+1,1);
    if(count>3){
      count=0;
      //Struggle in one direction three times and then try the other.
      ++sense;
      sense=sense % 2;
    }
    myDist=getDistance();
    trapped=(myDist < TRAPPED_DIST);
 }
 return;
  
}

The Headless Pi-Man

The Headless Pi-Man

By Bobby Neal Winters
As those of you who have sampled this blog recently will be aware, lately I’ve been into building a robot.  I am progressing in that and will report on that shortly.  My account wouldn’t be complete if I didn’t share what got started on that was the Raspberry Pi.  I originally saw--was shown--Raspberry Pi on Facebook over Christmas Break.
I googled it.  Raspberry Pi was backordered, but the Arduino processor showed up on the search.  The rest is history, as they say.  
But I’m nothing if not stub..tenacious. I got my Raspberry Pi and have been trying to work it in amongst the Arduino/Robotics.  I may eventually try to marry them, but we have to see whether they get along first.
The Raspberry Pi is a computer based on an ARM chip...blah, blah, blah.  I’ve seen it described as the motherboard from a smartphone with some nice connectors glued to it.  They sell two varieties.  You want Model B and you can get it for $35 here.  You will also want to get the SD card with the operating system on it; that will cost you $13.
And you will need a TV at first.  It will have to have either an HDMI connector or a RCA jack connector.  These are the two ways that the Raspberry Pi connects directly with monitors.  The Pi was designed to appeal the the hacker mentality.  Since Christmas break, I’ve learned a lot about this psychology.  
There are folks who will spend hundreds of hours to find a way to do something outside of the constraints of the system.  (Be kind to them because you will want them to be your friends come the Zombie Apocalypse.) For these folks--and to make it as cheap as possible--the Pi has been designed so that you can make it work with things you might have laying around: keyboard, mouse, TV, ethernet hub, cell phone charger, etc.
I must confess that this peculiarity of working with anything BUT a computer monitor has cost me the most.  All of the TVs in my home are being watched by someone.  After a couple of misadventures with monitors designed for use with backup cameras and CCTV such as this. I got a cheap little TV for $100.  The bright side of this is that it can be used later for something else.  My youngest daughter is already lobbying for it.
This is all going to be filed under “I” for Irony in the Twilight Zone, however, because I believe I am going to be running my Pi headless.
That’s right, headless.
As it is a Linux box, you can use secure shell (SSH) to connect to it remotely.  As it is such a small little fellow, running a GUI on it makes it run slowly.  The light little browser that comes on it doesn’t do the things I like.
But it is a Linux box so I can put it on my network and set it up as a server.  The only thing I needed the monitor for was to get its IP address so I could connect to it remotely.
However, in the course of this, I have resurrected my Ubuntu box so I may put together a Linux network: A little computer farm in my own office.
There will be more entries as madness descends.

Thursday, February 21, 2013

Snow Day: Downton Abbey, Engineers, and a Chest Cold

Snow Day: Downton Abbey, Engineers, and a Chest Cold

By Bobby Neal Winters
You may recall the Multimedia PC I built one piece at a time.  I made a big deal about it.  I didn’t make such a big deal out of the fact that it suddenly stopped working.  (I now believe the power supply went out, but the truth of that remains to be seen.)  It turns out that building a video recorder isn’t such a big need when you’ve got Netflix.
In any case, it went out and I wasn’t in any hurry to get it fixed until a friend who’d loaned me the second season of Downton Abbey on DVD--before we discovered it was on Netflix--wanted his discs back.  It was then I remembered they were stuck in the Multimedia PC which couldn’t be opened because it was broken and which couldn’t be fixed because I didn’t have the time.  The solution at that point was to buy my friend a replacement set of DVDs and to wait until I had time to fix my Multimedia PC.
Summer came and went.  The wind whipped in flipping the days on my calendar.  Children dressed first in Halloween costumes and then as pilgrims came by.  A large man in a red suit struggled down a chimney and a naked baby in a top hat crawled by.
Then we got a snow day and I finally had time to mess with the computer.
It actually took less than half an hour to get the DVD out. All I had to do was take the DVD-Drive out of one and put it into another.  I pressed a button and out it popped.  I walked around the house with the DVD on my finger saying “Donna Noble has been saved.”  (It’s an obscure Dr. Who reference, okay, and not particularly germane to the event, but its obscurity covers that.)
Anyway, on the heels of that victory, I thought I would try to fix the Multimedia PC.  If I get it started, I think I might put Debian Linux on it so it can talk to my little Raspberry Pis.  The symptom that the PC exhibits is that you press the button and it won’t come on.  To me that suggests the power supply.  The reason I think this isn’t so much because I know a lot but because that would be the easiest and cheapest thing to fix.
In order to test this hypothesis, I thought I ought to plug it in. (Hey, I got a PhD, folks. The brilliance just flows.) I needed a power cord for that. (That PhD just keeps giving and giving.) I’d used the Multimedia PCs cord on another computer, so I borrowed one from my coffee pot.
Yes, you read that correctly. A computer uses the same power cord as a coffee pot. This is because good engineers, like Scotty said, are always just a wee bit conservative.  Wee bit, hell, once they have something that works they never change it.
I am old enough to remember the first printers for PCs.  You needed a screw-driver to hook them to the back of your computer.  It never occurred to the engineers who designed them that there would be offices without screwdrivers.  
Seriously.
Eventually we got the aptly named thumbscrews and those were around for years until they were replaced by USB printers.  This is because, like the coffee pot power cord, they worked.
I am sitting now at my Itty-bitty Ubuntu box tapping out this article after having fought with a chest cold for several days.  I am exhausted but my mind is somehow clear.  I am being battered by images around me.  USB printers, USB hard drives, USB thumb drives, my Arduino connected to the USB port, and a USB chargeable flashlight.  
The future is becoming clear to me.  I see it all.
One day I will awake to perk my coffee to a USB coffee pot.

Sunday, February 10, 2013

The Proto Cylon: Muscles on the Beast

The ProtoCylon: Muscles on the Beast

By Bobby Neal Winters
As I mentioned earlier, I am using Beginning Arduino by Michael McRoberts. It hasn’t failed me yet.  I’d also mentioned that my ProtoCylon’s robot body will be a car which will be run by a couple of motors.  In order to control the motors, transistors are required.  I wrote about using them in ProtoCylon: Control. There I used a temperature sensor to control the motor of an electric fan. Pretty cool. (Pun fully intended.)
I’d had visions of having to solder a couple of transistors to a pc board in order to control the motors on my robot.  That was before I learned about the Arduino Motor Shield.  The Arduino Motor Shield takes care of the transistors for you.  It also takes care of connectors for the power in and power out.
While an earlier version of myself would’ve insisted upon doing this the hard way, at 50 I am quite happy to use the scaffolding.  My skills soldering are steadily improving--not like they could get worse--and I am gaining confidence.  But I do like to be able to measure progress in visible ways, and today I did.  The robot moved.  See below:What you see there are motions that were pre-programmed.  I didn’t even write the code myself, though I did key it in.  While this is very fulfilling, I am not nearly done.  In order for this to really be a robot, it will have to be able to take input from the outside.  Remember the model: Input; Process; Output.  
I’ve got to decide on the mode of input.  There are two ways I am currently considering.  The first of these is to use my UltraSonic Sensors.  See ProtoCylon Senses.  These I could use to keep it from running into walls kind of like a bat.  The second model is that of the line following robot.  This would require light sensors.  It would have eyes.  I need to think on this a while.

Monday, February 04, 2013

An Interlude: Confronting Demons and Skeletons

An Interlude: Confronting Demons and Skeletons

By Bobby Winters
I may have shared with you before the brain block I have with regard to soldering.  When I was a kid, I’d gotten a computer kit that required soldering.  I made a mess of it and it wouldn’t work. It cost a lot of money, and we didn’t have all that much.  So, in my shame, I put it aside.
Since I’ve begun playing with microcontrollers, it’s become clear to me that beyond a certain point I will need to know how to solder.  Breadboards are nice, but anything that’s not going to be taken apart eventually will need to be soldered together.  I’ve taken to a program of learning the manly skill of soldering.  I’ve confronted the soldering demon.
I will never be an artist.  Heck, I may never actually solder anything that works.  But I am beyond the “Oh my gosh, what a mess” stage.  It boils down to those three words people have been telling me all my life: “Take your time!” Yes, that’s it.  That’s the secret.  One must decide that soldering is a thing that one must do and then set out the preparations to do it.  
The first thing is to prepare a place.  You’ve got to have a place to do your work.  The second is to have all of your materials around you.  You need your soldering iron, its stand, a little wet sponge to clean your tip on, and--this helped me a lot--a desoldering iron complete with attached desoldering bulb.  I always do a better job writing when I have an eraser, so it figures I do a better job soldering when I have a desoldering iron.
All of that having been said, I’ve not been able to solder a heat sensor to the pc board yet.  I think that I’m frying them.  I hook them to my thermometer program and they read -196.6. I tried three times and got this result three times with three different ruined sensors--and I’ve tried using a alligator clip as a heat sink.  In the world of digital thermal sensors, I am now known as He-who-brings-hot-death.  I am now looking for conductive glue on Amazon.
On other news, I’ve gotten a skeleton for my ProtoCylon.  There’s a picture below.  My experience in opening the box and thinking about putting it together made me think of building the pyramids.  I knew it could be done, but thousands might die in the process. There were parts--nuts, bolts, wheels, motors, plates--but no directions.  I have got something screwed--such a versatile word--together, but it was interesting.  I suppose they thought it would be more interesting without the directions.




Friday, February 01, 2013

Reconciliation

Reconciliation

By Bobby Neal Winters

The more I know, the less I understand
And all the things I thought I figured out, I have to learn again
I've been tryin' to get down to the Heart of the Matter
But my will gets weak
And my heart is so shattered
But I think it's about forgiveness
--Don Henley, Mike Campbell, and J.D. Souther

My father loved women.  And he was the sort of man who believed that there wasn’t a woman so beautiful that she couldn’t be made more beautiful with a two-year-old child tagging along behind her. As a truck driver, he viewed the world through his windshield and often created opinions of people from what he saw.  I remember of him speaking of a young woman who lived on the 19-mile stretch of road between Ada and Asher (Oklahoma).  He’d only knew her from from these glimpses along the road, but he admired her because she was so frequently outside and was working every time he saw her.
That is something I do too.  I create my own people by my glimpses of what I see.  There might be very little to go on.  I might only see them in public occasions when they are putting out what they want to be seen.  And it has been my habit to create an idealized version of them.  This means I admire a lot of people--and that makes me happy--but it also means that I am frequently disappointed.  One nasty side-effect of this is I am becoming more cynical as I grow older.
Those who watch this space may recall that a while back wrote that my father had committed suicide because of having cancer and that, after all these years, I was finding it difficult to really forgive him for it.  It was one of those things that in my youth I had forgiven, but as I grew closer to the age he’d been when I’d known him, I found forgiveness to be more difficult.
I got letters about that which doesn’t happen often.  They were very thoughtful, and though I have answered them all personally, I want to acknowledge them here. Thank you.
The Lord’s Prayer--the Our Father--asks that we be forgiven as we forgive others, so I’d better forgive.  But it is a process.
When the Presbyterians say the Lord’s Prayer, they say forgive us our debts.  We owe something.  It makes it almost a financial transaction.  That brings up another financial term: reconciliation. When you look up reconciliation in the dictionary, it brings of the image of two parties, each  bringing out accounts of their mutual transactions to see whether they line up.
When I’ve reconciled my bank account--my records versus the bank’s--there have been times when the two accounts didn’t line up exactly.  Mathematics dictates that I am wrong or the bank is wrong or that both of us are wrong.  There is a certain amount of good faith searching that must take place on the part of each of us.  How much depends upon the size of the difference. After that good faith effort, there comes a time when the difference must be acknowledge and each party must proceed.
Most of the time this ends with me admitting that I must have made a mistake.  But the search is not wasted because sometimes banks do make mistakes and because I gain greater insight to the sorts of mistakes I make.  If I follow the procedures that Mr. Scott taught me in high school bookkeeping, then there is a trail of what I’ve done that I can look back on.
This is what I’ve been doing in reconciling with my father.  There comes a point where the accounts don’t match up and if the relationship is to continue somebody has to let the difference go.  
And Dad’s been gone for nearly three decades, but there is still a relationship.  He’s not around to state his case, so I’ve just got to let the difference go.
But in the process, I’ve recalled all the good about him. I’ve discovered the things about him--good and bad--that live on in me. And I’ve let go of my anger.
(Bobby Winters, a native of Harden City, Oklahoma, is Assistant Dean of the College of Arts and Sciences and Professor of Mathematics at Pittsburg State University. He blogs at redneckmath.blogspot.com and okieinexile.blogspot.com. You may contact him at okieinexile@gmail.com. )

Sunday, January 27, 2013

ProtoCylon: Control

ProtoCylon: Control

By Bobby Neal Winters

Again and again I am reminded of the importance of the basic model:  Input information, Process that information, and Output (or Act on!) the processed information.  This simple model helps us to keep the processes separate and keeps us from confusing them.  Indeed, once we understand various, separate processes, we can mix and match ways of inputting with ways of outputting.
This brings us to today’s project: Temperature control.  One way I justify this new hobby of mine to the Other Half is that one day I can use it to control the fan for the greenhouse next door.  The fan has to be turned on when it gets too hot.  
During the summer, there are some days we simply have to anticipate that it will be hot before it actually gets hot and think to turn on the fan before we go to work.  If there were a temperature control for the fan, we would neither have to remember to turn it on in the morning or turn it off in the evening.  
Today’s project will turn a fan on and off at a certain threshold temperature.  It won’t control a fan as big as the one in the greenhouse, but I am into the “baby step” thing.
For the input part, I refer my reader to my last blog entry on Telling the Temperature.  In that, I construct a temperature sensor that connects to the Arduino with one wire.  The sensor itself is a surprisingly tiny component.  You can get ten of them for fifteen dollars.  This is input at its best.  You don’t have to type in anything; you don’t have to turn a dial; you just connect it and let the software do the rest.
The control in this case is easy as well once you have the transistor wired in.  To control the fan, I refer the reader to Beginning Arduino by Michael MacRoberts in the section where he shows how to use a TIP120 transistor to control a motor.  
Transistors are kind of scary to me.  I still don’t understand them very well.  This I know: They have three prongs.  One of the prongs goes to power, one goes to ground, and the third (actually the middle one) connects to the Arduino where it gets instructions for controlling the flow of current.
All of the complication of this project took place on the breadboard.  Wiring the temperature sensor and the transistor are still non-intuitive to me.
The code is simple:

// include the library code:
#include
#include

//Temperature Sensor pin
#define ONE_WIRE_BUS 3

//Pin that controls the transistor

int transistorPin=A1;

// initialize the library with the numbers of the interface pins
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress insideThermometer, outsideThermometer;
//place to put the temperature
float tempC=20;

void setup() {
 //Set up transistor
 pinMode(transistorPin, OUTPUT);
 // Get the temperature sensors running.
 sensors.begin();
/*The 0 in the second argument is because this is the first transistor.  Computers start counting at 0.*/
 sensors.getAddress(insideThermometer,0);
}

void loop() {
 //Get the Temperatures
 sensors.requestTemperatures();
 tempC=sensors.getTempC(insideThermometer);
 //Is it hot enough for the fan?
 if(tempC>25){
     //Turn the fan on
     analogWrite(transistorPin,255);
 }
 else{
     //Turn the fan off
     analogWrite(transistorPin,0);
 }
 //No reason to be impatient
 delay(1000);
}

Monday, January 21, 2013

ProtoCylon: Telling the Temperature


ProtoCylon: Telling the Temperature

By Bobby Neal Winters
I remember reading old documents, ages ago, about the computing model that was in three parts: Input, Process, and Output.  I thought it was kind of goofy at the time, but I was younger and smarter then.  Now that I am old and stupid I’ve gained an appreciation of how separating a project into smaller parts--even into three parts--can make doing the project a reality. (When I was younger and smarter, I never actually did anything.)
Thus is the tale of teaching my ProtoCylon to tell the temperature.  It comes in three parts and there is a part where I grow just a little bit.
The Input part I referred to in my post ProtoCylon Senses. This involved the DS18B20 digital temperature sensor.  This is a tiny thing.  It has three pins like a transistor.  Heck, for all I know, it might be a transistor.  The power goes in one side, out the other, and the center pin is connected to the Arduino board.  You can check the wiring at this tutorial.
For the Output, I used an LCD display.  This required growth for me.  I will work with the most obvious part first. This display has 16 pins.  That is a lot of pins. This is eased a bit by the fact that four of them are used for power and one is just grounded out.  This leaves eleven, though, and that is nothing to sneeze at.  This wasn’t the major growth inducer, however.  No, the big this is that I had to solder--yes, solder--those 16 pins to a set of pins that would allow me to plug it into the breadboard before I could even start to hook up the rest. (I will leave out the part where I attempted to hook it up without soldering. Not a happy time.)
After I got it soldered, I hooked it up and it didn’t work.  This is becoming a theme with me, but I am learning from this and recovering quicker each time.  The first stage is not to allow myself to be crushed by each failure.  I stop, take a deep breath, let it out, and try to figure out where I goofed.  
One useful technique is to take it apart and put it together again--slowly from scratch.  For wiring up the LCD display, I recommend the tutorial at Adafruit Learning System.
In between the Input and the Output is the Process.  The process in this case involved the use of libraries.  Libraries are specialized functions that make using hardware easier.  While there is a young turk deep inside me that would like to write my own libraries, there is an old goat who would like to actually get something done without taking it apart electron by electron.  Therefore, I happily use the libraries.
In creating this project, I actually used my creativity to merge two programs.  One of these was a “Hello, world!” program for the LCD that was an example that came with my Arduino compiler.  The other was in the book Beginning Arduino by Michael MacRoberts. I lay claim to the creativity crown because I did have to modify their code mutatis mutandis for the project to work.  The completed project follows:


This is the code:
/*
The uses temperature sensors to take the temperature
and outputs it to an LCD display.
I fused two programs by other people and modified them.

The first was:

The LCD Library originally added 18 Apr 2008
by David A. Mellis
library modified 5 Jul 2009
by Limor Fried (http://www.ladyada.net)
example added 9 Jul 2009
by Tom Igoe
modified 22 Nov 2010
by Tom Igoe

This example code is in the public domain.

http://www.arduino.cc/en/Tutorial/LiquidCrystal

The second was from Begining Arduino by Michael MacRoberts
*/

// include the library code:
#include
#include
#include

#define ONE_WIRE_BUS 3

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7,8,9,10,11,12);
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress insideThermometer, outsideThermometer;

void setup() {
 // set up the LCD's number of columns and rows:
 lcd.begin(16, 2);
 lcd.clear();
 // Get the temperature sensors running.
 sensors.begin();
 sensors.getAddress(insideThermometer,0);
 sensors.getAddress(outsideThermometer,1);

}

void loop() {
 //Get the Temperatures
 sensors.requestTemperatures();
 //Print it on the first row, i.e. row 0
 lcd.setCursor(0,0);
 printTemperature(insideThermometer);
 //Print it on the second row, i.e. row 1
 lcd.setCursor(0, 1);
 printTemperature(outsideThermometer);
 //enjoy the weather for one second
 delay(1000);
}


void printTemperature(DeviceAddress deviceAddress){
 //Get the temperature
 float tempC=sensors.getTempC(deviceAddress);
 //print it out.
 lcd.print("TempF:  ");
 lcd.print(DallasTemperature::toFahrenheit(tempC));
}

Sunday, January 20, 2013

ProtoCylon Senses

ProtoCylon Senses

By Bobby Winters

I’ve spent the last week on a voyage of discovery in which I’ve discovered myself the same as I’ve always been.
Let me explain.  
Last weekend I tried to get a UltraSonic distance sensor hooked up to my Arduino Uno.  The procedure is easy to find on the Internet.  I wired it, and it didn’t work.  I required it, and...it didn’t work.  In my reading of the reviews in the process of buying this sensor, one of the reviewers had complained the one he bought was trash. I figured I’d had a bit of bad luck, so I bought another one.  Yesterday, I wired it up again.
It worked great.
Then my curiosity got the better of me, so I plugged in the other one to the same wiring.  It worked too.  It had been miswired the first time.  
Now, I am fully capable of screwing up that badly.  I admit that freely.  In my fiddling around, I discovered that one of the jumper wires I had been using was bad.  This is a possibility that hadn’t occurred to me before.  In math your results don’t just go belly-up because your pencil has a crack in its lead.
This is a practice where the real world will check your work for you.
Another project I’d been working on from Beginning Arduino was to connect temperature sensors.  The sensors I’d purchased for this were DS18B20 sensors. You get 10 for that price.  I worked through the book, and, having learned my lesson, I wired the boards painstakingly. I hooked it up and discovered it was 285 degrees centigrade in my house. (For you non-metric types, water boils at 100 degrees centigrade.)  I discovered my error when I looked further in the book and discovered the DS18B20 are a different type of sensor and must be wired in a different way and require a different library of functions to operate.  I hooked them up, and got the temperature down to 85 degrees centigrade.  I changed a resistor in my wiring and it came down to 74 Fahrenheit.
Like I said, the real world checks your work for you.