0

I'm working on a project that consists of sending data from flex sensors from a master Arduino to a slave arduino that uses that data to control servo-motors. I am trying to start slow and just control an LED using a button. I have gone through all AT commands, have set both a master and a slave and binded the addresses but when I try to light the LED on it for some reason doesn't work. My serial monitor keeps printing the letter "d" over and over again and I don't know what this is. Code is below:

int val=0; //Master code
#define button 3
void setup() {
Serial.begin(38400);
pinMode(button,HIGH);
}
void loop(){
val=digitalRead(HIGH);
if(val==HIGH){
Serial.write(100);
delay(500);
}
delay(50);
}
}

#define led2
int pos=0;
int val;

void setup(){
Serial.begin(38400);
pinMode(led,OUTPUT);
}
void loop(){
if(Serial.available()>0){
val=Serial.read();
if(val==100 && pos==0)
{
digitalWrite(led,HIGH);
pos=1;
}
else if(val==100 && pos==1)
{
digitalWrite(led,LOW);
pos=0;
}
}
}

If anyone can help i'd appreciate

  • that is what you are sending ... look at lower case d on this page ... asciitable.com/mobile – jsotola Jun 15 at 3:18
  • How can I convert that value 100 to the actual decimal value? I want to send a number not an ASCII code – Rafael Reis Jun 15 at 12:15
  • Currently you are sending a number. The serial monitor is just interpreting it as ASCII (since that is what the serial monitor is supposed to do). Other serial terminal programs can also shoe you the byte data, where you could see the value 100. If you want to see it in serial monitor, you have to send ASCII encoded data with Serial.print() – chrisl Jun 15 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.