Hello everyone,
I am having trouble writing some code for my Electrical engineering project and need some help.
So far i have a code that will tell me what the Arduino Nano on the car receives, and it gets sent back to my computer.
This is Setup by having a Xbee S1 hooked up to my laptop with a Xbee explorer, that is communicating with another Xbees S1 that is on a Arduino Nano Shield. On the car is self there is an H-Bridge for power to the motors, and battery pack.
This is the code for what i have so far. The only command that i have going so far is to make the car go forward, because once i figure one out i can do the rest out.
//XCTU W = 119 Recieved
//XCTU S = 115 Recieved
//XCTU A = 97 Recieved
//XCTU D = 100 Recieved
int incomingByte = 0;// H Bridge code for the pins into the H Bridge
int in1 = 2;
int in2 = 3;
int enA = 5;
int in3 = 4;
int in4 = 7;
int enB = 6;
void setup() {
Serial.begin(9600);
//HBridge
pinMode(in1,OUTPUT);
pinMode(in2,OUTPUT);
pinMode(in3,OUTPUT);
pinMode(in4,OUTPUT);
pinMode(enA,OUTPUT);
pinMode(enB,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
// say what you got:
Serial.print("I received: ");
Serial.println(incomingByte, DEC);
int getData = Serial.read(); //read the serial port
delay(100);
if (getData == 119){
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
delay(100);}
}
}