Voltage decrease and wrong reading

I have two reflective infrared sensors connected to my Arduino mega.
I read inputs on pins 22 and 23. I write output on pins 2 and 3. The output goes to the input of other hardware.
Problem 1: Arduino does not keep my sketch as I disconnect and connect USB cable.
Problem 2: I do not get proper values on output pin(two connected sensors). The voltage divided between two output around 2.4v.
When I am using only one sensor everything works good but not with two sensors. I am going to add 10 infrared sensor which I need 10 output.
The blow lines are my sketch.

int sens1val=1;
int sens2val=1;

void setup() {
  // put your setup code here, to run once:
//Serial.begin(9600);
pinMode(22, INPUT); 
pinMode(2, OUTPUT);


pinMode(23, INPUT);
pinMode(3, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
sens1val = digitalRead(22); 
digitalWrite(2,sens1val);

sens2val = digitalRead(23); 
digitalWrite(3,sens2val);

The code is incomplete. There is no schematic.

Arduino does not keep my sketch as I disconnect and connect USB cable.

What does that mean?

If you are measuring low voltages on output pins I would look first at the "other hardware" they feed to see what that is doing to the outputs.

Steve

Problem 1: Arduino does not keep my sketch as I disconnect and connect USB cable.

Any sketch you have uploaded will be retained, through an indefinite number of power on/off cycles.

The code is incomplete. There is no schematic.

I am new to Arduino so please let me know whats wrong with the script?

jremington:
Any sketch you have uploaded will be retained, through an indefinite number of power on/off cycles.

This is likely a symptom of improper reset at power on, not that the code isn't stored on the Arduino.
Reprogramming the thing provides a new reset pulse, clearing the problem.

The underlying cause may be related to the power source or other hardware sharing this power source.

But you've not told us what all the hardware is - so please do so, preferably links to datasheets or product
pages.