Transferring Uno code to Nano

Hi, I’ve been pondering about this and was wondering about how to transfer the code from my Uno to my nano.

// const int irreadings = 40;
int total; 
int readings; 
int irnow;
int average;
int iRead; 
//float Cm;
int newaverage;
void setup() {
  pinMode(2, OUTPUT);
  pinMode(A1, INPUT);
     int iRead = (analogRead(A1));


void loop() 

    irnow= 0;
    while ( irnow < 9)
      readings = analogRead(A1);
   //   Serial.println(readings);
      total = total + readings;
     // Serial.println("total");
     // Serial.println(total);
      irnow = irnow +1;
     // Serial.println("irnow");
     // Serial.println(irnow);     
  average = total / 11 ;

  newaverage = map(average, 0, 1023, 150, 0);

       if (newaverage < 135)
           digitalWrite(2, HIGH);
           digitalWrite(2, LOW);
  average = 0; 
  total = 0;
  newaverage = 0;

Help much appreciated,

By uploading it to the other board from the IDE would be the easiest. I don't think they have an interface to transfer code between them.

The problem is that I'm using inferred and it won't work for some reason, the values somehow won't change. I tried testing the voltage and there seems to be very little.

So… you’re not trying to get your program code from one to the other but something else? Then please start explaining what you’re actually trying to do, in detail, plus exactly what you want to do and what actually happens.

Your original post and reply #2 both confuse me. Please help me understand what you are trying to do.

In your original post you say you want to transfer code from your Uno to your Nano. Since there is no effective way to get the code FROM the Uno, I a going to assume that you mean that you have a sketch that you uploaded to your Uno, and now you want to know if you can upload it to your Nano.

The short answer is Yes, you can upload your sketch to your Nano. It may or may not have issues dealing with the differences between the 2 boards but you can certainly try.

In reply #2, I just cannot figure out what you are trying to say. Your use of the word 'inferred' does not fit my understanding. You say it won't work but I am not sure what 'it' is. You said you tried testing voltage. Which voltage? You say it seems to be very little. Compared to what?

Please explain the infra-red part some more. How do you have stuff connected? The code you have written will compiles just fine for either board - it's the same '328P processor either way, just a different physical package.

@wvmarvie look at my following comments

@vinceherman Yes, I have the code on my pc, and I'm wondering if it can work for nano. The inferred is a sensor that produces inferred radiation and (in my case) also receives as well. My program works perfectly on the Uno.But when I transfer it to the Nano ( by using male to female, putting the nano on a mini breadboard, then connecting the male end to the breadboard and connecting it to the male to male jumper wires from my original Uno breadboard and plugging it into the female wires) the sensor analog values doesn't seem to change when I put my hand in front and away from it. I tested the Uno's voltage to the Inferredsensorand got 4.58 when I used the nano, it showed 0 and -0 (who knows?) @crossroads It is connected through the jumper wires

Hope that explains something, squidsirymchenry

I think you mean infrared instead of "inferred"? Otherwise I have no idea what "inferred" could possibly be.

Furthermore I have still no idea what you're actually trying to accomplish.

I don't know whath this "male to female" business is … hang on. Dude, are you attempting to transfer a program from the UNO to a nano by connecting a USB cable between the two and wishing real hard? Is that what's going on here?

" I tested the Uno’s voltage to the Inferred sensor and got 4.58 when I used the nano, it showed 0 and -0 (who knows?) "

That sounds like you don’t have the Infra-Red (not “inferred”) components connected properly.
Uno and Nano use the same processor chip in different physical packages, the same code will run on both once uploaded from your PC.
Make sure you connect the Ground from the sensor to the Nano ground as well, a lot of folks leave that out.

Sorry to get to you late, I had lots of schoolwork I just realized the average was funny I have corrected it. I'm trying to make the values smaller so I can compare it to its 150 cm scale, otherwise, it's only if a computer is connected to it. Also, I can switch the values so the number is bigger when the number is farther away. I think the map function does that. I have a problem transferring it to the nano. My dad and I tested it and when we put the voltage meter on it we see only 0.00 as the voltage. I tried it on two of my nano boards all show the same. I used the voltage again on the Uno, same setting and I got 4.89 or 4.79 or whatever. That's the weird part. My dad bought some more infrared sensors ( got the infrared right this time).I will check my hardware and will get back to you.

@ Paul no that's not what is happening

Hah, figured it out, I didn’t soldier…

My guess is even the wildest imagination won't come close to what is actually connected to what.

Paralleling boards perhaps? :o Even what is "inferred" is not clear. :confused:

Squidsirymchenry: Hah, figured it out, I didn't soldier...

Just inserted the pin strip into the Nano without soldering the pins to the holes on the Nano? It can work but as you've found it usually doesn't.