-1
#include <VirtualWire.h>
const int sen1 = 9;
const int sen2 = 10;
const int sen3 = 11;
const int sen4 = 12;
int key1 = 5, ipin = A1, wpin = A0;
void setup() {
  Serial.begin(9600);
  vw_setup(2000);
  vw_set_tx_pin(3);
  pinMode (key1, INPUT);
  digitalWrite (key1, HIGH);
}
void loop() {
  int dif = 5, dif2 = 500, ldr, wtr;
  long dur1, dur2, dur3, dur4, dis1, dis2, dis3, dis4;
  wtr = analogRead(wpin);
  ldr + analogRead(ipin);
  pinMode(sen1, OUTPUT);
  digitalWrite(sen1, LOW);
  delayMicroseconds(2);
  digitalWrite(sen1, HIGH);
  delayMicroseconds(10);
  digitalWrite(sen1, LOW);
  pinMode(sen1, INPUT);
  dur1 = pulseIn(sen1, HIGH);
  dis1 = microsecondsToInches(dur1);
  pinMode(sen2, OUTPUT);
  digitalWrite(sen2, LOW);
  delayMicroseconds(2);
  digitalWrite(sen2, HIGH);
  delayMicroseconds(10);
  digitalWrite(sen2, LOW);
  pinMode(sen2, INPUT);
  dur2 = pulseIn(sen2, HIGH);
  dis2 = microsecondsToInches(dur2);
  delayMicroseconds(2);
  digitalWrite(sen4, HIGH);
  delayMicroseconds(10);
  digitalWrite(sen4, LOW);
  pinMode(sen4, INPUT);
  dur4 = pulseIn(sen4, HIGH);
  dis4 = microsecondsToInches(dur4);
  Serial.print(dis1);
  Serial.print("s1,");
  Serial.print(dis2);
  Serial.print("s2,");
  Serial.print(dis3);
  Serial.print("s3,");
  Serial.print(dis4);
  Serial.print("s4,");
  Serial.println(); delay(0);
  if (wtr > dif2) {
    wstop();
  }
  if (ldr > dif2 && key1 == HIGH) {
    light();
  }
  if (ldr > dif2 && key1 == HIGH) {
    nolight();
  }
  if (dis2 < 3 || dis3 < 3) {
    stoped();
  }
  if (dis1 < 3 && dis2 > dis1 && dis3 > dis2) {
    group();
  }
  if (dis4 > 3) {
    godown();
  }
  if (dis1 < 3 && dis2 == dis3) {
    jump();
  }
  if (dis1 > 3 && dis2 > 3 && dis3 > 3 && dis4 < 3 && wtr < dif2) {
    forword();
  }
}
long microsecondsToInches(long microseconds) {
  return microseconds / 74 / 4;
}
void forword() {
  char *msg2 = "0";
  vw_send((unit8_t *) msg, strlen(msg2));
  vw_wait_tx(); Serial.print("FORWORD");
  delay(1000);
}
void stoped() {
  char *msg2 = "1";
  vw_send((unit8_t *)msg2, strlen(msg2));
  vw_wait_tx(); Serial.print("STOP");
  delay(1000);
}
void group() {
  char *msg2 = "2";
  vw_send((unit8_t *)msg2, strlen(msg2));
  vw_wait_tx(); Serial.print("GROUP");
  delay(1000);
}
void godown() {
  char *msg2 = "3";
  vw_send((unit8_t *)msg2, strlen(msg2));
  vw_wait_tx(); Serial.print("GODOWN");
  delay(1000);
}
void jump() {
  char *msg2 = "4";
  vw_send((unit8_t *)msg2, strlen(msg2));
  vw_wait_tx(); Serial.print("JUMP");
  delay(1000);
}
void wstop() {
  char *msg2 = "5";
  vw_send((unit8_t *)msg2, strlen(msg2));
  vw_wait_tx(); Serial.print("WSTOP");
  delay(1000);
}
void light() {
  char  *msg2 = "6"
  vw_send((unit8_t *)msg2, strlen(msg2));
  vw_wait_tx(); Serial.print("LIGHT");
  delay(1000);
}

void nolight() {
  char *msg2 = "7";
  vw_send((unit8_t *)msg2, strlen(msg2));
  vw_wait_tx(); Serial.print("NOLIGHT");
  delay(1000);
}
  • 2
    I’m voting to close this question because it's about a spelling error and has nothing directly to do with Arduino. – chrisl May 19 at 11:44
  • I would class this code in the "unrecoverable" category. Delete it and start again after learning the basics of C coding. – Majenko May 19 at 11:46
  • 1
    Why close a question like this? Some people, myself included, can stare at a typo and see what they expect, not what's there. Sometimes I need a kick in the pants from somebody else. This question seems like a useful lesson in "the compiler doesn't understand what you meant. If you have a spelling error in your code, it will produce a compiler error and you have to fix it." – Duncan C May 20 at 13:04
  • Have you successfully run any of this code yet? When you write a lot of code before you compile and test any of it, you generally get a lot of errors, or end up with a lot of unusable code when you discover that some basic assumption was wrong -- or both. Start small - write a few lines at a time, compile it, and fix any errors. Complete and test a small piece of the overall project and get it working before you add any more to it. Then, each time something fails, you know exactly where the problem is: it will be in whatever you just added. – JRobert May 20 at 13:22
1

You mean uint8_t not unit8_t. uint8_t means Unsigned INTeger of size 8.

Also you seem to have taken two different sketches and just dumped them once after another. That is not how you combine sketches. You can have one, and only one each of setup() and loop().

| improve this answer | |
  • it says this, error: 'unit8_t' was not declared in this scope vw_send((unit8_t *) msg, strlen(msg2)); – Tashii Gurung May 19 at 11:39
  • 1
    @TashiiGurung Read what you wrote very carefully. – Majenko May 19 at 11:39
  • @TashiiGurung Very carefully: unit8_t buf [ VW_MAX_MESSAGE_LEN } ; "u nit" instead of "u int" isn't the only mistake here – KIIV May 19 at 11:42
  • 1
    Maybe you should fix your brackets then? In fact, you should just delete the "sketch" completely and start from scratch. It's compete junk. – Majenko May 19 at 11:45

Not the answer you're looking for? Browse other questions tagged or ask your own question.