Project working on Mega but not Uno

Hi all,

So i’ve got a project thats working on a Mega but not an Uno. Its a heartbeat sensor that countsdown then displays the number on an Adafruit 7 segment display with backpack. i’ve got the sensor going into A0 then the SDA and SCL coming out of the dedicated lines on the Uno. Whereas on the Mega i had pins 20 and 21 doing the SDA and SCL, the sensor was also in A0. Code is attached, is there something i’m doing wrong with the step down to the Uno?

/*

Heartrate Monitor Countdown Clock Timer 

*/

#include <Wire.h> 
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"
Adafruit_7segment matrix = Adafruit_7segment(); 


//  Variables
int PulseSensor = A0;        
int beatCounter = 5025;         //Start number of count 
int LED13 = 13;                //On-board LED
int Signal;                   // holds the incoming raw data. Signal value can range from 0-1024
int Threshold = 600;         // Determine which Signal to "count as a beat"


void setup() {
matrix.print(10000, DEC); //used to dispay ---- on LED
matrix.writeDisplay();
delay(2000);
  
  pinMode(LED13,OUTPUT);         // pin that will blink to your heartbeat
   Serial.begin(9600);         // Set's up Serial Communication at certain speed.
 matrix.begin(0x70);
 
}


void loop() {


  Signal = analogRead(PulseSensor);  // Read the PulseSensor's value. Then assign value to "Signal" variable
                                             
  if(Signal > Threshold) {
   beatCounter--; //beatcounter counts down 
     Serial.print("Number Of Heartbeats: ");
      Serial.println(beatCounter);
      matrix.print(beatCounter); //LED Segment print
      matrix.writeDisplay();    //LED Segment Display
     delay(200);
  }

 if(Signal > Threshold){                          // If the signal is above "600", then "turn-on" Arduino's on-Board LED.
     digitalWrite(LED13,HIGH);
   } else {
     digitalWrite(LED13,LOW);                //  Else, the signal must be below "600", so "turn-off" this LED.
   }
    
delay(100);


 

}

Try to put the Serial.begin & matrix.begin at the top of your setup method like this

void setup() {

Serial.begin(9600);         // Set's up Serial Communication at certain speed.
matrix.begin(0x70);

matrix.print(10000, DEC); //used to dispay ---- on LED
matrix.writeDisplay();
delay(2000);
 
 pinMode(LED13,OUTPUT);         // pin that will blink to your heartbeat
 

}

maybe it will fix your problem.

No luck there unfortunately

Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read. If you're using the Arduino Web Editor you will not have access to this useful tool but it's still unacceptable to post poorly formatted code. I recommend you to use the standard IDE instead.

Please explain exactly what you mean by "i've got a project thats working on a Mega but not an Uno".

Ah my bad, i'd never seen that before. It certainly looks a lot nicer now.

So on the Mega it does everything i'd expect but on the Uno i can't even get readings from the sensor in the serial monitor and the display ins't lighting up.

Break the problem into parts.

Write a simple sketch that only prints the sensor readings to Serial Monitor. Run it with only the sensor connected to the Uno, no display.

Write a simple sketch that only prints a number to the display. Run it with only the display connected to the Uno, no sensor.

Those minimal circuits and programs will provide a sanity check. You should only proceed to the more complex program once they are working perfectly.

I'll try but surely the problem is more of a wiring issue or set up issue rather than a coding one as it works on a Mega? Surely it would step down to an Uno just fine?

...which is why I said to simplify the circuit as well as the code by only connecting one component at a time.