I need help with my Arduino UNO!

Hello! I was testing a code for a school project, in my Arduino MEGA, but I got a UNO and changed to it, now it won't work, what can it be?

"It won't work" is the lamest problem description.

It is very difficult to help with code that we cannot see. I, for one, do not feel like listing everything that you could have done wrong. Post the code. Read the forum guidelines to see how to properly post code. Tell us what the code actually does and how that differs from what you want.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

ok.

#include <CapacitiveSensor.h>
#define buzzer 13

//Sets output and input pins.
CapacitiveSensor   cs_12_2 = CapacitiveSensor(12, 2);
CapacitiveSensor   cs_12_3 = CapacitiveSensor(12, 3);
CapacitiveSensor   cs_12_4 = CapacitiveSensor(12, 4);
CapacitiveSensor   cs_12_5 = CapacitiveSensor(12, 5);
CapacitiveSensor   cs_12_6 = CapacitiveSensor(12, 6);
CapacitiveSensor   cs_12_7 = CapacitiveSensor(12, 7);
CapacitiveSensor   cs_12_8 = CapacitiveSensor(12, 8);

void setup() {


}

void loop() {

  long start = millis();

  // Set the sensitivity of the paper foil keys.
  long total1 =  cs_12_2.capacitiveSensor(30);
  long total2 =  cs_12_3.capacitiveSensor(30);
  long total3 =  cs_12_4.capacitiveSensor(30);
  long total4 =  cs_12_5.capacitiveSensor(30);
  long total5 =  cs_12_6.capacitiveSensor(30);
  long total6 =  cs_12_7.capacitiveSensor(30);
  long total7 =  cs_12_8.capacitiveSensor(30);

  //Sets the tones of the piano.
  if (total1 > 150) tone(buzzer, 523);
  if (total2 > 150) tone(buzzer, 587);
  if (total3 > 150) tone(buzzer, 659);
  if (total4 > 150) tone(buzzer, 698);
  if (total5 > 150) tone(buzzer, 784);
  if (total6 > 150) tone(buzzer, 880);
  if (total7 > 150) tone(buzzer, 988);

  if (total1 <= 150  &  total2 <= 150  &  total3 <= 150 & total4 <= 150  &  total5 <= 150  &  total6 <= 150 &  total7 <= 150)
    noTone(buzzer);

  delay(0);
}

It's a piano played with paper foil keys, and in the MEGA was working fine, but now that I passed to the UNO it isn't.

and here a recreation of the project itself

Note: The 8 pin connector is what should be the paper foil.

Print what you read from your capacitive sensors

there is none, it's just the paper foil, with the code on it

I think @J-M-L means to open the serial port and print out the values returned by the sensors, like this. I slowed down the loop so the serial monitor does not get flooded.

#include <CapacitiveSensor.h>
#define buzzer 13

//Sets output and input pins.
CapacitiveSensor   cs_12_2 = CapacitiveSensor(12, 2);
CapacitiveSensor   cs_12_3 = CapacitiveSensor(12, 3);
CapacitiveSensor   cs_12_4 = CapacitiveSensor(12, 4);
CapacitiveSensor   cs_12_5 = CapacitiveSensor(12, 5);
CapacitiveSensor   cs_12_6 = CapacitiveSensor(12, 6);
CapacitiveSensor   cs_12_7 = CapacitiveSensor(12, 7);
CapacitiveSensor   cs_12_8 = CapacitiveSensor(12, 8);

void setup()
{
   Serial.begin(9600);
}

void loop()
{
   static unsigned long timer = 0;
   unsigned long interval = 1000;
   if (millis() - timer >= interval)
   {
      timer = millis();
      long start = millis();

      // Set the sensitivity of the paper foil keys.
      long total1 =  cs_12_2.capacitiveSensor(30);
      long total2 =  cs_12_3.capacitiveSensor(30);
      long total3 =  cs_12_4.capacitiveSensor(30);
      long total4 =  cs_12_5.capacitiveSensor(30);
      long total5 =  cs_12_6.capacitiveSensor(30);
      long total6 =  cs_12_7.capacitiveSensor(30);
      long total7 =  cs_12_8.capacitiveSensor(30);

      Serial.println("readings from cap sensors");
      Serial.println(total1);
      Serial.println(total2);
      Serial.println(total3);
      Serial.println(total4);
      Serial.println(total5);
      Serial.println(total6);
      Serial.println(total7);
      Serial.println();

      //Sets the tones of the piano.
      if (total1 > 150) tone(buzzer, 523);
      if (total2 > 150) tone(buzzer, 587);
      if (total3 > 150) tone(buzzer, 659);
      if (total4 > 150) tone(buzzer, 698);
      if (total5 > 150) tone(buzzer, 784);
      if (total6 > 150) tone(buzzer, 880);
      if (total7 > 150) tone(buzzer, 988);

      if (total1 <= 150  &  total2 <= 150  &  total3 <= 150 & total4 <= 150  &  total5 <= 150  &  total6 <= 150 &  total7 <= 150)
         noTone(buzzer);

      delay(0);
   }
}

Exactly (@115200 bauds to go faster :wink: )

@lucash2008 post a picture of your setup

k, i'll do it

what do you mean?

here is what appeared:

readings from cap sensors
0
0
0
0
0
0
0

readings from cap sensors
1664
0
0
0
74
219
0

readings from cap sensors
0
0
0
0
0
0
0

readings from cap sensors
-2
-2
-2
-2
-2
-2
-2

readings from cap sensors
-2
-2
-2
-2
-2
-2
275878

readings from cap sensors
0
0
0
0
0
0
0

readings from cap sensors
-2
-2
-2
-2
-2
-2
202110

readings from cap sensors
0
0
0
0
0
0
0

readings from cap sensors
-2
-2
-2
-2
-2
-2
-2

readings from cap sensors
-2
-2
-2
-2
-2
-2
-2

readings from cap sensors
-2
-2
-2
-2
-2
-2
-2

readings from cap sensors
-2
-2
-2
-2
-2
-2
-2

readings from cap sensors
-2
-2
-2
-2
-2
-2
-2

readings from cap sensors
-2
-2
-2
-2
-2
-2
-2

readings from cap sensors
-2
-2
-2
-2
-2
-2
-2

readings from cap sensors
-2
-2
-2
-2
-2
-2
-2

I was pressing the 8° pin key

I use 9600 baud cause that is what serial monitor seems to default to and I don't want to add confusion.

Take a picture of your UNO and the breadboard and the wiring. Also the capacitive keys. Post it here.

I don't think i changed the code since i did in the MEGA, and i'll put && instead of just &

i'll try to get a good image with my pc camera

but i think i'll just be able to post tomorrow at 2 p.m.

@lucash2008, your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with your project :wink: See About the Installation & Troubleshooting category.

... better still, use the modern 'and' instead of the somewhat cryptic '&&'.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.