NEED HELP ON PROGRAMING

HI
Below is my transmitter code. Can you rectifier it because when i conected a push button to pin 3 and push button is pressed, the data is not transmitting as i observed from the serial monitor(nothing pop from the serial monitor)

int crankingPin = 3;
int liftoffPin = 4;
int upwardPin = 5;
int downwardPin = 6;
int turnleftPin = 7;
int turnrightPin = 8;
int forwardPin = 9;
int backwardPin = 10;
int buttonstate;

void setup()
{
// initialize the serial communication:
Serial.begin(9600);

// initialize the ledPin as an output:

pinMode(crankingPin, INPUT);
pinMode(liftoffPin, INPUT);
pinMode(upwardPin, INPUT);
pinMode(downwardPin, INPUT);
pinMode(turnleftPin, INPUT);
pinMode(turnrightPin, INPUT);
pinMode(forwardPin, INPUT);
pinMode(backwardPin, INPUT);
}

void loop()
{
if(digitalRead(crankingPin)==HIGH)
{
Serial.write( 8 ) ;
delay(1000);
}
else
{
buttonstate = 0;
}
}

And how is crankingPin wired?

Serial.write() sends binary data. I personally wouldn't expect to be able to make sense of what is sends to the serial monitor.

With smiley faces in the code, it's really hard to tell what you are sending to the serial port.

I truly hope you don't expect the smiley face to appear in the serial monitor.

For future postings, select the triangle in front of Additional Options below this window, and select the "Don"t use smileys" option.

Sure be nice if similey strings between code tags were ignored.

hi
sorry i m new this forum.

After some example i go through, i change Serial.write( 8 ) ; to Serial.write('8') ; and the serial monitor showing integer 8 when i pressed the push button. So am i transferring data ?

PaulS:
Serial.write() sends binary data. I personally wouldn't expect to be able to make sense of what is sends to the serial monitor.

please refer back to the code. it will be more clear now.

rooney04:
hi
sorry i m new this forum.

After some example i go through, i change Serial.write( 8 ) ; to Serial.write('8') ; and the serial monitor showing integer 8 when i pressed the push button. So am i transferring data ?

Read careful the example options avalible below in serial printing for how the data will be handled and sent to the PC.

yeah i read that, but what you trying to say toward my situation or the problem i face.

What we are wondering is why you insist on using Serial.write to send ascii data, when that is not what is was meant to send. Why won't you change it to Serial.print()?

Hmm. Basically i need to transfer few 4 bit binary data (1000, 1001, 1011, 1101, 1110 and etc)) to another arduino and the receiving arduino will receive it. For each 4 bit binary data received , it executes a certain routines such controlling the speed of motor or brightness of led, So how can i do that?

Are you trying to transfer data to another Arduino via the Serial Monitor? You might use Serial.write() to talk to a device that understands binary data, but you use Serial.print() to talk to the Serial Monitor.

For each 4 bit binary data received , it executes a certain routines such controlling the speed of motor or brightness of led,

Serial data is one byte/8 bits long. You can not send just 4 bits. What is the significance of sending a binary value, anyway? The receiver still has to compare the received value against all possible values.

int val = Serial.read();
switch(val)
{
   case 0b0000: Do0();  break;
   case 0b0001: Do1();  break;
   case 0b0010: Do2();  break;
   case 0b0011: Do3();  break;
   case 0b0400: Do4();  break;
}

will be no faster than:

int val = Serial.read();
switch(val)
{
   case '0': Do0();  break;
   case '1': Do1();  break;
   case '2': Do2();  break;
   case '3': Do3();  break;
   case '4': Do4();  break;
}

The second set of values looks reasonable in the Serial Monitor, too. The first set of values does not.

The character data, since it is one byte long, transmits in the same length of time as the byte value.

yeah i m trying to send binary data to another arduino. So to check i m using serial monitor whether it able to send the binary data or not? basically the code for transmitter can be use right? the receiver code follows your idea?

I give up on trying to explain why. I'll put it simply:
Use Serial.print() to send data, and Serial.read() to read it.

At some time in the future, you might encounter a situation where Serial.print() is not appropriate, but this is not one of those cases.

i m very for lack knowledge in programming. As for conclusion just "serial.print" to transmit the data to another arduino?