HC-05 pin 34 HIGH with Arduino sketch for AT mode

I connected an HC-05 module to pins 0 and 1 of an Arduino, including a voltage divider between Arduino TX and HC-05 RX.

Communication to the mobile app I made, goes only via:

Serial.begin(9600);
Serial.println(integer);

Changing the name and pincode of the module, however, isn't working.

Using soldering, I attached a wire from pin 34 to a voltage divider (1K and 2K, to get 3,3V).
The other leg of the 1K resistor is connected to Arduino pin 8. The other leg of the 2K resistor is connected to GND. Actually, I didn't have a 2K resistor so I put two 1K resistors in serie.

I am using this code to change the name and pincode on start-up, and to communicate with my app.

void setup() {

  pinMode(8, OUTPUT);
  
  Serial.begin(9600);
  
  digitalWrite(8, HIGH);
  
  Serial.write("AT+PSWD=9876\r\n");
  Serial.write("AT+NAME=NEWNAME\r\n");
  
  digitalWrite(8, LOW);

}

void loop () {

if (statement) {                
    Serial.println(integer);
  }

}

The basic communication still works perfectly fine, with the app showing the right values.
However, both in Android settings and in my app, I still see the name as 'HC-05' and the pincode is still the default '1234'.

I'm hoping something is amiss in my code.

If not, that probably means I didn't solder the wire to pin 34 correctly, not having the right tools for such precision soldering, and possibly have a cold joint. Then I might look for a clipper.

It sounds rather like you are just trying to make things more difficult than they really are, but you probably haven't done any damage. Is your HC-05 a bare module, or is it on a breakout board? If the latter, you should not need to solder anything. If the former, you might consider investing $1-50 on a blank ZS-040 breakout board and doing the job properly.
As for the code, you are off to a bad start, as the baud rate to address HC-05 in AT mode is 38400. You might find the rest of it is junk too. Check the Martyn Currey website. He knows what he is doing

It's on a breakout board (ZS-040).

I did read Martyn Currey's tutorial and also method 4 of this PDF.

I cannot use the button, since I don't want user interaction and it needs to go automatically from within a sketch.

Alternatively, if you are using AT command mode for any length of time, make a direct connection between pin 34 and +3.3v. Either solder a wire to the pin or use a clip.

Hence the set-up as shown in the image, albeit with two 1K resistors in series instead of a 2K one.

The Arduino I'm using has built in support for serial communication on pins 0 and 1. I don't think I need to use SoftwareSerial to use more serial ports, since all serial communication goes to the HC-05. Output of my Arduino sketch is sending an integer to a mobile app and lighting up a LED.

Communication works by using Serial.begin(9600) and Serial.print(integer). Tested and verified. I thought by, in the setup(), first using Serial.begin(38400) whilst pin 34 is high, it would unable me to send the AT commands. Then returning to Serial.begin(9600).

This gives me the following code (cropping out non-related code):

void setup() {
  
  pinMode(8, OUTPUT);
  
  Serial.begin(38400);
  
  digitalWrite(8, HIGH);
  
  Serial.write("AT+PSWD=9876\r\n");
  Serial.write("AT+NAME=NEWNAME\r\n");
  
  digitalWrite(8, LOW);
  
  Serial.begin(9600);
}

void loop() {
  
  if (integer > 0) {                
    Serial.println(integer);
  }
  
}

The EN pin ENables you to enter AT mode under software. The button is just a convenience. Some obscure AT commands require the soldered wire. I don't know what they are, but I'm sure Martyn does. All Arduinos have hardware serial on pins 0,1. Although I think a couple have their physical positions reversed. It is quite OK to have Bluetooth on hardware serial, indeed software serial is never a good idea and best, in principle, only used as a last resort.

You only need to ensure that Bluetooth is disconnected when uploading your programme - something you probably know already.

To use AT mode, you must always use 38400. The rate for comms mode can be whatever but, if you are chopping and changing around, I guess it is simpler to have that set at 38400 as well.