Programmer is not responding. WHY?

HERE's THE ERROR:
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0xab
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0xab

HERE'S MY CODE:
#define SENSE A0

void setup()
{
pinMode(SENSE, INPUT);
pinMode(2, OUTPUT);

pinMode(LED_BUILTIN, OUTPUT);
}
void loop()
{
if(digitalRead(SENSE))
{
digitalWrite(LED_BUILTIN, LOW);
pinMode(2, LOW);
}
else
{
delay (2000);
if(digitalRead(SENSE))
{
digitalWrite(LED_BUILTIN, LOW);
pinMode(2, LOW);
}
else
digitalWrite(LED_BUILTIN, HIGH);
pinMode(2, HIGH);
}
}

Welcome to the forum

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

1 Like

Bad cable, wrong port you name it

Wrong board :smiley:

Wrong planet!

Sorry, let me state here that I've no programming or computer hardware knowledge. This is for my wife's school project. I have made the Anti-Sleep Alarm glass that should blink 2 seconds after the driver's eyelids are closed. I'm happy that I've made the glass but it does not respond the way I want it. It kept on continuously blinking till I uploaded the BLINK program on Arduino IDE. I uploaded the above-mentioned CODE but i don't see any response whatsoever. Any program that can help me do it?

You haven’t uploaded anything according to error message

We still don't know anything about your project except

  1. You can't upload
  2. You have some code (incorrectly posted, please fix).
  3. A description.

Please provide details like which board you're using as well as a wiring diagram / schematic (photo of a hand drawn one is fine).

@killzone_kid @sterretje

I'll explain to my maximum capability here - I'll respond to your respective reverts.

@killzone_kid said:
You haven’t uploaded anything according to error message.

Well below given is the 'code' that I am trying to upload.

#define SENSE A0

void setup()
{
pinMode(SENSE, INPUT);
pinMode(2, OUTPUT);

pinMode(LED_BUILTIN, OUTPUT);
}
void loop()
{
if(digitalRead(SENSE))
{
digitalWrite(LED_BUILTIN, LOW);
pinMode(2, LOW);
}
else
{
delay (2000);
if(digitalRead(SENSE))
{
digitalWrite(LED_BUILTIN, LOW);
pinMode(2, LOW);
}
else
digitalWrite(LED_BUILTIN, HIGH);
pinMode(2, HIGH);
}
}

But nothing happens.

@sterretje said:
.

  1. You can't upload - I can upload as of now. I have uploaded a code that makes it beep after 10 seconds (WHICH IS A BIG DEAL FOR ME AS OF NOW :))

  2. You have some code (incorrectly posted, please fix. - I didn't understand initially how to post the code here but I guess I have cracked it and here goes the code:

#define SENSE A0

void setup()
{
pinMode(SENSE, INPUT);
pinMode(2, OUTPUT);

pinMode(LED_BUILTIN, OUTPUT);
}
void loop()
{
if(digitalRead(SENSE))
{
digitalWrite(LED_BUILTIN, LOW);
pinMode(2, LOW);
}
else
{
delay (2000);
if(digitalRead(SENSE))
{
digitalWrite(LED_BUILTIN, LOW);
pinMode(2, LOW);
}
else
digitalWrite(LED_BUILTIN, HIGH);
pinMode(2, HIGH);
}
}
  1. A description - I am trying to make an Anti-Sleep Alarm Glass that will wake you up if you fall asleep when you drive. This glass will start vibrating & beeping an alarm as soon as it detects that your EYELIDS ARE CLOSED FOR MORE THAN 2 SECONDS which means you are asleep behind the wheel.

Also I would like to post the diagram of what I'm trying to achieve.

You've cracked the code tags, thanks.

I don't know how much current the motor and buzzer draw. The current that a pin can sink/source is limited. Disconnect the motor and buzzer and see if the built-in led will do something. For that test, i would add a digitalWrite(LED_BUILTIN, HIGH); in setup() and add a delay after that so you can see that the pin works; it should light up for e.g 3 seconds if you use delay(3000) just before the end of setup().

Why do you have pinMode statements in loop()? Pin 2 is not even connected.

Once your sensor goes high, your pin13 will always be low and never go back to high till you reset the board.

@sterretje I think you misunderstood me as a CODE pro :).
I just copy pasted the CODE from some site. When you say this -

I JUST STARE. I don't understand this stuff. Is there a site where i can get this code readymade :slight_smile: ? So that i can just COPY PASTE it into the Arduino IDE? :pray: :slight_smile:

The forum offers a section for (paid for) help: Jobs and Paid Consultancy - Arduino Forum .

You will have to :wink: But we're here to help.

As it's not quite clear to me what does not work as expected, below the steps that I would take; you might already have done them, in that case skip.

I suggest that you break your code down into pieces.

(1) Get your sensor working with some simple code like below. Do not connect anything but the sensor; power wil be supplied by the USB port of the PC.

#define SENSE A0

void setup()
{
  // serial communication for debugging
  Serial.begin(115200);
  Serial.println(F("starting"));
  
  // configure pins
  pinMode(SENSE, INPUT);
  pinMode(LED_BUILTIN, OUTPUT);
  // led of to start with
  digitalWrite(LED_BUILTIN, LOW);
}

void loop()
{
  // read the sensor
  uint8_t sensorStatus = digitalRead(SENSE);
  // for debugging, print
  Serial.print(F("Sense input: "));
  Serial.println(sensorStatus);
  
  // to prevent serial monitor to be spammed
  delay(1000);
}

(2) Once that behaves as expected, you can add the LED on pin 13; below the updated loop() function. Still nothing but the sensor connected.

void loop()
{
  // read the sensor
  uint8_t sensorStatus = digitalRead(SENSE);
  // for debugging, print
  Serial.print(F("Sense input: "));
  Serial.println(sensorStatus);

  // control the led / motor / buzzer
  digitalWrite(LED_BUILTIN, sensorStatus);
  
  // to prevent serial monitor to be spammed
  delay(1000);
}

As I don't know the sensor, you might have to invert the reading. You can do that e.g. as shown below; I will show another way using a macro in (5).

  // read the sensor
  uint8_t sensorStatus = !digitalRead(SENSE);

(3) If that behaves as expected, you can add the buzzer and the vibration motor one by one. Each time, test.

(4) Once that behaves as you want / expect, disconnect the USB and power from the battery. Does it still work? If not,

  1. The pins can only safely drive a load of 20 mA (40 mA amx); you will have to measure the total current with a multimeter. If it exceeds the 20 mA by a lot, you can use two pins; one to drive the buzzer and one to drive the motor.
  2. Your Arduino can't supply enough current to drive the motor and buzzer; the on-board regulator that converts the battery voltage to 5V is very limited when it comes to current. You will need an external converter to convert your battery voltage to 5V and feed the Arduino, the sensor, motor and buzzer.

Let us know if there is any problem up till now.

(5) Now you can start concentrating on the timing. You're requirement is / seems to be that after 2 seconds with closed eyes, you want the system to start beeping / vibrating. In the first step, your code must detect if the eyes became closed; therefore you have to keep track of the current state of the sensor and the provious state.

// macro to more easily evaluate the sensor status
#define EYES_ARE_CLOSED LOW

void loop()
{
  // the previous sensor status
  static uint8_t previousSensorStatus;
  
  // read the sensor
  uint8_t sensorStatus = digitalRead(SENSE);

  // if the sensor status changed
  if(sensorStatus != previousSensorStatus)
  {
    // and the eyes are closed
    if(sensorStatus == EYES_ARE_CLOSED)
    {
      // for debugging, print
      Serial.println(F("Eyes became closed"));
    }
  }
  
  // remember sensor status
  previousSensorStatus = sensorStatus;
}

If this goes as expected, you will 'see' only one message when the eyes became closed. Open the eyes again and close them again and you will 'see' the next message. It's a bit difficult to see with your eyes closed :slight_smile: If you see "Eyes became closed" when they were actually opened, you must change the #define to #define EYES_ARE_CLOSED HIGH.

Now you can add the timing.

// macro to more easily evaluate the sensor status
#define EYES_ARE_CLOSED LOW

void loop()
{
  // the previous sensor status
  static uint8_t previousSensorStatus;
  // the times that eyes closed was detected
  static uint32_t startTime;
  // flag that the timer is started
  static bool timerIsStarted = false;
  
  // read the sensor
  uint8_t sensorStatus = digitalRead(SENSE);

  // if the sensor status changed
  if(sensorStatus != previousSensorStatus)
  {
    // and the eyes are now closed
    if(sensorStatus == EYES_ARE_CLOSED)
    {
      // record the start time
      startTime = millis();
      timerIsStarted = true;

      // for debugging, print
      Serial.print(F("Eyes became closed at "));
      Serial.println(startTime);
    }
  }
  
  // remember sensor status
  previousSensorStatus = sensorStatus;

  // check if the eyes are closed for two or more seconds
  if(timerIsStarted == true && millis() - startTime >= 2000)
  {
    // activate buzzer and motor
    digitalWrite(LED_BUILTIN, HIGH);
  }
}

The only thing outstanding is to stop the buzzer / vibration sensor when the eyes are opened again.

// macro to more easily evaluate the sensor status
#define EYES_ARE_CLOSED LOW

void loop()
{
  // the previous sensor status
  static uint8_t previousSensorStatus;
  // the times that eyes closed was detected
  static uint32_t startTime;
  // flag that the timer is started
  static bool timerIsStarted = false;
  
  // read the sensor
  uint8_t sensorStatus = digitalRead(SENSE);

  // if the sensor status changed
  if(sensorStatus != previousSensorStatus)
  {
    // and the eyes are now closed
    if(sensorStatus == EYES_ARE_CLOSED)
    {
      // record the start time
      startTime = millis();
      timerIsStarted = true;

      // for debugging, print
      Serial.print(F("Eyes closed at "));
      Serial.println(startTime);
    }
    // eyes are open
    else
    {
      // 'stop' timer
      timerIsStarted = false;
      // de-activate buzzer and motor
      digitalWrite(LED_BUILTIN, LOW);
   
      Serial.print(F("Eyes opened at "));
      Serial.println(millis());
    }
  }
  
  // remember sensor status
  previousSensorStatus = sensorStatus;

  // check if the eyes are closed for two or more seconds
  if(timerIsStarted == true && millis() - startTime >= 2000)
  {
    // activate buzzer and motor
    digitalWrite(LED_BUILTIN, HIGH);
  }
}

And that is it. Ask if you have questions or if does not work; in that case, please provide (web) links to the sensor, the buzzer and the vibration motor.

As this no longer is a bootloader issue, I've moved your topic to a more suitable location on the forum.

The full code, compiled but not tested.

// macro to more easily evaluate the sensor status
#define EYES_ARE_CLOSED LOW

#define SENSE A0

void setup()
 {
  // serial communication for debugging
  Serial.begin(115200);
  Serial.println(F("starting"));

  // configure pins
  pinMode(SENSE, INPUT);
  pinMode(LED_BUILTIN, OUTPUT);
  // led of to start with
  digitalWrite(LED_BUILTIN, LOW);
}

void loop()
 {
  // the previous sensor status
  static uint8_t previousSensorStatus;
  // the times that eyes closed was detected
  static uint32_t startTime;
  // flag that the timer is started
  static bool timerIsStarted = false;

  // read the sensor
  uint8_t sensorStatus = digitalRead(SENSE);

  // if the sensor status changed
  if (sensorStatus != previousSensorStatus)
   {
    // and the eyes are now closed
    if (sensorStatus == EYES_ARE_CLOSED)
     {
      // record the start time
      startTime = millis();
      timerIsStarted = true;

      // for debugging, print
      Serial.print(F("Eyes closed at "));
      Serial.println(startTime);
    }
    // eyes are open
    else 
    {
      // 'stop' timer
      timerIsStarted = true;
      // de-activate buzzer and motor
      digitalWrite(LED_BUILTIN, LOW);

      Serial.print(F("Eyes opened at "));
      Serial.println(millis());
    }
  }

  // remember sensor status
  previousSensorStatus = sensorStatus;

  // check if the eyes are closed for two or more seconds
  if (timerIsStarted == true && millis() - startTime >= 2000)
   {
    // activate buzzer and motor
    digitalWrite(LED_BUILTIN, HIGH);

    // for debugging, print
    Serial.println(F("Buzzer / motor activated"));
  }
}

THANKS A TON @sterretje for the TIME & EFFORT you have put into this simple thing.
I tried almost everything you said above but there is no change in its behavior.

It still works on this default program which can be found in File > Examples > Basics > Blink.
i.e. it still lights the LED and beeps the beeeep sound after 10 Secs.

The compiled code that you've pasted in the end gives this error.

avrdude: ser_open(): can't open device "\\.\COM5": The system cannot find the file specified.


Problem uploading to board.  See https://support.arduino.cc/hc/en-us/sections/360003198300 for suggestions.

Can you once more try to help me here? I am sure this entire thing comes off from a very minute mistake that I'm not aware of. Hope you help :slight_smile:

I still suspect a power issue. If toy're really using one of those batteries as shown in the picture, I'm not surprised.

Is the motor also connected at that moment?

OK, what does Windows device manager say at that moment that you get the error? Is the board still COM5?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.