Combining Two Arduino Sketches

Hello, I am new to Arduino/Coding - I want to combine Two sketches - a Gyroscope(MPU6050), a Humidity/Temperature Sensor(DHT11), and want the data to be saved on a, "5V ready Micro-SD Breakout board+(Adafruit)".

Below, I have the sketches for the DHT11 and the MPU6050. They do work on their own, but I have trouble combining the two codes - which I have also attached a file of named, "SketchCombineAttempt".

When I upload and view the serial monitor - the MPU6050 Gyroscope makes a successful connection and but will display a FIFO overload, after displaying a few x,y,z, points.
And during this time, the humidity/temperature is also displayed, but with an error, giving negative readings/numbers.

The code gets verified and uploaded with no problem and the Arduino board seems to have a successful connection with the two sensors - but can't really figure it out from just looking at the codes.

I am planning on placing the finished product onto a rocket, and get gyroscope/humidity/temperature readings, that will be saved onto a Micro-SD card.
So, how would I edit the code to allow the Borad+Sensors to gather information, store it onto an SD card, by powering it with a 9v battery?

  • Thank you

DHT11.txt (2.2 KB)

MPU6050.txt (16.1 KB)

SketchCombineAttempt.txt (9.96 KB)

You need to understand what pins each of your devices uses. The SD device almost certainly uses SPI as the means of communicating with the Arduino, which means that you can not use the SPI pins (10, 11, 12, and 13 on the Uno and other 328-based Arduinos) for anything else.

You must also set pin 10 to an OUTPUT pin, to make the Arduino the SPI master.

You need to use the F() macro much more often than you are.

So, how would I edit the code to allow the Borad+Sensors to gather information, store it onto an SD card, by powering it with a 9v battery?

You can forget about powering the devices with a useless 9V battery. The SD card alone will tax a 9V battery. Switching to a 3.3V Arduino and SD shield would allow you to use 2 AA batteries, which won't weigh that much more, but will provide a lot more current.

Thanks PaulS - I'll try it out! ^^