Code not work in my seconde micro controller :/

hi guys

i just buy a microcontroller 328PU… so when i try this code:

  #include <SoftwareSerial.h>
  // Connect bluetooth module on pins 9 and 10 (Rx Tx)
SoftwareSerial bluetoothser(9,10);
void setup()
{
  bluetoothser.begin(9600);
pinMode(11,OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
if(bluetoothser.available())
{
  char i = bluetoothser.read();
  if(i == '1')
  {
    analogWrite(11,255);
  }
    if(i == '2')
  {
    analogWrite(11,0);
  }
  
}
}

with my original 328PU its work perfectly if i use my application android or this application https://play.google.com/store/apps/details?id=com.techbitar.android.Andruino

but if i use it with my new 328PU the code work only if i use TX and RX arduino with my application, and his still working perfectly with this application https://play.google.com/store/apps/details?id=com.techbitar.android.Andruino

so why his work on original microcontroller and not my seconde micro controller thanks

What exactly do you mean when you say “i just buy a microcontroller 328PU”, “with my original 328PU” and “if i use it with my new 328PU”

Atmega 328s don’t work when sitting on a table. They need other parts. What other parts are you using.

Are you using the 2nd 328 in the same system as the first one - ie unplug the first one and insert the second one?

Or are they working in two separate, but smilar systems?

And post your code - using the code button </> so it looks like this

…R

ok look at this:

http://www.hostingpics.net/viewer.php?id=717671IMG20160106211102.jpg

i have 2 microcontroller with the same code.

/////////////////////////////////

if i work with the original microcontroller, the LED turn on with my application and with ArduDroid application

but if i remplace the seconde microcontroller only the ArduDroid work. and i dont know why :frowning:

Does the second 328 run normally in the Arduino board IC socket? Can you upload and run a simple sketch like Blink Without Delay?

If i try this code

#include <SoftwareSerial.h>

// Connect bluetooth module on pins 9 and 10 (Rx Tx)
SoftwareSerial bluetoothser(9,10);

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

void loop()
{
  
    if ( bluetoothser.available() )
    {
        Serial.println(bluetoothser.read(), HEX);
    }
}

my application work with first and seconde microcontroller :confused:

but if i try this code:

#include <SoftwareSerial.h>

// Connect bluetooth module on pins 9 and 10 (Rx Tx)
SoftwareSerial bluetoothser(9,10);

const int redPin = 6;
const int greenPin = 5;
const int bluePin = 3;

byte colorValue [3] = {0};


bool displayedNewValue = true;

void setup() 
{
  Serial.begin(115200);
  bluetoothser.begin(9600);
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);
  // put your setup code here, to run once:
}

void loop() 
{
  if(bluetoothser.available())
  {
    char myChar = bluetoothser.read();
    if(myChar == '*') // found leading *
    {
      for (int i = 0; i < 3; i++)
      {
        colorValue[i] = bluetoothser.parseInt();
        if(i!=2)
        {
          bluetoothser.read();  // ignore the pipe
        }
        else
        {
          char lastChar;
          lastChar = bluetoothser.read();
          if(lastChar != '#')  // expects a # ... abort if it didn't arrive  ////<<<<<<<error was here
          {
            Serial.println(F("bad read"));
            break;
          }
          else
          {
            displayedNewValue = false;
          }
        }
        delay(10);
      }
    }
  }
  if (!displayedNewValue)
  {
    char packetContents[32];
    sprintf(packetContents, "Red:%3d Green:%3d Blue:%3d", colorValue[2], colorValue[1], colorValue[0]);
    Serial.println(packetContents);
    analogWrite(redPin, colorValue[2]);
    analogWrite(greenPin, colorValue[1]);
    analogWrite(bluePin, colorValue[0]);
    displayedNewValue = true;
  }    
}

no signal detected :frowning:

its work i dont know how but his work, thanks